1 Star 0 Fork 56

麦琪 / Genius-Android

forked from Qiujuer / Genius-Android 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Version 2.0.0 Guide

中文 English Guides

Genius-Android是什么?

icon

Genius-AndroidAndroid 中一些常用的的方法集合, Genius 提供6个基本板块:

appUianimation动画widgetMaterial控件command命令行net toolPing、Dns...util常用方法,类

截图

GeniusUI

GeniusUI

BlurKit

BlurKit

ThemeColors

ThemeColors

功能模块

  • animation

    • TouchEffectAnimator 支持快速响应点击特效
  • app

    • UIKit 支持子线程同步异步切换到主线程操作
    • BlurKit 支持JavaJni使用StackBlur算法模糊图片
  • widget

    • 字体 opensans roboto
    • 颜色 none dark light
    • 控件 GeniusButton GeniusCheckBox GeniusTextView
  • command

    • 独立服务进程执行命令行工作
    • ProcessBuilder操作类似
    • 智能修正运行错误,解决运行故障
    • 一键化的启动与取消操作,自由控制
    • 可同步与异步方式执行,可回调事件
  • net tool

    • 一键Ping DNS TelNet TraceRoute
    • 可控制,可取消;不必关心细节问题
    • 并发的路由任务,可在40s左右测试完成
  • util

    • AppContext 全局、存取方便快捷
    • HashUtils 字符串与文件MD5获取
    • Tools ID SN 确定设备唯一标识
    • Log 如系统Log一样使用简单,一键开关
    • Log 可存储日志到文件,方便分析差错
    • Log 可添加事件监听,方便界面显示日志信息
    • FixedList 定长队列,自动弹出,保持队列数量

获取库

  • StarFork 项目。
  • MavenCentral 远程导入 :
// 在项目 "build.gradle" 中添加
dependencies {
  compile 'com.github.qiujuer:genius:2.0.0'
}

更新日志

使用方法

初始化与销毁
Genius.initialize(Application application);
Genius.dispose();
app 模块
// "Runnable" 实现其中 "run()" 方法
// "run()" 运行在主线程中,可在其中进行界面操作
// 同步进入主线程,等待主线程处理完成后继续执行子线程
UIKit.runOnMainThreadSync(Runnable runnable);
// 异步进入主线程,无需等待
UIKit.runOnMainThreadAsync(Runnable runnable);
// 同步但是子线程只等待指定时间
// @param runnable Runnable 接口
// @param waitTime 子线程等待时长
// @param cancel   等待时间到时是否取消主线程执行该任务
UIKit.runOnMainThreadSync(Runnable runnable, int waitTime, boolean cancel)

// "bitmap" 待处理的图片
// "radius" 图片模糊半径
// "canReuseInBitmap" 是否直接使用 "bitmap" 中进行模糊,
// "false" 情况下将拷贝 "bitmap" 的副本进行模糊
// 在"Java"中实现图片模糊
BlurKit.blur(Bitmap bitmap, int radius, boolean canReuseInBitmap);
// 在"Jni"中实现图片模糊,传给"Jni"的是图片类"Bitmap"
BlurKit.blurNatively(Bitmap bitmap, int radius, boolean canReuseInBitmap);
// 在"Jni"中实现图片模糊,传给"Jni"的是图片 "像素集合"
BlurKit.blurNativelyPixels(Bitmap bitmap, int radius, boolean canReuseInBitmap);
animation 模块
// TouchEffectAnimator 允许给你的控件添加点击特效
// 特效类型:Move, Ease, Ripple, None
public class GeniusButton extends Button {
    private TouchEffectAnimator touchEffectAnimator = null;
    // 在你的控件中初始化动画效果类
    public void initTouchEffect(TouchEffect touchEffect) {
        touchEffectAnimator = new TouchEffectAnimator(this);
        // 动画模式
        touchEffectAnimator.setTouchEffect(touchEffect);
        // 动画颜色
        touchEffectAnimator.setEffectColor("this color");
        // 边缘圆弧半径
        touchEffectAnimator.setClipRadius(20);
    }
    // 用于初始化高宽等数据
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (touchEffectAnimator != null)
            touchEffectAnimator.onMeasure();
    }
    // 回调绘制方法
    @Override
    protected void onDraw(Canvas canvas) {
        if (touchEffectAnimator != null)
            touchEffectAnimator.onDraw(canvas);
        super.onDraw(canvas);
    }
    // 触发点击事件
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (touchEffectAnimator != null)
            touchEffectAnimator.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
}
widget 模块
// 首先在根容器中指定:
<LinearLayout
    ...
    xmlns:genius="http://schemas.android.com/apk/res-auto"/>

// 主题样式:见截图Colors
// 提供字体:`opensans` `roboto`
// 字体粗细:`bold` `extrabold` `extralight` `light` `regular`

// ==================全局属性==================
<net.qiujuer.genius.widget.all
    ...
    genius:g_textAppearance="light"
    genius:g_fontFamily="opensans"
    genius:g_fontWeight="bold"
    genius:g_fontExtension="ttf"
    genius:g_cornerRadius="5dp"
    genius:g_borderWidth="5dp"
    genius:g_theme="@array/grass" />

// `g_textAppearance`: 指定字体颜色,默认为 `none`
// `g_fontFamily`: 指定两种字体中的一种字体
// `g_fontWeight`: 指定字体粗细
// `g_fontExtension`: 字体扩展名
// `g_cornerRadius`: 控件边缘圆角半径
// `g_borderWidth`: 描边宽度
// `g_theme`: 指定主题样式,12种任意选

// ==================GeniusButton==================
<net.qiujuer.genius.widget.GeniusButton
    ...
    genius:g_touchEffect="move"
    genius:g_blockButtonEffectHeight="10dp" />

// `g_touchEffect`: Move, Ease, Ripple, None
// `g_blockButtonEffectHeight`: 底部阴影高度

// ==================GeniusCheckBox==================
<net.qiujuer.genius.widget.GeniusCheckBox
    ...
    genius:g_ringWidth="2dp"
    genius:g_circleRadius="22dp"
    genius:g_checked="true"
    genius:g_enabled="true" />

// `g_ringWidth`: 圆环宽度
// `g_circleRadius`: 圆心半径
// `g_checked`: 是否选中
// `g_enabled`: 是否可点击

// ==================GeniusTextView==================
<net.qiujuer.genius.widget.GeniusTextView
    ...
    genius:g_textColor="light"
    genius:g_backgroundColor="dark"
    genius:g_customBackgroundColor="#FFFFFF" />

// `g_textColor`: 字体颜色类型
// `g_backgroundColor`: 背景颜色类型
// `g_customBackgroundColor`: 背景颜色
command 模块
// 执行命令,后台服务自动控制
// 调用方式与ProcessBuilder传参方式一样
// timeout:任务超时值,可选参数
// params:执行参数,如:"/system/bin/ping","-c", "4", "-s", "100","www.baidu.com"
Command command = new Command(int timeout, String... params);

// 同步方式
// 完成后结果直接返回
String result = Command.command(new Command(Command.TIMEOUT, "..."));

// 异步方式
// 结果以事件回调方式返回
Command command = new Command("...");
Command.command(command, new Command.CommandListener() {
    @Override
    public void onCompleted(String str) {
    }
    @Override
    public void onCancel() {
    }
    @Override
    public void onError(Exception e) {
    }
});

// 取消一个命令任务
Command.cancel(Command command);

// 重启 Command 服务
Command.restart();

// 销毁
// 调用 ‘Genius.dispose()’ 方法时默认调用
Command.dispose();
net tool 模块
// Ping
// 传入域名或者IP
// 结果:是否执行成功、延时、丢包
Ping ping = new Ping("www.baidu.com");
// 开始
ping.start();
// 返回
if (ping.getError() == NetModel.SUCCEED) {}
else {}
...
其他操作与Ping类似
...
util 模块
// ===================FixedList===================
// 固定长度队列
// 可指定长度,使用方法与普通队列类似
// 当加入元素数量达到指定数量时将弹出元素
// 头部插入尾部弹出,尾部插入头部弹出

// 初始化最大长度为5
FixedList<Integer> list = new FixedList<Integer>(5);

// 获取最大容量
list.getMaxSize();
// 调整最大长度;缩小长度时将自动删除头部多余元素
list.setMaxSize(3);

// 可使用List操作
List<Integer> list = new FixedList<Integer>(2);


// ====================HashUtils==================
// 哈希计算(Md5)
// 可计算字符串与文件Md5值

// 获取字符串MD5
String hash = HashUtils.getStringMd5(String str);
// 获取文件MD5
String hash = HashUtils.getFileMd5(File file);


// ======================Log======================
// 日志类
// 调用方法与使用Android Log方法一样
// 可设置其是否存储日志信息
// 可拷贝日志信息到SD卡
// 可在主界面添加事件回调,界面实时显示日志

// 添加回调
// 回调类
Log.LogCallbackListener listener = new LogCallbackListener() {
    @Override
    public void onLogArrived(Log data) {
        ...
    }
};
// 添加
Log.addCallbackListener(listener);

// 是否调用系统Android Log,可控制是否显示
Log.setCallLog(true);
// 是否开启写入文件,文件数量,单个文件大小(Mb)
// 默认存储在程序目录/Genius/Logs
Log.setSaveLog(true, 10, 1);
// 设置是否监听外部存储插入操作
// 开启:插入外部设备(SD)时,将拷贝日志文件到外部存储
// 此操作依赖于是否开启写入文件功能,未开启则此方法无效
Log.setCopyExternalStorage(true, "Test/Logs");

// 拷贝内部存储的日志文件到外部存储(SD)
// 此操作依赖于是否开启写入文件功能,未开启则此方法无效
Log.copyToExternalStorage("Test/Logs");

// 设置日志等级
// ALL(全部显示),VERBOSE到ERROR依次递减
Log.setLevel(Log.ALL);

// 添加日志
Log.d(TAG, "DEBUG ");


// ====================Tools====================
// 常用工具包
// 全部为静态方法,以后会持续添加完善

// 休眠
Tools.sleepIgnoreInterrupt(long time);
// 拷贝文件
Tools.copyFile(File source, File target);
// AndroidId
Tools.getAndroidId(Context context);
// SN编号
Tools.getSerialNumber();

配置权限

    <!-- 网络 权限 -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- 日志写文件 权限 -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <!-- getDeviceId 权限 -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    

你是开发者

下载本项目,项目可导入到 Android Studio,Android Studio >= 1.0

项目中含有一个库以及一个测试项目,可将库导入到自己的项目中使用。

Eclipse 中无法直接导入项目,请先建立一个项目按照对应目录拷贝到项目中。

反馈

在使用中有任何问题,欢迎能及时反馈给我,可以用以下联系方式跟我交流

捐助开发者

有兴趣、写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支付宝: qiujuer@live.cn );没钱捧个人场,谢谢各位。

关于我

  var info = {
    nickName  : "qiujuer",
    site : "http://www.qiujuer.net"
  }

License

Copyright 2014 CengaLabs.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Android Material theme and Tool library. 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/emaiqi/Genius-Android.git
git@gitee.com:emaiqi/Genius-Android.git
emaiqi
Genius-Android
Genius-Android
master

搜索帮助