├── .gitignore
├── LICENSE
├── README.md
├── art
├── blur.png
├── eclipse.png
├── material.gif
└── themes.png
├── build.gradle
├── docs
├── EclipseImport.md
└── NOTES.md
├── gradle.properties
├── library
├── .gitignore
├── build.gradle
├── gradle.properties
├── libs
│ ├── arm64-v8a
│ │ └── libgenius.so
│ ├── armeabi-v7a
│ │ └── libgenius.so
│ ├── armeabi
│ │ └── libgenius.so
│ ├── mips
│ │ └── libgenius.so
│ ├── mips64
│ │ └── libgenius.so
│ ├── x86
│ │ └── libgenius.so
│ └── x86_64
│ │ └── libgenius.so
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── net
│ │ └── qiujuer
│ │ └── genius
│ │ └── ApplicationTest.java
│ ├── jni
│ ├── Android.mk
│ ├── Application.mk
│ ├── BlurNative.c
│ └── BlurNative.h
│ └── main
│ ├── AndroidManifest.xml
│ ├── aidl
│ └── net
│ │ └── qiujuer
│ │ └── genius
│ │ └── command
│ │ └── ICommandInterface.aidl
│ ├── assets
│ └── fonts
│ │ ├── opensans_bold.ttf
│ │ ├── opensans_extrabold.ttf
│ │ ├── opensans_extralight.ttf
│ │ ├── opensans_light.ttf
│ │ ├── opensans_regular.ttf
│ │ ├── roboto_bold.ttf
│ │ ├── roboto_extrabold.ttf
│ │ ├── roboto_extralight.ttf
│ │ ├── roboto_light.ttf
│ │ └── roboto_regular.ttf
│ ├── java
│ └── net
│ │ └── qiujuer
│ │ └── genius
│ │ ├── Attributes.java
│ │ ├── Genius.java
│ │ ├── MaterialUI.java
│ │ ├── app
│ │ ├── BlurKit.java
│ │ ├── BlurNative.java
│ │ ├── HandlerPoster.java
│ │ ├── SyncPost.java
│ │ └── ToolKit.java
│ │ ├── command
│ │ ├── Command.java
│ │ ├── CommandExecutor.java
│ │ └── CommandService.java
│ │ ├── material
│ │ └── MaterialButton.java
│ │ ├── nettool
│ │ ├── DnsResolve.java
│ │ ├── NetModel.java
│ │ ├── Ping.java
│ │ ├── SimplePing.java
│ │ ├── SpeedRoad.java
│ │ ├── Telnet.java
│ │ └── TraceRoute.java
│ │ └── util
│ │ ├── FixedList.java
│ │ ├── GeniusException.java
│ │ ├── HashUtils.java
│ │ ├── Log.java
│ │ ├── LogWriter.java
│ │ └── Tools.java
│ └── res
│ └── values
│ ├── genius_attrs.xml
│ └── genius_colors.xml
├── maven_push.gradle
├── release
├── eclipse
│ ├── AndroidManifest.xml
│ ├── R.java
│ ├── aidl
│ │ └── net
│ │ │ └── qiujuer
│ │ │ └── genius
│ │ │ └── command
│ │ │ └── ICommandInterface.aidl
│ ├── assets
│ │ └── fonts
│ │ │ ├── opensans_bold.ttf
│ │ │ ├── opensans_extrabold.ttf
│ │ │ ├── opensans_extralight.ttf
│ │ │ ├── opensans_light.ttf
│ │ │ ├── opensans_regular.ttf
│ │ │ ├── roboto_bold.ttf
│ │ │ ├── roboto_extrabold.ttf
│ │ │ ├── roboto_extralight.ttf
│ │ │ ├── roboto_light.ttf
│ │ │ └── roboto_regular.ttf
│ ├── libs
│ │ ├── arm64-v8a
│ │ │ └── libgenius.so
│ │ ├── armeabi-v7a
│ │ │ └── libgenius.so
│ │ ├── armeabi
│ │ │ └── libgenius.so
│ │ ├── mips
│ │ │ └── libgenius.so
│ │ ├── mips64
│ │ │ └── libgenius.so
│ │ ├── x86
│ │ │ └── libgenius.so
│ │ └── x86_64
│ │ │ └── libgenius.so
│ └── res
│ │ └── values
│ │ ├── genius_attrs.xml
│ │ └── genius_colors.xml
├── genius_0.9.0.aar
└── genius_0.9.0.jar
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── net
│ │ └── qiujuer
│ │ └── sample
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── net
│ │ └── qiujuer
│ │ └── sample
│ │ ├── BlurActivity.java
│ │ ├── MainActivity.java
│ │ ├── MaterialActivity.java
│ │ └── TestCaseActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ ├── blur_img.png
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_blur.xml
│ ├── activity_main.xml
│ ├── activity_material.xml
│ └── activity_test_case.xml
│ ├── menu
│ └── menu_blur.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | .idea/
8 | *.iml
9 | /gradle
10 | gradlew
11 | gradlew.bat
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ReadMe
2 |
3 | ## Genius-Android是什么?
4 |
5 | **Genius-Android** 包含了 **Android** 中一些常用的的方法集合, **Genius** 库现提供5个基本板块:
6 |
7 | `app`(**Ui**) `material`(**控件**) `command`(**命令行**) `net tool`(**Ping、Dns...**) `util`(**常用方法,类**)
8 |
9 | 向我参考过的开源库作者致敬:
10 |
11 | `FlatUI`,`blurring`
12 |
13 |
14 | ## Screenshots
15 |
16 | ##### MaterialButton
17 |
18 |
19 | ##### Themes
20 |
21 |
22 | ##### BlurKit
23 |
24 |
25 |
26 | ## Genius-Android 库有哪些功能?
27 |
28 | * `app`
29 | > * `ToolKit` 可在子线程`同步`切换到主线程操作
30 | > * `ToolKit` 可在子线程`异步`切换到主线程操作
31 | > * `BlurKit` 可在`Java`端使用`FastBlur`算法模糊图片
32 | > * `BlurKit` 可在`Jni`端使用`FastBlur`算法模糊图片
33 |
34 | * `material`
35 | > * 内置字体 `opensans` `roboto`
36 | > * 字体颜色 `none` `dark` `light`
37 | > * 含有五种字体粗细样式切换
38 | > * 含有十二种主题颜色搭配
39 | > * `MaterialButton` 按钮
40 |
41 | * `command`
42 | > * 独立服务进程控制进程创建销毁
43 | > * 智能的进程管理服务
44 | > * 超高的并发效率,不担心缓冲区问题
45 | > * 简单的操作,与ProcessBuilder操作类似
46 | > * 智能的监听与自杀方式,保证进程不阻塞
47 | > * 子进程失败后自动重新调用执行,重复10次
48 | > * 保证语句正常执行不疏漏
49 | > * 一键化的启动与取消操作,自由控制
50 | > * 可同步与异步方式执行,异步事件通知
51 |
52 | * `net tool`
53 | > * 一键Ping操作,无需命令行,无需Root
54 | > * 一键DNS域名解析,可指定解析服务器
55 | > * 一键TelNet功能,对指定IP Port测试
56 | > * 一键TraceRoute,记录每一跳丢包与延时
57 | > * 一键的测速工具,对指定文件下载测试
58 | > * 控制随心,取消随心;不用关心细节问题
59 | > * 高并发的路由测试,可在40s左右测试完成
60 |
61 | * `util`
62 | > * 全局AppContext属性获取
63 | > * 方便的MD5运算,包括字符串与文件
64 | > * 线程休眠无需多加try catch模块
65 | > * 获取设备标识`ID`,`SN`
66 | > * `Log`:使用方式与Android日志Log一样
67 | > * `Log`:一键设置是否调用系统Log类
68 | > * `Log`:可一键设置日志级别,解决发布的烦恼
69 | > * `Log`:可实现将日志写入文件中保存以便查看分析
70 | > * `Log`:可实现将日志一键拷贝到外部存储设备中
71 | > * `Log`:可添加事件监听,方便界面显示日志信息
72 | > * `FixedList`:定长队列,自动弹出,保持队列数量
73 |
74 |
75 | ## 获取库
76 |
77 | * `Star` 和 `Fork` 本项目;这样方便获取以后更新内容。
78 | * `release` 文件夹中的 `*.jar` 或者 `*.aar` 文件可以直接导入到自己项目中。
79 | * `*.jar` 无法使用控件资源,如字体和 `R..`。
80 | * `*.aar` 能使用所有的类和控件以及字体等。
81 | * `*.aar` 本地引入方法:
82 | * `Eclipse` [完全导入使用方法详解](docs/EclipseImport.md)
83 | * `Android Studio` :
84 | * `*.aar` 本地导入方法:
85 |
86 | ```gradle
87 | // 需先拷贝 "genius_0.9.0.aar" 到 "libs" 目录
88 | android {
89 | repositories {
90 | flatDir { dirs 'libs' }
91 | }
92 | }
93 | dependencies {
94 | compile (name:'genius_0.9.0', ext:'aar')
95 | }
96 |
97 | ```
98 |
99 | * `*.aar` `MavenCentral`远程导入:
100 |
101 | ```gradle
102 | // 在项目 "build.gradle" 中添加
103 | // 无需拷贝任何文件,等待联网更新完成即可使用
104 | dependencies {
105 | compile 'com.github.qiujuer:genius:0.9.0'
106 | }
107 |
108 | ```
109 |
110 |
111 | ## 更新日志
112 |
113 | * 版本:0.9.0
114 | * 日期:2014-11-26 22:40
115 | * 日志:[更新日志](docs/NOTES.md)
116 |
117 |
118 | ## 使用方法
119 |
120 | ##### 初始化与销毁
121 |
122 | ```java
123 | // Command 使用模块必须初始化
124 | // Log 类如进行存储则需要初始化
125 | // 只使用控件与 net tool 模块可不初始化
126 | Genius.initialize(Application application);
127 | Genius.dispose();
128 |
129 | ```
130 |
131 |
132 | ##### `app` 模块
133 |
134 | ```java
135 | // "Runnable" 类实现其中 "run()" 方法
136 | // "run()" 运行在主线程中,可在其中进行界面操作
137 | // 同步进入主线程,等待主线程处理完成后继续执行子线程
138 | ToolKit.runOnMainThreadSync(Runnable runnable);
139 | // 异步进入主线程,无需等待
140 | ToolKit.runOnMainThreadAsync(Runnable runnable);
141 |
142 | // "bitmap" 待处理的图片
143 | // "radius" 图片模糊半径
144 | // "canReuseInBitmap" 是否在 "bitmap" 中进行模糊,
145 | // "false" 情况下将拷贝"bitmap"的副本进行模糊
146 | // 在"Java"中实现图片模糊
147 | BlurKit.fastBlurInJava(Bitmap bitmap, int radius, boolean canReuseInBitmap);
148 | // 在"Jni"中实现图片模糊,传给"Jni"的是图片像素集合"Array"
149 | BlurKit.fastBlurInJniArray(Bitmap bitmap, int radius, boolean canReuseInBitmap);
150 | // 在"Jni"中实现图片模糊,传给"Jni"的是图片类"Bitmap"
151 | BlurKit.fastBlurInJniBitmap(Bitmap bitmap, int radius, boolean canReuseInBitmap);
152 |
153 | ```
154 |
155 |
156 | ##### `material` 模块
157 |
158 | ```xml
159 | // 首先需要在根容器中指定:
160 |
163 |
164 | // 提供12种主题样式,见截图
165 | // 提供2种字体:`opensans` `roboto`
166 | // 字体粗细:`bold` `extrabold` `extralight` `light` `regular`
167 |
168 | // ==================MaterialButton==================
169 |
177 |
178 | // `gm_textAppearance`: 指定字体颜色,默认为 `none`
179 | // `gm_fontFamily`: 指定两种字体中的一种字体
180 | // `gm_fontWeight`: 指定字体粗细
181 | // `gm_isMaterial`: 是否打开 Material 动画,默认 `true`
182 | // `gm_isAutoMove`: 动画是否自动移动到中心,默认 `true`
183 | // 开启后动画将不会原地扩散,点击处 `XY` 坐标将向中心靠拢
184 | // `gm_theme`: 指定主题样式,12种任意选
185 |
186 | ```
187 |
188 |
189 | ##### `command` 模块
190 |
191 | ```java
192 | // 执行命令,后台服务自动控制
193 | // 调用方式与ProcessBuilder传参方式一样
194 | // 同步方式
195 | // 完成后结果直接返回
196 | Command command = new Command("/system/bin/ping",
197 | "-c", "4", "-s", "100",
198 | "www.baidu.com");
199 | String res = Command.command(command);
200 | Log.i(TAG, "Ping 测试结果:" + res);
201 |
202 | // 异步方式
203 | // 结果以事件回调方式返回
204 | Command command = new Command("/system/bin/ping",
205 | "-c", "4", "-s", "100",
206 | "www.baidu.com");
207 | Command.command(command, new Command.CommandListener() {
208 | @Override
209 | public void onCompleted(String str) {
210 | Log.i(TAG, "onCompleted:\n" + str);
211 | }
212 | @Override
213 | public void onCancel() {
214 | Log.i(TAG, "onCancel");
215 | }
216 | @Override
217 | public void onError() {
218 | Log.i(TAG, "onError");
219 | }
220 | });
221 |
222 | // 取消一个命令任务
223 | Command.cancel(Command command);
224 |
225 | // 销毁
226 | // 可调用 ‘Genius.dispose()’ 方法统一销毁
227 | Command.dispose();
228 |
229 | ```
230 |
231 |
232 | ##### `net tool` 模块
233 |
234 | ```java
235 | // Ping
236 | // 传入域名或者IP
237 | // 结果:是否执行成功、延时、丢包
238 | Ping ping = new Ping("www.baidu.com");
239 | // 开始
240 | ping.start();
241 | if (ping.getError() != NetModel.SUCCEED) {
242 | Log.i("异常");
243 | } else {
244 | Log.i(TAG,ping.toString());
245 | }
246 |
247 | // DNS
248 | // 传入域名 + 服务器地址
249 | // 结果:是否执行成功、延时、Ip地址集合
250 | DnsResolve dnsResolve = new DnsResolve("www.baidu.com");
251 | // 开始
252 | dnsResolve.start();
253 | if (dnsResolve.getError() != NetModel.SUCCEED) {
254 | Log.i("异常");
255 | } else {
256 | Log.i(TAG,dnsResolve.toString());
257 | }
258 | ...
259 | 其他的类似
260 | ...
261 |
262 | ```
263 |
264 | ##### `util` 模块
265 |
266 | ```java
267 | // ===================FixedList===================
268 | // 固定长度队列
269 | // 可指定长度,使用方法与普通队列类似
270 | // 当加入元素数量达到指定数量时将弹出元素
271 | // 头部插入尾部弹出,尾部插入头部弹出
272 |
273 | // 初始化最大长度为5
274 | FixedList list = new FixedList(5);
275 | // 使用Queue方法添加元素
276 | list.offer(0);
277 | // 使用List方法添加元素,两种方式操作是一样
278 | list.add(1);
279 | // 末尾插入元素与add一样
280 | list.addLast(1);
281 | // 从头部插入,默认删除尾部超出元素
282 | list.addFirst(19);
283 | // 添加一个列表
284 | list.addAll(new ArrayList());
285 |
286 | // 获取最大容量
287 | list.getMaxSize();
288 | // 调整最大长度;缩小长度时将自动删除头部多余元素
289 | list.setMaxSize(3);
290 |
291 | // 采用poll方式弹出元素
292 | int i = list.poll();
293 | // remove 与 poll 类似,不过不返回删除元素,仅删除一个元素
294 | list.remove();
295 | // 清空操作
296 | list.clear();
297 |
298 | // 可使用List操作
299 | List list1 = new FixedList(2);
300 | list1.add(1);
301 | list1.clear();
302 |
303 |
304 | // ====================HashUtils==================
305 | // 哈希计算(Md5)
306 | // 可计算字符串与文件Md5值
307 |
308 | // 获取字符串MD5
309 | String hash = HashUtils.getStringMd5(String str);
310 | // 获取文件MD5
311 | String hash = HashUtils.getFileMd5(File file);
312 |
313 |
314 | // ======================Log======================
315 | // 日志类
316 | // 调用方法与使用Android默认方法一样
317 | // 可设置其是否存储日志信息
318 | // 可拷贝日志信息到SD卡
319 | // 可在主界面添加事件回调,界面实时显示日志
320 |
321 | // 添加回调
322 | // 回调类
323 | Log.LogCallbackListener listener = new LogCallbackListener() {
324 | @Override
325 | public void onLogArrived(Log data) {
326 | //日志来了
327 | }
328 | };
329 | // 添加
330 | Log.addCallbackListener(listener);
331 |
332 | // 是否调用系统Android Log,可控制是否显示
333 | Log.setCallLog(true);
334 | // 是否开启写入文件,文件数量,单个文件大小(Mb)
335 | // 默认存储在程序目录/Genius/Logs
336 | Log.setSaveLog(true, 10, 1);
337 | // 设置是否监听外部存储插入操作
338 | // 开启:插入外部设备(SD)时,将拷贝日志文件到外部存储
339 | // 此操作依赖于是否开启写入文件功能,未开启则此方法无效
340 | Log.setCopyExternalStorage(true, "Test/Logs");
341 |
342 | // 拷贝内部存储的日志文件到外部存储(SD)
343 | // 此操作依赖于是否开启写入文件功能,未开启则此方法无效
344 | Log.copyToExternalStorage("Test/Logs");
345 |
346 | // 设置日志等级
347 | // ALL(全部显示),VERBOSE到ERROR依次递减
348 | Log.setLevel(Log.ALL);
349 | Log.setLevel(Log.INFO);
350 |
351 | // 添加日志
352 | Log.v(TAG, "日志 VERBOSE ");
353 | Log.d(TAG, "日志 DEBUG ");
354 | Log.i(TAG, "日志 INFO ");
355 | Log.w(TAG, "日志 WARN ");
356 | Log.e(TAG, "日志 ERROR ");
357 |
358 |
359 | // ====================ToolUtils====================
360 | // 常用工具包
361 | // 全部为静态方法,以后会持续添加完善
362 |
363 | // 休眠
364 | ToolUtils.sleepIgnoreInterrupt(long time);
365 | // 拷贝文件
366 | ToolUtils.copyFile(File source, File target);
367 | // AndroidId
368 | ToolUtils.getAndroidId(Context context);
369 | // SN编号
370 | ToolUtils.getSerialNumber();
371 |
372 | ```
373 |
374 |
375 | ## 配置权限
376 |
377 | ```xml
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 | ```
387 |
388 |
389 | ## 你是开发者
390 |
391 | 下载本项目,项目可导入到 `Android Studio`,Android Studio >= 1.0 RC 1
392 |
393 | 项目里边含有一个库以及一个测试项目,可将库导入到自己的项目中使用。
394 |
395 | 'Eclipse' 中无法直接导入项目,请先建立一个项目按照对应目录替换到自己项目中。
396 |
397 |
398 | ## 反馈
399 |
400 | 在使用中有任何问题,欢迎能及时反馈给我,可以用以下联系方式跟我交流
401 |
402 | * 项目:[提交Bug或想法](https://github.com/qiujuer/Genius-Android/issues)
403 | * 邮件:[qiujuer@live.cn](mailto:qiujuer@live.cn)
404 | * QQ: 756069544
405 | * Weibo: [@qiujuer](http://weibo.com/qiujuer)
406 | * 网站:[www.qiujuer.net](http://www.qiujuer.net)
407 |
408 |
409 | ## 捐助开发者
410 |
411 | 在兴趣的驱动下,写一个`免费`的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。
412 | 当然,有钱捧个钱场(支付宝: `qiujuer@live.cn` );没钱捧个人场,谢谢各位。
413 |
414 |
415 | ## 关于我
416 |
417 | ```javascript
418 | var info = {
419 | nickName : "qiujuer",
420 | site : "http://www.qiujuer.net"
421 | }
422 | ```
423 |
424 |
425 | License
426 | --------
427 |
428 | Copyright 2014 CengaLabs.
429 |
430 | Licensed under the Apache License, Version 2.0 (the "License");
431 | you may not use this file except in compliance with the License.
432 | You may obtain a copy of the License at
433 |
434 | http://www.apache.org/licenses/LICENSE-2.0
435 |
436 | Unless required by applicable law or agreed to in writing, software
437 | distributed under the License is distributed on an "AS IS" BASIS,
438 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
439 | See the License for the specific language governing permissions and
440 | limitations under the License.
441 |
442 |
--------------------------------------------------------------------------------
/art/blur.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/art/blur.png
--------------------------------------------------------------------------------
/art/eclipse.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/art/eclipse.png
--------------------------------------------------------------------------------
/art/material.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/art/material.gif
--------------------------------------------------------------------------------
/art/themes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/art/themes.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:0.14.4'
9 | }
10 | }
11 |
12 | allprojects {
13 | version = VERSION_NAME
14 | group = POM_GROUP_ID
15 |
16 | repositories {
17 | mavenCentral()
18 | }
19 | }
20 | ext {
21 | compileSdkVersion = 20
22 | buildToolsVersion = "20.0.0"
23 | }
24 |
25 | apply plugin: 'android-reporting'
--------------------------------------------------------------------------------
/docs/EclipseImport.md:
--------------------------------------------------------------------------------
1 | # Eclipse Import
2 |
3 | ## 为什么要写这份文档?
4 |
5 | 在使用中,我经常遇到有朋友问我, **Eclipse** 导入后怎么不能使用控件的问题;在这里我只能说抱歉了!
6 |
7 | 如果在 **Android Studio** 中只需要导入本地 `aar` 或者采用远程的方式,一行代码就能引入整个包,包含全部的功能;甚至不需要自己写权限和配置。
8 |
9 | 是的的确是这样,这是因为 `aar` 包中包含了 `Jar,jni,aidl,AndroidManifest,assets,res,R.java` 这些是一个完整的 **Library** .
10 |
11 | 而在**Eclipse**中通常引入一个包都是导入 `Jar` 就算完事儿了;虽然在 Jar 中包含了大部分的代码,但是如果遇到需要资源的情况就无能为力了;所以要使用控件就必须自己导入其他部分。
12 |
13 |
14 | ## Jar
15 |
16 | 这个步骤我相信,没有朋友不会的吧?
17 | 简单的说,拷贝 **Jar** 文件到 **Eclipse** 的项目 `Libs` 文件夹下。
18 | 然后在项目中包含进去就OK。
19 |
20 | 在引入了 **Jar** 的情况下,可以使用完整的 `Util` 包中的方法,以及 `App` 包中的 `ToolKit` 类。
21 |
22 |
23 | ## Jni
24 |
25 | 这个的导入其实与 **Jar** 相似,在这里我生成了各个平台的 `so` 文件,你可以拷贝对应平台文件夹或者拷贝项目中完整的 `release\eclipse\libs` 文件夹到你自己项目的 `libs` 中。
26 |
27 | 这个拷贝进去就算Ok,不用在项目中设置什么,唯一保证的就是不改变名称;完全拷贝。
28 | 在引入了 `Jni so` 文件后,你现在可以使用 `App` 包中的 `BlurKit` 类来模糊你的图片了,当然没有导入的情况下,你也是可以使用 `BlurKit` 中的 `Java` 方法来模糊你的图片操作的。
29 |
30 |
31 | ## aidl
32 |
33 | 这个是用于使用 `Command` 包所必需的接口。在 `Command` 中是采用的独立进程模式所以需要使用 `aidl` 接口来交互数据。
34 | 不过这个无需多此一举的配置什么,因为其接口已经打包到 `Jar` 中了;如果你实在是要配置:
35 | * 那么请在你的项目中建立 `aidl`
36 | * 并在其下建立包:`net.qiujuer.genius.command`
37 | * 然后在此包下建立文件 :`ICommandInterface.aidl`
38 | * 最后写入代码:
39 |
40 | ```java
41 | // ICommandInterface.aidl
42 | package net.qiujuer.genius.command;
43 |
44 | // Declare any non-default types here with import statements
45 | interface ICommandInterface {
46 | String command(String id, String params);
47 | void cancel(String id);
48 | void dispose();
49 | int getTaskCount();
50 | }
51 | ```
52 |
53 | 此时你还不能使用 `Command` 模块,因为你最差的是 `CommandService` 服务的配置。
54 |
55 |
56 | ## AndroidManifest
57 |
58 | 在这一步你需要打开你的项目 `AndroidManifest` 文件:
59 | ##### 权限
60 |
61 | ```xml
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | ```
71 |
72 | ##### CommandService
73 |
74 | ```xml
75 |
76 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | ```
88 |
89 | 经过以上两步后你现在能使用 `Command` 与 `net tool` 模块了。
90 |
91 |
92 | ## assets
93 |
94 | 这一步中,你需要拷贝项目根目录 `release/eclipse/assets` 中的字体文件到你自己项目中的 `assets` 文件夹中。
95 | 这是为后面支持 `material` 模块中控件的字体属性做准备。
96 |
97 |
98 | ## res
99 |
100 | 在这一步中,你需要拷贝项目根目录 `release/eclipse/res/values` 中的 `xml` 文件到你自己项目中的 `res/value` 文件夹中。
101 | 这是为后面支持 `material` 模块中控件的颜色以及属性的配置文件。
102 |
103 |
104 | ## R.java
105 |
106 | 这是最后一步了,很多人前面都完成了,但是唯独这一步没有做,导致使用控件的时候说 `属性` 加载失败。
107 | 在这一步中,你需要这样操作:
108 | * 在你的项目中找到 `gen` 目录
109 | * 在其下建立包: `net.qiujuer.genius`
110 | * 拷贝项目根目录 `release/eclipse/R.java` 文件到所建立的包中。
111 |
112 |
113 | 到这里你的项目能正常使用所有板块了,包括控件板块。当然你或许需要刷新一下你的项目。
114 |
115 |
116 | ## Picture
117 |
118 |
119 |
120 |
121 | ## 关于我
122 |
123 | ```javascript
124 | var info = {
125 | nickName : "qiujuer",
126 | site : "http://www.qiujuer.net"
127 | }
128 | ```
129 |
130 |
131 | License
132 | --------
133 |
134 | Copyright 2014 CengaLabs.
135 |
136 | Licensed under the Apache License, Version 2.0 (the "License");
137 | you may not use this file except in compliance with the License.
138 | You may obtain a copy of the License at
139 |
140 | http://www.apache.org/licenses/LICENSE-2.0
141 |
142 | Unless required by applicable law or agreed to in writing, software
143 | distributed under the License is distributed on an "AS IS" BASIS,
144 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145 | See the License for the specific language governing permissions and
146 | limitations under the License.
147 |
148 |
--------------------------------------------------------------------------------
/docs/NOTES.md:
--------------------------------------------------------------------------------
1 | * 2014/9/2 修改GLog方法"addLogCallbackListener()"为:"addCallbackListener()"。
2 | * 2014/9/2 解决GLog回调时出现:"java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()" Bug。
3 | * 2014/9/2 修复因为日志消息传输问题导致的服务调用日志类出现的程序死掉问题。
4 | * 2014/9/2 GLog与Command类添加"destroy()"方法用于释放资源。
5 | * 2014/9/2 Publish Version-0.1.0.
6 |
7 |
8 | * 2014/9/6 更改日志部分Bug。
9 | * 2014/9/6 修改命令行执行部分,更改了服务实现与接口释放。
10 | * 2014/9/6 命令行执行添加异步执行方法。
11 | * 2014/9/6 命令执行类删除回调方式等待,采用有次数等待方式。
12 | * 2014/9/6 添加新的UI项目。
13 | * 2014/9/6 Material Button实现。
14 | * 2014/9/8 Publish Version-0.1.1.
15 |
16 |
17 | * 2014/9/18 程序注释等英文化。
18 | * 2014/9/20 Log精简化,删除内存缓存及通知功能。
19 | * 2014/9/21 ToolUtils添加文件拷贝,或许系统唯一标识等方法。
20 | * 2014/9/22 Command精炼化,添加取消任务功能。
21 | * 2014/9/23 Command服务添加自动停止功能,与销毁功能。
22 | * 2014/9/24 添加NetTool模块,提供Ping/DNS等常见功能使用。
23 | * 2014/9/24 添加HashUtils模块,提供对字符串与文件计算MD5。
24 | * 2014/9/28 库添加初始化与销毁方法。
25 | * 2014/9/30 Publish Version-0.4.0.
26 |
27 |
28 | * 2014/10/2 简化Log设置文件存储的方法调用
29 | * 2014/10/2 Log与Command抛出异常语句统一化
30 | * 2014/10/2 修改NetTool中toString方法的Bug
31 | * 2014/10/3 添加FixedList固定队列
32 | * 2014/10/4 添加App相关UiTool与UiModel
33 | * 2014/10/5 修复TraceRoute,Dns解析中解析失败时结果为null时触发异常
34 | * 2014/10/5 更新README,更新SAMPLE
35 | * 2014/10/5 Publish Version-0.6.5.
36 |
37 |
38 | * 2014/10/5 调整属性样式
39 | * 2014/10/5 公布Material Button
40 | * 2014/10/5 添加截图等工作
41 | * 2014/10/5 更新README,更新SAMPLE
42 | * 2014/10/5 Publish Version-0.6.8.
43 |
44 |
45 | * 2014/10/9 更改域名解析传入服务器地址参数为:InetAddress
46 | * 2014/10/9 更改域名解析有服务器情况下超时时间为8秒
47 | * 2014/10/10 更改域名解析实例化是传入服务器参数为:InetAddress
48 | * 2014/10/10 删除命令行执行中产生的日志信息
49 | * 2014/10/11 MaterialButton 调整速度参数
50 | * 2014/10/11 MaterialButton 支持近似正方形情况
51 | * 2014/10/11 MaterialButton 添加新属性AutoMove,自动移动到中间
52 | * 2014/10/11 更新项目截图
53 | * 2014/10/12 Publish Version-0.7.5.
54 |
55 |
56 | * 2014/10/27 修复Material按钮竖直情况下动画BUG
57 | * 2014/10/27 更改README,添加Jar包模式下配置信息
58 | * 2014/10/27 Publish Version-0.7.6.
59 |
60 |
61 | * 2014/11/21 Log方法添加直接拷贝日志到外部存储方法
62 | * 2014/11/21 取消Log初始化开启日志存储时的位置指定参数
63 | * 2014/11/21 修改README,更正Log传参错误示例
64 | * 2014/11/21 Publish Version-0.7.9.
65 |
66 |
67 | * 2014/11/24 微调 `Log` 中发送消息方法
68 | * 2014/11/24 删除掉 `UiTool` 类
69 | * 2014/11/24 新增 `ToolKit` 代替 `UiTool` ,完成同样工作的同时无需传入Activity,传入Runnable类即可
70 | * 2014/11/25 编写 `Jni FastBlur` 实现模糊效果
71 | * 2014/11/25 `Jni` 生成 so 文件完成
72 | * 2014/11/25 编写 `BlurKit` 类,添加 `FastBlur` 方法用于模糊图片
73 | * 2014/11/26 添加图片模糊案例
74 | * 2014/11/26 删除 `Jni` 中加载的 `android/log` 头文件
75 | * 2014/11/26 重新生成 `Jni` 文件so
76 | * 2014/11/26 修改 `util/ToolUtils` 类名为 `Tools`
77 | * 2014/11/26 删除 `util/Tools` 类中不常用方法:`getDeviceId()` `isAvailablePackage()`
78 | * 2014/11/26 更改资源 `attrs_material` 为 `genius_attrs`
79 | * 2014/11/26 更改资源 `colors` 为 `genius_colors`
80 | * 2014/11/26 更名日志 `Log.txt` 为工作记录 `NOTES.md`
81 | * 2014/11/26 添加文档文件夹并添加Eclipse完全导入说明书 `Log.txt` 为工作记录 `NOTES.md`
82 | * 2014/11/26 更改 `LogWriter` 类中锁的释放,解决其在特定情况下出现死锁情况
83 | * 2014/11/26 优化 `Log` 类回调部分,更改Handle为自定义线程类实现,优化效率
84 | * 2014/11/26 修改测试用例部分命名,以及删除多余部分
85 | * 2014/11/26 删除 `MaterialRectButton`,以及删除多余属性文件
86 | * 2014/11/26 修改 `README` 准备发布相关
87 | * 2014/11/26 完善相关文档,包括 **Eclipse** 导入方法
88 | * 2014/11/26 Publish Version-0.9.0.
89 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=0.9.0-SNAPSHOT
2 | VERSION_CODE=88
3 |
4 | POM_GROUP_ID=com.github.qiujuer
5 | POM_DESCRIPTION=Genius Lib For Android
6 | POM_URL=https://github.com/qiujuer/Genius-Android
7 | POM_SCM_URL=https://github.com/qiujuer/Genius-Android
8 | POM_SCM_CONNECTION=scm:git@github.com:qiujuer/Genius-Android.git
9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:qiujuer/Genius-Android.git
10 | POM_LICENCE_COMMENTS=A business-friendly OSS license
11 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
12 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
13 | POM_LICENCE_DIST=repo
14 | POM_DEVELOPER_ID=qiujuer
15 | POM_DEVELOPER_NAME=Qiu Ju
16 | POM_DEVELOPER_EMAIL=qiujuer@live.cn
17 | POM_DEVELOPER_URL=http://www.qiujuer.net
18 | POM_ISSUE_MANAGEMENT_SYSTEM=Github
19 | POM_ISSUE_MANAGEMENT_URL=https://github.com/qiujuer/Genius-Android/issues
20 | POM_INCEPTION_YEAR=2014
21 |
22 | ANDROID_BUILD_MIN_SDK_VERSION=15
23 | ANDROID_BUILD_TARGET_SDK_VERSION=20
24 | ANDROID_BUILD_TOOLS_VERSION=21.1.1
25 | ANDROID_BUILD_SDK_VERSION=20
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION as int
5 | buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
6 |
7 | defaultConfig {
8 | applicationId "net.qiujuer.genius"
9 | minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION as int
10 | targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION as int
11 | versionCode VERSION_CODE as int
12 | versionName VERSION_NAME
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | compileOptions {
23 | sourceCompatibility JavaVersion.VERSION_1_7
24 | targetCompatibility JavaVersion.VERSION_1_7
25 | }
26 |
27 | sourceSets {
28 | main {
29 | manifest.srcFile 'src/main/AndroidManifest.xml'
30 | java.srcDirs = ['src/main/java']
31 | res.srcDirs = ['src/main/res']
32 | jniLibs.srcDirs = ['libs']
33 | }
34 | }
35 |
36 | lintOptions {
37 | abortOnError false
38 | }
39 | }
40 |
41 | dependencies {
42 | }
43 |
44 | task clearJar(type: Delete) {
45 | delete 'build/libs/' + POM_ARTIFACT_ID + '_' + VERSION_NAME + '.jar'
46 | }
47 |
48 | task makeJar(type: Copy) {
49 | from('build/intermediates/bundles/release/')
50 | into('../release/')
51 | include('classes.jar')
52 | rename('classes.jar', POM_ARTIFACT_ID + '_' + VERSION_NAME + '.jar')
53 | }
54 | makeJar.dependsOn(clearJar, build)
55 |
56 | apply from: '../maven_push.gradle'
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Genius Android Lib
2 | POM_ARTIFACT_ID=genius
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/library/libs/arm64-v8a/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/arm64-v8a/libgenius.so
--------------------------------------------------------------------------------
/library/libs/armeabi-v7a/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/armeabi-v7a/libgenius.so
--------------------------------------------------------------------------------
/library/libs/armeabi/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/armeabi/libgenius.so
--------------------------------------------------------------------------------
/library/libs/mips/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/mips/libgenius.so
--------------------------------------------------------------------------------
/library/libs/mips64/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/mips64/libgenius.so
--------------------------------------------------------------------------------
/library/libs/x86/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/x86/libgenius.so
--------------------------------------------------------------------------------
/library/libs/x86_64/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/libs/x86_64/libgenius.so
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/DevelopTools/Android/SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/net/qiujuer/genius/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := genius
6 | LOCAL_SRC_FILES := BlurNative.c
7 | LOCAL_LDLIBS := -lm -llog -ljnigraphics
8 |
9 | include $(BUILD_SHARED_LIBRARY)
--------------------------------------------------------------------------------
/library/src/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_ABI := all
2 | APP_PLATFORM:= android-21
3 | APP_OPTIM := release
--------------------------------------------------------------------------------
/library/src/jni/BlurNative.c:
--------------------------------------------------------------------------------
1 | /*************************************************
2 | Copyright: Copyright QIUJUER 2014.
3 | Author: QiuJu
4 | Date: 2014-11-26
5 | Description:Realize image blurred images blurred
6 | **************************************************/
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #define ABS(a) ((a)<(0)?(-a):(a))
13 | #define MAX(a,b) ((a)>(b)?(a):(b))
14 | #define MIN(a,b) ((a)<(b)?(a):(b))
15 |
16 | /*************************************************
17 | Function: StackBlur
18 | Description: Using stack way blurred image pixels
19 | Calls: malloc
20 | Table Accessed: NULL
21 | Table Updated: NULL
22 | Input: Collection of pixels, wide image, image is high, the blur radius
23 | Output: After return to fuzzy collection of pixels
24 | Return: After return to fuzzy collection of pixels
25 | Others: NULL
26 | *************************************************/
27 | int* stackBlur(int* pix, int w, int h, int radius) {
28 | int wm = w - 1;
29 | int hm = h - 1;
30 | int wh = w * h;
31 | int div = radius + radius + 1;
32 |
33 | int *r = (int *)malloc(wh * sizeof(int));
34 | int *g = (int *)malloc(wh * sizeof(int));
35 | int *b = (int *)malloc(wh * sizeof(int));
36 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
37 |
38 | int *vmin = (int *)malloc(MAX(w,h) * sizeof(int));
39 |
40 | int divsum = (div + 1) >> 1;
41 | divsum *= divsum;
42 | int *dv = (int *)malloc(256 * divsum * sizeof(int));
43 | for (i = 0; i < 256 * divsum; i++) {
44 | dv[i] = (i / divsum);
45 | }
46 |
47 | yw = yi = 0;
48 |
49 | int(*stack)[3] = (int(*)[3])malloc(div * 3 * sizeof(int));
50 | int stackpointer;
51 | int stackstart;
52 | int *sir;
53 | int rbs;
54 | int r1 = radius + 1;
55 | int routsum, goutsum, boutsum;
56 | int rinsum, ginsum, binsum;
57 |
58 | for (y = 0; y < h; y++) {
59 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
60 | for (i = -radius; i <= radius; i++) {
61 | p = pix[yi + (MIN(wm, MAX(i, 0)))];
62 | sir = stack[i + radius];
63 | sir[0] = (p & 0xff0000) >> 16;
64 | sir[1] = (p & 0x00ff00) >> 8;
65 | sir[2] = (p & 0x0000ff);
66 |
67 | rbs = r1 - ABS(i);
68 | rsum += sir[0] * rbs;
69 | gsum += sir[1] * rbs;
70 | bsum += sir[2] * rbs;
71 | if (i > 0) {
72 | rinsum += sir[0];
73 | ginsum += sir[1];
74 | binsum += sir[2];
75 | }
76 | else {
77 | routsum += sir[0];
78 | goutsum += sir[1];
79 | boutsum += sir[2];
80 | }
81 | }
82 | stackpointer = radius;
83 |
84 | for (x = 0; x < w; x++) {
85 |
86 | r[yi] = dv[rsum];
87 | g[yi] = dv[gsum];
88 | b[yi] = dv[bsum];
89 |
90 | rsum -= routsum;
91 | gsum -= goutsum;
92 | bsum -= boutsum;
93 |
94 | stackstart = stackpointer - radius + div;
95 | sir = stack[stackstart % div];
96 |
97 | routsum -= sir[0];
98 | goutsum -= sir[1];
99 | boutsum -= sir[2];
100 |
101 | if (y == 0) {
102 | vmin[x] = MIN(x + radius + 1, wm);
103 | }
104 | p = pix[yw + vmin[x]];
105 |
106 | sir[0] = (p & 0xff0000) >> 16;
107 | sir[1] = (p & 0x00ff00) >> 8;
108 | sir[2] = (p & 0x0000ff);
109 |
110 | rinsum += sir[0];
111 | ginsum += sir[1];
112 | binsum += sir[2];
113 |
114 | rsum += rinsum;
115 | gsum += ginsum;
116 | bsum += binsum;
117 |
118 | stackpointer = (stackpointer + 1) % div;
119 | sir = stack[(stackpointer) % div];
120 |
121 | routsum += sir[0];
122 | goutsum += sir[1];
123 | boutsum += sir[2];
124 |
125 | rinsum -= sir[0];
126 | ginsum -= sir[1];
127 | binsum -= sir[2];
128 |
129 | yi++;
130 | }
131 | yw += w;
132 | }
133 | for (x = 0; x < w; x++) {
134 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
135 | yp = -radius * w;
136 | for (i = -radius; i <= radius; i++) {
137 | yi = MAX(0, yp) + x;
138 |
139 | sir = stack[i + radius];
140 |
141 | sir[0] = r[yi];
142 | sir[1] = g[yi];
143 | sir[2] = b[yi];
144 |
145 | rbs = r1 - ABS(i);
146 |
147 | rsum += r[yi] * rbs;
148 | gsum += g[yi] * rbs;
149 | bsum += b[yi] * rbs;
150 |
151 | if (i > 0) {
152 | rinsum += sir[0];
153 | ginsum += sir[1];
154 | binsum += sir[2];
155 | }
156 | else {
157 | routsum += sir[0];
158 | goutsum += sir[1];
159 | boutsum += sir[2];
160 | }
161 |
162 | if (i < hm) {
163 | yp += w;
164 | }
165 | }
166 | yi = x;
167 | stackpointer = radius;
168 | for (y = 0; y < h; y++) {
169 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
170 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
171 |
172 | rsum -= routsum;
173 | gsum -= goutsum;
174 | bsum -= boutsum;
175 |
176 | stackstart = stackpointer - radius + div;
177 | sir = stack[stackstart % div];
178 |
179 | routsum -= sir[0];
180 | goutsum -= sir[1];
181 | boutsum -= sir[2];
182 |
183 | if (x == 0) {
184 | vmin[y] = MIN(y + r1, hm) * w;
185 | }
186 | p = x + vmin[y];
187 |
188 | sir[0] = r[p];
189 | sir[1] = g[p];
190 | sir[2] = b[p];
191 |
192 | rinsum += sir[0];
193 | ginsum += sir[1];
194 | binsum += sir[2];
195 |
196 | rsum += rinsum;
197 | gsum += ginsum;
198 | bsum += binsum;
199 |
200 | stackpointer = (stackpointer + 1) % div;
201 | sir = stack[stackpointer];
202 |
203 | routsum += sir[0];
204 | goutsum += sir[1];
205 | boutsum += sir[2];
206 |
207 | rinsum -= sir[0];
208 | ginsum -= sir[1];
209 | binsum -= sir[2];
210 |
211 | yi += w;
212 | }
213 | }
214 |
215 | free(r);
216 | free(g);
217 | free(b);
218 | free(vmin);
219 | free(dv);
220 | free(stack);
221 | return(pix);
222 | }
223 |
224 |
225 | JNIEXPORT void JNICALL Java_net_qiujuer_genius_app_BlurNative_fastBlurArray
226 | (JNIEnv *env, jclass obj, jintArray arrIn, jint w, jint h, jint r)
227 | {
228 | jint *pix;
229 | // cpp:
230 | // pix = (env)->GetIntArrayElements(arrIn, 0);
231 | pix = (*env)->GetIntArrayElements(env, arrIn, 0);
232 | if (pix == NULL)
233 | return;
234 | // Start
235 | pix = stackBlur(pix, w, h, r);
236 | // End
237 |
238 | // if return:
239 | // int size = w * h;
240 | // jintArray result = env->NewIntArray(size);
241 | // env->SetIntArrayRegion(result, 0, size, pix);
242 | // cpp:
243 | // (env)->ReleaseIntArrayElements(arrIn, pix, 0);
244 | (*env)->ReleaseIntArrayElements(env, arrIn, pix, 0);
245 | // return result;
246 | }
247 |
248 | JNIEXPORT void JNICALL Java_net_qiujuer_genius_app_BlurNative_fastBlurBitmap
249 | (JNIEnv *env, jclass obj, jobject bitmapIn, jint r)
250 | {
251 | AndroidBitmapInfo infoIn;
252 | void* pixelsIn;
253 | int ret;
254 |
255 | // Get image info
256 | if ((ret = AndroidBitmap_getInfo(env, bitmapIn, &infoIn)) < 0)
257 | return;
258 | // Check image
259 | if (infoIn.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
260 | return;
261 | // Lock all images
262 | if ((ret = AndroidBitmap_lockPixels(env, bitmapIn, &pixelsIn)) < 0) {
263 | //AndroidBitmap_lockPixels failed!
264 | }
265 | // height width
266 | int h = infoIn.height;
267 | int w = infoIn.width;
268 |
269 | // Start
270 | pixelsIn = stackBlur((int*)pixelsIn, w, h, r);
271 | // End
272 |
273 | // Unlocks everything
274 | AndroidBitmap_unlockPixels(env, bitmapIn);
275 | }
--------------------------------------------------------------------------------
/library/src/jni/BlurNative.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class net_qiujuer_genius_app_BlurNative */
4 |
5 | #ifndef _Included_net_qiujuer_genius_app_BlurNative
6 | #define _Included_net_qiujuer_genius_app_BlurNative
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: net_qiujuer_genius_app_BlurNative
12 | * Method: fastBlurArray
13 | * Signature: ([IIII)V
14 | */
15 | JNIEXPORT void JNICALL Java_net_qiujuer_genius_app_BlurNative_fastBlurArray
16 | (JNIEnv *, jclass, jintArray, jint, jint, jint);
17 |
18 | /*
19 | * Class: net_qiujuer_genius_app_BlurNative
20 | * Method: fastBlurBitmap
21 | * Signature: (Landroid/graphics/Bitmap;I)V
22 | */
23 | JNIEXPORT void JNICALL Java_net_qiujuer_genius_app_BlurNative_fastBlurBitmap
24 | (JNIEnv *, jclass, jobject, jint);
25 |
26 | #ifdef __cplusplus
27 | }
28 | #endif
29 | #endif
30 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/library/src/main/aidl/net/qiujuer/genius/command/ICommandInterface.aidl:
--------------------------------------------------------------------------------
1 | // ICommandInterface.aidl
2 | package net.qiujuer.genius.command;
3 |
4 | // Declare any non-default types here with import statements
5 |
6 | interface ICommandInterface {
7 | String command(String id, String params);
8 | void cancel(String id);
9 | void dispose();
10 | int getTaskCount();
11 | }
12 |
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/opensans_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/opensans_bold.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/opensans_extrabold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/opensans_extrabold.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/opensans_extralight.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/opensans_extralight.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/opensans_light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/opensans_light.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/opensans_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/opensans_regular.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/roboto_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/roboto_bold.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/roboto_extrabold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/roboto_extrabold.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/roboto_extralight.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/roboto_extralight.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/roboto_light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/roboto_light.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/fonts/roboto_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/library/src/main/assets/fonts/roboto_regular.ttf
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/Attributes.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Color;
5 |
6 | /**
7 | * Created by QiuJu
8 | * on 2014/9/3.
9 | */
10 | public class Attributes {
11 |
12 | public static int INVALID = -1;
13 |
14 | public static int DEFAULT_THEME = R.array.blood;
15 |
16 | public static final String DEFAULT_FONT_FAMILY = "roboto";
17 | public static final String DEFAULT_FONT_WEIGHT = "light";
18 | public static final String DEFAULT_FONT_EXTENSION = "ttf";
19 | public static final int DEFAULT_TEXT_APPEARANCE = 0;
20 |
21 | public static int DEFAULT_RADIUS_DP = 4;
22 | public static int DEFAULT_BORDER_WIDTH_DP = 2;
23 | public static int DEFAULT_SIZE_DP = 10;
24 |
25 | public static int DEFAULT_RADIUS_PX = 10;
26 | public static int DEFAULT_BORDER_WIDTH_PX = 4;
27 | public static int DEFAULT_SIZE_PX = 20;
28 |
29 | /**
30 | * Color related fields
31 | */
32 | private int[] colors;
33 | private int theme = -1;
34 |
35 | /**
36 | * Font related fields
37 | */
38 | private String fontFamily = DEFAULT_FONT_FAMILY;
39 | private String fontWeight = DEFAULT_FONT_WEIGHT;
40 | private String fontExtension = DEFAULT_FONT_EXTENSION;
41 | private int textAppearance = DEFAULT_TEXT_APPEARANCE;
42 |
43 | /**
44 | * Size related fields
45 | */
46 | private int radius = DEFAULT_RADIUS_PX;
47 | private int size = DEFAULT_SIZE_PX;
48 | private int borderWidth = DEFAULT_BORDER_WIDTH_PX;
49 |
50 | private boolean isMaterial = true;
51 | private boolean isAutoMove = true;
52 |
53 | /**
54 | * Attribute change listener. Used to redraw the view when attributes are changed.
55 | */
56 | private AttributeChangeListener attributeChangeListener;
57 |
58 | public Attributes(AttributeChangeListener attributeChangeListener, Resources resources) {
59 | this.attributeChangeListener = attributeChangeListener;
60 | setThemeSilent(DEFAULT_THEME, resources);
61 | }
62 |
63 | public int getTheme() {
64 | return theme;
65 | }
66 |
67 | public void setTheme(int theme, Resources resources) {
68 | setThemeSilent(theme, resources);
69 | attributeChangeListener.onThemeChange();
70 | }
71 |
72 | public void setThemeSilent(int theme, Resources resources) {
73 | try {
74 | this.theme = theme;
75 | colors = resources.getIntArray(theme);
76 | } catch (Resources.NotFoundException e) {
77 |
78 | // setting theme blood if exception occurs (especially used for preview rendering by IDE)
79 | colors = new int[]{Color.parseColor("#732219"), Color.parseColor("#a63124"),
80 | Color.parseColor("#d94130"), Color.parseColor("#f2b6ae")};
81 | }
82 | }
83 |
84 | public void setColors(int[] colors) {
85 | this.colors = colors;
86 | attributeChangeListener.onThemeChange();
87 | }
88 |
89 | public int getColor(int colorPos) {
90 | return colors[colorPos];
91 | }
92 |
93 | public String getFontFamily() {
94 | return fontFamily;
95 | }
96 |
97 | public void setFontFamily(String fontFamily) {
98 | if (fontFamily != null && !fontFamily.equals("") && !fontFamily.equals("null"))
99 | this.fontFamily = fontFamily;
100 | }
101 |
102 | public String getFontWeight() {
103 | return fontWeight;
104 | }
105 |
106 | public void setFontWeight(String fontWeight) {
107 | if (fontWeight != null && !fontWeight.equals("") && !fontWeight.equals("null"))
108 | this.fontWeight = fontWeight;
109 | }
110 |
111 | public String getFontExtension() {
112 | return fontExtension;
113 | }
114 |
115 | public void setFontExtension(String fontExtension) {
116 | if (fontExtension != null && !fontExtension.equals("") && !fontExtension.equals("null"))
117 | this.fontExtension = fontExtension;
118 | }
119 |
120 | public int getRadius() {
121 | return radius;
122 | }
123 |
124 | public float[] getOuterRadius() {
125 | return new float[]{radius, radius, radius, radius, radius, radius, radius, radius};
126 | }
127 |
128 | public void setRadius(int radius) {
129 | this.radius = radius;
130 | }
131 |
132 | public int getSize() {
133 | return size;
134 | }
135 |
136 | public void setSize(int size) {
137 | this.size = size;
138 | }
139 |
140 | public int getBorderWidth() {
141 | return borderWidth;
142 | }
143 |
144 | public void setBorderWidth(int borderWidth) {
145 | this.borderWidth = borderWidth;
146 | }
147 |
148 | public int getTextAppearance() {
149 | return textAppearance;
150 | }
151 |
152 | public void setTextAppearance(int textAppearance) {
153 | this.textAppearance = textAppearance;
154 | }
155 |
156 | public boolean isMaterial() {
157 | return isMaterial;
158 | }
159 |
160 | public void setMaterial(boolean isMaterial) {
161 | this.isMaterial = isMaterial;
162 | }
163 |
164 | public void setAutoMove(boolean isAutoMove) {
165 | this.isAutoMove = isAutoMove;
166 | }
167 |
168 | public boolean isAutoMove() {
169 | return isAutoMove;
170 | }
171 |
172 | public interface AttributeChangeListener {
173 | public void onThemeChange();
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/Genius.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius;
2 |
3 | import android.app.Application;
4 |
5 | import net.qiujuer.genius.app.ToolKit;
6 | import net.qiujuer.genius.command.Command;
7 | import net.qiujuer.genius.util.Log;
8 |
9 | /**
10 | * Created by QiuJu
11 | * on 2014/9/17.
12 | */
13 | public final class Genius {
14 | private static Application application;
15 |
16 | public static Application getApplication() {
17 | return application;
18 | }
19 |
20 | public static void initialize(Application application) {
21 | Genius.application = application;
22 | }
23 |
24 | public static void dispose() {
25 | Command.dispose();
26 | Log.dispose();
27 | ToolKit.dispose();
28 | application = null;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/MaterialUI.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Typeface;
6 | import android.graphics.drawable.Drawable;
7 | import android.graphics.drawable.LayerDrawable;
8 | import android.graphics.drawable.PaintDrawable;
9 | import android.util.DisplayMetrics;
10 | import android.util.Log;
11 | import android.util.TypedValue;
12 |
13 | /**
14 | * Created by QiuJu
15 | * on 2014/9/3.
16 | */
17 | public class MaterialUI {
18 |
19 | public static final String androidStyleNameSpace = "http://schemas.android.com/apk/res/android";
20 |
21 | public static final int SAND = R.array.sand;
22 | public static final int ORANGE = R.array.orange;
23 | public static final int CANDY = R.array.candy;
24 | public static final int BLOSSOM = R.array.blossom;
25 | public static final int GRAPE = R.array.grape;
26 | public static final int DEEP = R.array.deep;
27 | public static final int SKY = R.array.sky;
28 | public static final int GRASS = R.array.grass;
29 | public static final int DARK = R.array.dark;
30 | public static final int SNOW = R.array.snow;
31 | public static final int SEA = R.array.sea;
32 | public static final int BLOOD = R.array.blood;
33 |
34 | /**
35 | * Converts the default values to dp to be compatible with different screen sizes
36 | *
37 | * @param context
38 | */
39 | public static void initDefaultValues(Context context) {
40 |
41 | Attributes.DEFAULT_BORDER_WIDTH_PX = (int) dipToPx(context, Attributes.DEFAULT_BORDER_WIDTH_DP);
42 | Attributes.DEFAULT_RADIUS_PX = (int) dipToPx(context, Attributes.DEFAULT_RADIUS_DP);
43 | Attributes.DEFAULT_SIZE_PX = (int) dipToPx(context, Attributes.DEFAULT_SIZE_DP);
44 | }
45 |
46 | /**
47 | * Creates and returns the font file from given attributes.
48 | *
49 | * @param context
50 | * @param attributes
51 | * @return
52 | */
53 | public static Typeface getFont(Context context, Attributes attributes) {
54 |
55 | String fontPath = "fonts/" + attributes.getFontFamily()
56 | + "_" + attributes.getFontWeight()
57 | + "." + attributes.getFontExtension();
58 |
59 | try {
60 | return Typeface.createFromAsset(context.getAssets(), fontPath);
61 | } catch (Exception e) {
62 | Log.e("FlatUI", "Font file at " + fontPath + " cannot be found or the file is " +
63 | "not a valid font file. Please be sure that library assets are included " +
64 | "to project. If not, copy assets/fonts folder of the library to your " +
65 | "projects assets folder.");
66 | return null;
67 | }
68 | }
69 |
70 | public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark) {
71 | return getActionBarDrawable(activity, theme, dark, 0);
72 | }
73 |
74 | /**
75 | * Returns a suitable drawable for ActionBar with theme colors.
76 | *
77 | * @param theme selected theme
78 | * @param dark boolean for choosing dark colors or primary colors
79 | * @param borderBottom bottom border width
80 | * @return drawable to be used in ActionBar
81 | */
82 | public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark, float borderBottom) {
83 | int[] colors = activity.getResources().getIntArray(theme);
84 |
85 | int color1 = colors[2];
86 | int color2 = colors[1];
87 |
88 | if (dark) {
89 | color1 = colors[1];
90 | color2 = colors[0];
91 | }
92 |
93 | borderBottom = dipToPx(activity, borderBottom);
94 |
95 | PaintDrawable front = new PaintDrawable(color1);
96 | PaintDrawable bottom = new PaintDrawable(color2);
97 | Drawable[] d = {bottom, front};
98 | LayerDrawable drawable = new LayerDrawable(d);
99 | drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom);
100 | return drawable;
101 | }
102 |
103 | /**
104 | * Sets the default theme of the application. The views which doesn't have any theme attribute
105 | * will have this defined default theme.
106 | *
107 | * IMPORTANT: This method should be called before setContentView method of the activity.
108 | *
109 | * @param theme
110 | */
111 | public static void setDefaultTheme(int theme) {
112 | Attributes.DEFAULT_THEME = theme;
113 | }
114 |
115 | private static float dipToPx(Context context, float dp) {
116 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
117 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/app/BlurKit.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.app;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by QiuJu
7 | * on 2014/11/25.
8 | *
9 | * This is blur image class
10 | */
11 | public class BlurKit {
12 |
13 | private static Bitmap buildBitmap(Bitmap bitmap, boolean canReuseInBitmap) {
14 | // If can reuse in bitmap return this or copy
15 | Bitmap rBitmap;
16 | if (canReuseInBitmap) {
17 | rBitmap = bitmap;
18 | } else {
19 | rBitmap = bitmap.copy(bitmap.getConfig(), true);
20 | }
21 | return (rBitmap);
22 | }
23 |
24 | /**
25 | * FastBlur By Jni Bit Array
26 | *
27 | * @param bitmap Image
28 | * @param radius Blur radius
29 | * @param canReuseInBitmap Can reuse InBitmap
30 | * @return Image
31 | */
32 | public static Bitmap fastBlurInJniArray(Bitmap bitmap, int radius, boolean canReuseInBitmap) {
33 | if (radius < 1) {
34 | return null;
35 | }
36 |
37 | Bitmap rBitmap = buildBitmap(bitmap, canReuseInBitmap);
38 |
39 | int w = rBitmap.getWidth();
40 | int h = rBitmap.getHeight();
41 |
42 | int[] pix = new int[w * h];
43 | rBitmap.getPixels(pix, 0, w, 0, 0, w, h);
44 |
45 | // By Jni Array Blur
46 | BlurNative.fastBlurArray(pix, w, h, radius);
47 |
48 | rBitmap.setPixels(pix, 0, w, 0, 0, w, h);
49 | return (rBitmap);
50 | }
51 |
52 | /**
53 | * FastBlur By Jni Bitmap
54 | *
55 | * @param bitmap Image
56 | * @param radius Blur radius
57 | * @param canReuseInBitmap Can reuse InBitmap
58 | * @return Image
59 | */
60 | public static Bitmap fastBlurInJniBitmap(Bitmap bitmap, int radius, boolean canReuseInBitmap) {
61 | if (radius < 1) {
62 | return null;
63 | }
64 |
65 | Bitmap runBitmap = buildBitmap(bitmap, canReuseInBitmap);
66 |
67 | //Jni BitMap
68 | BlurNative.fastBlurBitmap(runBitmap, radius);
69 |
70 | return (runBitmap);
71 | }
72 |
73 | /**
74 | * FastBlur By Java Bitmap
75 | *
76 | * @param bitmap Image
77 | * @param radius Blur radius
78 | * @param canReuseInBitmap Can reuse InBitmap
79 | * @return Image
80 | */
81 | public static Bitmap fastBlurInJava(Bitmap bitmap, int radius, boolean canReuseInBitmap) {
82 | // Stack Blur v1.0 from
83 | // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
84 | //
85 | // Java Author: Mario Klingemann
86 | // http://incubator.quasimondo.com
87 | // created Feburary 29, 2004
88 | // Android port : Yahel Bouaziz
89 | // http://www.kayenko.com
90 | // ported april 5th, 2012
91 |
92 | // This is a compromise between Gaussian Blur and Box blur
93 | // It creates much better looking blurs than Box Blur, but is
94 | // 7x faster than my Gaussian Blur implementation.
95 | //
96 | // I called it Stack Blur because this describes best how this
97 | // filter works internally: it creates a kind of moving stack
98 | // of colors whilst scanning through the image. Thereby it
99 | // just has to add one new block of color to the right side
100 | // of the stack and remove the leftmost color. The remaining
101 | // colors on the topmost layer of the stack are either added on
102 | // or reduced by one, depending on if they are on the right or
103 | // on the left side of the stack.
104 | //
105 | // If you are using this algorithm in your code please add
106 | // the following line:
107 | //
108 | // Stack Blur Algorithm by Mario Klingemann
109 |
110 | if (radius < 1) {
111 | return (null);
112 | }
113 |
114 | Bitmap rBitmap = buildBitmap(bitmap, canReuseInBitmap);
115 |
116 | int w = rBitmap.getWidth();
117 | int h = rBitmap.getHeight();
118 |
119 | int[] pix = new int[w * h];
120 | rBitmap.getPixels(pix, 0, w, 0, 0, w, h);
121 |
122 | int wm = w - 1;
123 | int hm = h - 1;
124 | int wh = w * h;
125 | int div = radius + radius + 1;
126 |
127 | int r[] = new int[wh];
128 | int g[] = new int[wh];
129 | int b[] = new int[wh];
130 | int rSum, gSum, bSum, x, y, i, p, yp, yi, yw;
131 | int vMin[] = new int[Math.max(w, h)];
132 |
133 | int divSum = (div + 1) >> 1;
134 | divSum *= divSum;
135 | int dv[] = new int[256 * divSum];
136 | for (i = 0; i < 256 * divSum; i++) {
137 | dv[i] = (i / divSum);
138 | }
139 |
140 | yw = yi = 0;
141 |
142 | int[][] stack = new int[div][3];
143 | int stackPointer;
144 | int stackStart;
145 | int[] sir;
146 | int rbs;
147 | int r1 = radius + 1;
148 | int routSum, goutSum, boutSum;
149 | int rinSum, ginSum, binSum;
150 |
151 | for (y = 0; y < h; y++) {
152 | rinSum = ginSum = binSum = routSum = goutSum = boutSum = rSum = gSum = bSum = 0;
153 | for (i = -radius; i <= radius; i++) {
154 | p = pix[yi + Math.min(wm, Math.max(i, 0))];
155 | sir = stack[i + radius];
156 | sir[0] = (p & 0xff0000) >> 16;
157 | sir[1] = (p & 0x00ff00) >> 8;
158 | sir[2] = (p & 0x0000ff);
159 | rbs = r1 - Math.abs(i);
160 | rSum += sir[0] * rbs;
161 | gSum += sir[1] * rbs;
162 | bSum += sir[2] * rbs;
163 | if (i > 0) {
164 | rinSum += sir[0];
165 | ginSum += sir[1];
166 | binSum += sir[2];
167 | } else {
168 | routSum += sir[0];
169 | goutSum += sir[1];
170 | boutSum += sir[2];
171 | }
172 | }
173 | stackPointer = radius;
174 |
175 | for (x = 0; x < w; x++) {
176 |
177 | r[yi] = dv[rSum];
178 | g[yi] = dv[gSum];
179 | b[yi] = dv[bSum];
180 |
181 | rSum -= routSum;
182 | gSum -= goutSum;
183 | bSum -= boutSum;
184 |
185 | stackStart = stackPointer - radius + div;
186 | sir = stack[stackStart % div];
187 |
188 | routSum -= sir[0];
189 | goutSum -= sir[1];
190 | boutSum -= sir[2];
191 |
192 | if (y == 0) {
193 | vMin[x] = Math.min(x + radius + 1, wm);
194 | }
195 | p = pix[yw + vMin[x]];
196 |
197 | sir[0] = (p & 0xff0000) >> 16;
198 | sir[1] = (p & 0x00ff00) >> 8;
199 | sir[2] = (p & 0x0000ff);
200 |
201 | rinSum += sir[0];
202 | ginSum += sir[1];
203 | binSum += sir[2];
204 |
205 | rSum += rinSum;
206 | gSum += ginSum;
207 | bSum += binSum;
208 |
209 | stackPointer = (stackPointer + 1) % div;
210 | sir = stack[(stackPointer) % div];
211 |
212 | routSum += sir[0];
213 | goutSum += sir[1];
214 | boutSum += sir[2];
215 |
216 | rinSum -= sir[0];
217 | ginSum -= sir[1];
218 | binSum -= sir[2];
219 |
220 | yi++;
221 | }
222 | yw += w;
223 | }
224 | for (x = 0; x < w; x++) {
225 | rinSum = ginSum = binSum = routSum = goutSum = boutSum = rSum = gSum = bSum = 0;
226 | yp = -radius * w;
227 | for (i = -radius; i <= radius; i++) {
228 | yi = Math.max(0, yp) + x;
229 |
230 | sir = stack[i + radius];
231 |
232 | sir[0] = r[yi];
233 | sir[1] = g[yi];
234 | sir[2] = b[yi];
235 |
236 | rbs = r1 - Math.abs(i);
237 |
238 | rSum += r[yi] * rbs;
239 | gSum += g[yi] * rbs;
240 | bSum += b[yi] * rbs;
241 |
242 | if (i > 0) {
243 | rinSum += sir[0];
244 | ginSum += sir[1];
245 | binSum += sir[2];
246 | } else {
247 | routSum += sir[0];
248 | goutSum += sir[1];
249 | boutSum += sir[2];
250 | }
251 |
252 | if (i < hm) {
253 | yp += w;
254 | }
255 | }
256 | yi = x;
257 | stackPointer = radius;
258 | for (y = 0; y < h; y++) {
259 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
260 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rSum] << 16) | (dv[gSum] << 8) | dv[bSum];
261 |
262 | rSum -= routSum;
263 | gSum -= goutSum;
264 | bSum -= boutSum;
265 |
266 | stackStart = stackPointer - radius + div;
267 | sir = stack[stackStart % div];
268 |
269 | routSum -= sir[0];
270 | goutSum -= sir[1];
271 | boutSum -= sir[2];
272 |
273 | if (x == 0) {
274 | vMin[y] = Math.min(y + r1, hm) * w;
275 | }
276 | p = x + vMin[y];
277 |
278 | sir[0] = r[p];
279 | sir[1] = g[p];
280 | sir[2] = b[p];
281 |
282 | rinSum += sir[0];
283 | ginSum += sir[1];
284 | binSum += sir[2];
285 |
286 | rSum += rinSum;
287 | gSum += ginSum;
288 | bSum += binSum;
289 |
290 | stackPointer = (stackPointer + 1) % div;
291 | sir = stack[stackPointer];
292 |
293 | routSum += sir[0];
294 | goutSum += sir[1];
295 | boutSum += sir[2];
296 |
297 | rinSum -= sir[0];
298 | ginSum -= sir[1];
299 | binSum -= sir[2];
300 |
301 | yi += w;
302 | }
303 | }
304 |
305 | rBitmap.setPixels(pix, 0, w, 0, 0, w, h);
306 |
307 | return (rBitmap);
308 | }
309 | }
310 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/app/BlurNative.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.app;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by QiuJu
7 | * on 2014/11/25.
8 | *
9 | * This is call native JNI class
10 | */
11 | class BlurNative {
12 |
13 | /**
14 | * Blur Image By Array
15 | *
16 | * @param img Img pixel array
17 | * @param w Img width
18 | * @param h Img height
19 | * @param r Blur radius
20 | */
21 | public static native void fastBlurArray(int[] img, int w, int h, int r);
22 |
23 | /**
24 | * Blur Image By Bitmap
25 | *
26 | * @param bitmap Img Bitmap
27 | * @param r Blur radius
28 | */
29 | public static native void fastBlurBitmap(Bitmap bitmap, int r);
30 |
31 | /**
32 | * Load genius jni file
33 | */
34 | static {
35 | System.loadLibrary("genius");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/app/HandlerPoster.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.app;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 | import android.os.Message;
6 | import android.os.SystemClock;
7 |
8 | import net.qiujuer.genius.util.GeniusException;
9 |
10 | import java.util.LinkedList;
11 | import java.util.Queue;
12 |
13 | /**
14 | * Created by QiuJu
15 | * on 2014/11/24.
16 | */
17 | final class HandlerPoster extends Handler {
18 | private final int ASYNC = 0x1;
19 | private final int SYNC = 0x2;
20 | private final Queue asyncPool;
21 | private final Queue syncPool;
22 | private final int maxMillisInsideHandleMessage;
23 | private boolean asyncActive;
24 | private boolean syncActive;
25 |
26 | HandlerPoster(Looper looper, int maxMillisInsideHandleMessage) {
27 | super(looper);
28 | this.maxMillisInsideHandleMessage = maxMillisInsideHandleMessage;
29 | asyncPool = new LinkedList<>();
30 | syncPool = new LinkedList<>();
31 | }
32 |
33 | void dispose() {
34 | this.removeCallbacksAndMessages(null);
35 | this.asyncPool.clear();
36 | this.syncPool.clear();
37 | }
38 |
39 | void async(Runnable runnable) {
40 | synchronized (asyncPool) {
41 | asyncPool.offer(runnable);
42 | if (!asyncActive) {
43 | asyncActive = true;
44 | if (!sendMessage(obtainMessage(ASYNC))) {
45 | throw new GeniusException("Could not send handler message");
46 | }
47 | }
48 | }
49 | }
50 |
51 | void sync(SyncPost post) {
52 | synchronized (syncPool) {
53 | syncPool.offer(post);
54 | if (!syncActive) {
55 | syncActive = true;
56 | if (!sendMessage(obtainMessage(SYNC))) {
57 | throw new GeniusException("Could not send handler message");
58 | }
59 | }
60 | }
61 | }
62 |
63 | @Override
64 | public void handleMessage(Message msg) {
65 | if (msg.what == ASYNC) {
66 | boolean rescheduled = false;
67 | try {
68 | long started = SystemClock.uptimeMillis();
69 | while (true) {
70 | Runnable runnable = asyncPool.poll();
71 | if (runnable == null) {
72 | synchronized (asyncPool) {
73 | // Check again, this time in synchronized
74 | runnable = asyncPool.poll();
75 | if (runnable == null) {
76 | asyncActive = false;
77 | return;
78 | }
79 | }
80 | }
81 | runnable.run();
82 | long timeInMethod = SystemClock.uptimeMillis() - started;
83 | if (timeInMethod >= maxMillisInsideHandleMessage) {
84 | if (!sendMessage(obtainMessage(ASYNC))) {
85 | throw new GeniusException("Could not send handler message");
86 | }
87 | rescheduled = true;
88 | return;
89 | }
90 | }
91 | } finally {
92 | asyncActive = rescheduled;
93 | }
94 | } else if (msg.what == SYNC) {
95 | boolean rescheduled = false;
96 | try {
97 | long started = SystemClock.uptimeMillis();
98 | while (true) {
99 | SyncPost post = syncPool.poll();
100 | if (post == null) {
101 | synchronized (syncPool) {
102 | // Check again, this time in synchronized
103 | post = syncPool.poll();
104 | if (post == null) {
105 | syncActive = false;
106 | return;
107 | }
108 | }
109 | }
110 | post.run();
111 | long timeInMethod = SystemClock.uptimeMillis() - started;
112 | if (timeInMethod >= maxMillisInsideHandleMessage) {
113 | if (!sendMessage(obtainMessage(SYNC))) {
114 | throw new GeniusException("Could not send handler message");
115 | }
116 | rescheduled = true;
117 | return;
118 | }
119 | }
120 | } finally {
121 | syncActive = rescheduled;
122 | }
123 | } else super.handleMessage(msg);
124 | }
125 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/app/SyncPost.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.app;
2 |
3 | /**
4 | * Created by QiuJu
5 | * on 2014/11/24.
6 | */
7 | final class SyncPost {
8 | boolean end = false;
9 | Runnable runnable;
10 |
11 | SyncPost(Runnable runnable) {
12 | this.runnable = runnable;
13 | }
14 |
15 | public void run() {
16 | synchronized (this) {
17 | runnable.run();
18 | end = true;
19 | try {
20 | this.notifyAll();
21 | } catch (Exception e) {
22 | e.printStackTrace();
23 | }
24 | }
25 | }
26 |
27 | public void waitRun() {
28 | if (!end) {
29 | synchronized (this) {
30 | if (!end) {
31 | try {
32 | this.wait();
33 | } catch (InterruptedException e) {
34 | e.printStackTrace();
35 | }
36 | }
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/app/ToolKit.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.app;
2 |
3 | import android.os.Looper;
4 |
5 | /**
6 | * Created by QiuJu
7 | * on 2014/11/24.
8 | */
9 | public class ToolKit {
10 | private static HandlerPoster mainPoster = null;
11 |
12 | private static HandlerPoster getMainPoster() {
13 | if (mainPoster == null) {
14 | synchronized (ToolKit.class) {
15 | if (mainPoster == null) {
16 | mainPoster = new HandlerPoster(Looper.getMainLooper(), 20);
17 | }
18 | }
19 | }
20 | return mainPoster;
21 | }
22 |
23 | /**
24 | * Asynchronously
25 | * The child thread asynchronous run relative to the main thread,
26 | * not blocking the child thread
27 | *
28 | * @param runnable Runnable Interface
29 | */
30 | public static void runOnMainThreadAsync(Runnable runnable) {
31 | if (Looper.myLooper() == Looper.getMainLooper()) {
32 | runnable.run();
33 | return;
34 | }
35 | getMainPoster().async(runnable);
36 | }
37 |
38 | /**
39 | * Synchronously
40 | * The child thread relative thread synchronization operation,
41 | * blocking the child thread,
42 | * thread for the main thread to complete
43 | *
44 | * @param runnable Runnable Interface
45 | */
46 | public static void runOnMainThreadSync(Runnable runnable) {
47 | if (Looper.myLooper() == Looper.getMainLooper()) {
48 | runnable.run();
49 | return;
50 | }
51 | SyncPost poster = new SyncPost(runnable);
52 | getMainPoster().sync(poster);
53 | poster.waitRun();
54 | }
55 |
56 | public static void dispose() {
57 | if (mainPoster != null) {
58 | mainPoster.dispose();
59 | mainPoster = null;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/command/Command.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.command;
2 |
3 | import android.content.ComponentName;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.ServiceConnection;
7 | import android.os.IBinder;
8 | import android.os.RemoteException;
9 |
10 | import net.qiujuer.genius.Genius;
11 | import net.qiujuer.genius.util.Tools;
12 |
13 | import java.util.UUID;
14 | import java.util.concurrent.locks.Condition;
15 | import java.util.concurrent.locks.Lock;
16 | import java.util.concurrent.locks.ReentrantLock;
17 |
18 | /**
19 | * Created by QiuJu
20 | * on 2014/8/13.
21 | */
22 | public final class Command {
23 | private static final String TAG = Command.class.getSimpleName();
24 | //ICommandInterface
25 | private static ICommandInterface iService = null;
26 | //Service link class, used to instantiate the service interface
27 | private static ServiceConnection conn = new ServiceConnection() {
28 | @Override
29 | public void onServiceConnected(ComponentName name, IBinder service) {
30 | iLock.lock();
31 | iService = ICommandInterface.Stub.asInterface(service);
32 | if (iService != null) {
33 | try {
34 | iCondition.signalAll();
35 | } catch (Exception e) {
36 | e.printStackTrace();
37 | }
38 | } else {
39 | bindService();
40 | }
41 | iLock.unlock();
42 | }
43 |
44 | @Override
45 | public void onServiceDisconnected(ComponentName name) {
46 | iService = null;
47 | }
48 | };
49 | //Lock
50 | private static Lock iLock = new ReentrantLock();
51 | private static Condition iCondition = iLock.newCondition();
52 | //Mark If Bind Service
53 | private static boolean isBindService = false;
54 | //Context
55 | private static Context mContext;
56 |
57 |
58 | /**
59 | * start bind Service
60 | */
61 | private synchronized static void bindService() {
62 | dispose();
63 | mContext = Genius.getApplication();
64 | if (mContext == null) {
65 | throw new NullPointerException("Application is not null.Please Genius.initialize(Application)");
66 | } else {
67 | mContext.bindService(new Intent(mContext, CommandService.class), conn, Context.BIND_AUTO_CREATE);
68 | isBindService = true;
69 | }
70 | }
71 |
72 | /**
73 | * *********************************************************************************************
74 | * Static public
75 | * *********************************************************************************************
76 | */
77 |
78 | /**
79 | * Command the test
80 | *
81 | * @param command Command
82 | * @return Results
83 | */
84 | public static String command(Command command) {
85 | //check Service
86 | if (!isBindService)
87 | bindService();
88 | if (iService == null) {
89 | iLock.lock();
90 | try {
91 | iCondition.await();
92 | } catch (InterruptedException e) {
93 | e.printStackTrace();
94 | }
95 | iLock.unlock();
96 | }
97 | //Get result
98 | int count = 10;
99 | while (count > 0) {
100 | if (command.isCancel) {
101 | if (command.listener != null)
102 | command.listener.onCancel();
103 | break;
104 | }
105 | try {
106 | command.result = iService.command(command.id, command.parameter);
107 | if (command.listener != null)
108 | command.listener.onCompleted(command.result);
109 | break;
110 | } catch (Exception e) {
111 | count--;
112 | Tools.sleepIgnoreInterrupt(3000);
113 | }
114 | }
115 | //Check is Error
116 | if (count <= 0) {
117 | bindService();
118 | if (command.listener != null)
119 | command.listener.onError();
120 | }
121 | command.listener = null;
122 | //Check is end
123 | try {
124 | if (iService.getTaskCount() <= 0)
125 | dispose();
126 | } catch (RemoteException e) {
127 | e.printStackTrace();
128 | }
129 | //Return
130 | return command.result;
131 | }
132 |
133 | /**
134 | * Command the test
135 | *
136 | * @param command Command
137 | */
138 | public static void command(final Command command, CommandListener listener) {
139 | command.listener = listener;
140 | Thread thread = new Thread() {
141 | @Override
142 | public void run() {
143 | command(command);
144 | }
145 | };
146 | thread.setDaemon(true);
147 | thread.start();
148 | }
149 |
150 | /**
151 | * cancel Test
152 | */
153 | public static void cancel(Command command) {
154 | command.isCancel = true;
155 | if (iService != null)
156 | try {
157 | iService.cancel(command.id);
158 | } catch (RemoteException e) {
159 | e.printStackTrace();
160 | }
161 | }
162 |
163 | /**
164 | * dispose unbindService stopService
165 | */
166 | public static void dispose() {
167 | if (isBindService) {
168 | if (iService != null) {
169 | try {
170 | iService.dispose();
171 | } catch (RemoteException e) {
172 | e.printStackTrace();
173 | }
174 | iService = null;
175 | }
176 | mContext.unbindService(conn);
177 | mContext = null;
178 | isBindService = false;
179 | }
180 | }
181 |
182 | /**
183 | * *********************************************************************************************
184 | * Class
185 | * *********************************************************************************************
186 | */
187 | private String id;
188 | private String parameter = null;
189 | private boolean isCancel = false;
190 | private CommandListener listener = null;
191 | private String result = null;
192 |
193 | /**
194 | * Get a Command
195 | *
196 | * @param params params eg: "/system/bin/ping", "-c", "4", "-s", "100","www.qiujuer.net"
197 | */
198 | public Command(String... params) {
199 | //check params
200 | if (params == null)
201 | throw new NullPointerException("params is not null.");
202 | //run
203 | StringBuilder sb = new StringBuilder();
204 | for (String str : params) {
205 | sb.append(str);
206 | sb.append(" ");
207 | }
208 | this.parameter = sb.toString();
209 | this.id = UUID.randomUUID().toString();
210 | }
211 |
212 | /**
213 | * CommandListener
214 | */
215 | public interface CommandListener {
216 | public void onCompleted(String str);
217 |
218 | public void onCancel();
219 |
220 | public void onError();
221 | }
222 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/command/CommandExecutor.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.command;
2 |
3 | import net.qiujuer.genius.util.Tools;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 | import java.io.OutputStream;
10 | import java.util.concurrent.locks.Lock;
11 | import java.util.concurrent.locks.ReentrantLock;
12 |
13 | /**
14 | * Created by QiuJu
15 | * on 2014/9/17.
16 | */
17 | class CommandExecutor {
18 | private static final String TAG = CommandExecutor.class.getSimpleName();
19 |
20 | private static final String BREAK_LINE;
21 | private static final byte[] BUFFER;
22 | private static final int BUFFER_LENGTH;
23 |
24 | private static final Lock LOCK = new ReentrantLock();
25 | //Time Out
26 | private static final long TIMEOUT = 90000;
27 | //ProcessBuilder
28 | private static ProcessBuilder PRC;
29 |
30 | final private Process process;
31 | final private InputStream in;
32 | final private InputStream err;
33 | final private OutputStream out;
34 | final private StringBuilder sbReader;
35 |
36 | private BufferedReader bInReader = null;
37 | private InputStreamReader isInReader = null;
38 | private boolean isDone;
39 | private long startTime;
40 |
41 | /**
42 | * init
43 | */
44 | static {
45 | BREAK_LINE = "\n";
46 | BUFFER_LENGTH = 128;
47 | BUFFER = new byte[BUFFER_LENGTH];
48 |
49 | LOCK.lock();
50 | PRC = new ProcessBuilder();
51 | LOCK.unlock();
52 | }
53 |
54 | /**
55 | * *********************************************************************************************
56 | * private methods
57 | * *********************************************************************************************
58 | */
59 | /**
60 | * Get CommandExecutor
61 | *
62 | * @param process Process
63 | */
64 | private CommandExecutor(Process process) {
65 | //init
66 | this.startTime = System.currentTimeMillis();
67 | this.process = process;
68 | //get
69 | out = process.getOutputStream();
70 | in = process.getInputStream();
71 | err = process.getErrorStream();
72 |
73 | //in
74 | if (in != null) {
75 | isInReader = new InputStreamReader(in);
76 | bInReader = new BufferedReader(isInReader, BUFFER_LENGTH);
77 | }
78 |
79 | sbReader = new StringBuilder();
80 |
81 | //start read thread
82 | Thread processThread = new Thread(TAG) {
83 | @Override
84 | public void run() {
85 | startRead();
86 | }
87 | };
88 | processThread.setDaemon(true);
89 | processThread.start();
90 | }
91 |
92 | /**
93 | * read
94 | */
95 | private void read() {
96 | String str;
97 | //read In
98 | try {
99 | while ((str = bInReader.readLine()) != null) {
100 | sbReader.append(str);
101 | sbReader.append(BREAK_LINE);
102 | }
103 | } catch (Exception e) {
104 | e.printStackTrace();
105 | }
106 | }
107 |
108 | /**
109 | * run thread
110 | */
111 | private void startRead() {
112 | //while to end
113 | while (true) {
114 | try {
115 | process.exitValue();
116 | //read last
117 | read();
118 | break;
119 | } catch (IllegalThreadStateException e) {
120 | read();
121 | }
122 | Tools.sleepIgnoreInterrupt(50);
123 | }
124 |
125 | //read end
126 | int len;
127 | if (in != null) {
128 | try {
129 | while (true) {
130 | len = in.read(BUFFER);
131 | if (len <= 0)
132 | break;
133 | }
134 | } catch (IOException e) {
135 | e.printStackTrace();
136 | }
137 | }
138 |
139 | //close
140 | close();
141 | //destroy
142 | destroy();
143 | //done
144 | isDone = true;
145 |
146 | }
147 |
148 | /**
149 | * close
150 | */
151 | private void close() {
152 | //close out
153 | if (out != null) {
154 | try {
155 | out.close();
156 | } catch (IOException e) {
157 | e.printStackTrace();
158 | }
159 | }
160 | //err
161 | if (err != null) {
162 | try {
163 | err.close();
164 | } catch (IOException e) {
165 | e.printStackTrace();
166 | }
167 | }
168 | //in
169 | if (in != null) {
170 | try {
171 | in.close();
172 | } catch (IOException e) {
173 | e.printStackTrace();
174 | }
175 | }
176 | if (isInReader != null) {
177 | try {
178 | isInReader.close();
179 | } catch (IOException e) {
180 | e.printStackTrace();
181 | }
182 | }
183 | if (bInReader != null) {
184 | try {
185 | bInReader.close();
186 | } catch (IOException e) {
187 | e.printStackTrace();
188 | }
189 | }
190 | }
191 |
192 |
193 | /**
194 | * *********************************************************************************************
195 | * protected methods
196 | * *********************************************************************************************
197 | */
198 | /**
199 | * Run
200 | *
201 | * @param param param eg: "/system/bin/ping -c 4 -s 100 www.qiujuer.net"
202 | */
203 | protected static CommandExecutor create(String param) {
204 | String[] params = param.split(" ");
205 | CommandExecutor processModel = null;
206 | try {
207 | LOCK.lock();
208 | Process process = PRC.command(params)
209 | .redirectErrorStream(true)
210 | .start();
211 | processModel = new CommandExecutor(process);
212 | } catch (IOException e) {
213 | e.printStackTrace();
214 | } finally {
215 | //sleep 100
216 | Tools.sleepIgnoreInterrupt(100);
217 | LOCK.unlock();
218 | }
219 | return processModel;
220 | }
221 |
222 | /**
223 | * Get is Time Out
224 | *
225 | * @return Time Out
226 | */
227 | protected boolean isTimeOut() {
228 | return ((System.currentTimeMillis() - startTime) >= TIMEOUT);
229 | }
230 |
231 | /**
232 | * Get Result
233 | *
234 | * @return Result
235 | */
236 | protected String getResult() {
237 | //until startRead en
238 | while (!isDone) {
239 | Tools.sleepIgnoreInterrupt(200);
240 | }
241 |
242 | //return
243 | if (sbReader.length() == 0)
244 | return null;
245 | else
246 | return sbReader.toString();
247 | }
248 |
249 | /**
250 | * destroy
251 | */
252 | protected void destroy() {
253 | String str = process.toString();
254 | try {
255 | int i = str.indexOf("=") + 1;
256 | int j = str.indexOf("]");
257 | str = str.substring(i, j);
258 | int pid = Integer.parseInt(str);
259 | try {
260 | android.os.Process.killProcess(pid);
261 | } catch (Exception e) {
262 | try {
263 | process.destroy();
264 | } catch (Exception ex) {
265 | ex.printStackTrace();
266 | }
267 | }
268 | } catch (Exception e) {
269 | e.printStackTrace();
270 | }
271 | }
272 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/command/CommandService.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.command;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 | import android.os.RemoteException;
7 |
8 | import java.util.Collection;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 | import java.util.concurrent.locks.Lock;
12 | import java.util.concurrent.locks.ReentrantLock;
13 |
14 | /**
15 | * Created by QiuJu
16 | * on 2014/9/17.
17 | */
18 | public class CommandService extends Service {
19 | private CommandServiceImpl mImpl;
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 | mImpl = new CommandServiceImpl();
25 | }
26 |
27 | @Override
28 | public IBinder onBind(Intent intent) {
29 | if (mImpl == null)
30 | mImpl = new CommandServiceImpl();
31 | return mImpl;
32 | }
33 |
34 |
35 | @Override
36 | public void onDestroy() {
37 | if (mImpl != null) {
38 | mImpl.destroy();
39 | mImpl = null;
40 | }
41 | super.onDestroy();
42 | }
43 |
44 |
45 | private class CommandServiceImpl extends ICommandInterface.Stub {
46 | private Map commandExecutorMap = new HashMap();
47 | private Lock lock = new ReentrantLock();
48 | private Thread thread;
49 |
50 | public CommandServiceImpl() {
51 | //init
52 | thread = new Thread(CommandServiceImpl.class.getName()) {
53 | @Override
54 | public void run() {
55 | while (thread == this && !this.isInterrupted()) {
56 | if (commandExecutorMap != null && commandExecutorMap.size() > 0) {
57 | lock.lock();
58 | Collection commandExecutors = commandExecutorMap.values();
59 | for (CommandExecutor executor : commandExecutors) {
60 | //kill Service Process
61 | if (executor.isTimeOut())
62 | android.os.Process.killProcess(android.os.Process.myPid());
63 | if (thread != this && this.isInterrupted())
64 | break;
65 | }
66 | lock.unlock();
67 | }
68 | try {
69 | Thread.sleep(10000);
70 | } catch (InterruptedException e) {
71 | e.printStackTrace();
72 | }
73 | }
74 | }
75 | };
76 | thread.setDaemon(true);
77 | thread.start();
78 | }
79 |
80 | /**
81 | * destroy
82 | */
83 | protected void destroy() {
84 | if (thread != null) {
85 | thread.interrupt();
86 | thread = null;
87 | }
88 | lock.lock();
89 | commandExecutorMap.clear();
90 | commandExecutorMap = null;
91 | lock.lock();
92 | }
93 |
94 |
95 | /**
96 | * Run Command
97 | *
98 | * @param params params
99 | * @return result
100 | * @throws RemoteException
101 | */
102 | @Override
103 | public String command(String id, String params) throws RemoteException {
104 | CommandExecutor executor = CommandExecutor.create(params);
105 | lock.lock();
106 | commandExecutorMap.put(id, executor);
107 | lock.unlock();
108 | String result = executor.getResult();
109 | lock.lock();
110 | commandExecutorMap.remove(id);
111 | lock.unlock();
112 | return result;
113 | }
114 |
115 | /**
116 | * cancel command
117 | *
118 | * @param id command.id
119 | * @throws RemoteException
120 | */
121 | @Override
122 | public void cancel(String id) throws RemoteException {
123 | CommandExecutor executor = commandExecutorMap.get(id);
124 | if (executor != null) {
125 | lock.lock();
126 | commandExecutorMap.remove(id);
127 | lock.unlock();
128 | executor.destroy();
129 | }
130 | }
131 |
132 | /**
133 | * Dispose Service
134 | */
135 | @Override
136 | public void dispose() {
137 | stopSelf();
138 | }
139 |
140 | /**
141 | * Get Task Count
142 | *
143 | * @return Map Count
144 | * @throws RemoteException
145 | */
146 | @Override
147 | public int getTaskCount() throws RemoteException {
148 | if (commandExecutorMap == null)
149 | return 0;
150 | return commandExecutorMap.size();
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/DnsResolve.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import java.io.IOException;
4 | import java.net.DatagramPacket;
5 | import java.net.DatagramSocket;
6 | import java.net.InetAddress;
7 | import java.net.SocketException;
8 | import java.net.UnknownHostException;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by QiuJu
14 | * on 2014/9/20.
15 | */
16 | public class DnsResolve extends NetModel {
17 | private static final byte[] ID = new byte[]{(byte) 2, (byte) 6};
18 | private static final String POINT = ".";
19 | private String host;
20 | private InetAddress server;
21 | private List addresses;
22 | private long delay;
23 |
24 | /**
25 | * Domain name resolution test
26 | *
27 | * @param host Domain name address
28 | */
29 | public DnsResolve(String host) {
30 | this(host, null);
31 | }
32 |
33 | /**
34 | * Domain name resolution test
35 | *
36 | * @param host Domain name address
37 | * @param server Specify the domain name server
38 | */
39 | public DnsResolve(String host, InetAddress server) {
40 | this.host = host;
41 | this.server = server;
42 | }
43 |
44 | private ArrayList resolve(String domain, InetAddress dnsServer) {
45 | //pointer
46 | int pos;
47 | /**
48 | * init
49 | */
50 | byte[] sendBuffer = new byte[100];
51 | pos = 12;
52 | // message head
53 | sendBuffer[0] = ID[0];
54 | sendBuffer[1] = ID[1];
55 | sendBuffer[2] = 0x01;
56 | sendBuffer[3] = 0x00;
57 | sendBuffer[4] = 0x00;
58 | sendBuffer[5] = 0x01;
59 | sendBuffer[6] = 0x00;
60 | sendBuffer[7] = 0x00;
61 | sendBuffer[8] = 0x00;
62 | sendBuffer[9] = 0x00;
63 | sendBuffer[10] = 0x00;
64 | sendBuffer[11] = 0x00;
65 | // add domain
66 | String[] part = domain.split("\\.");
67 | for (String s : part) {
68 | if (s == null || s.length() <= 0)
69 | continue;
70 | int sLength = s.length();
71 | sendBuffer[pos++] = (byte) sLength;
72 | int i = 0;
73 | char[] val = s.toCharArray();
74 | while (i < sLength) {
75 | sendBuffer[pos++] = (byte) val[i++];
76 | }
77 | }
78 | // 0 end
79 | sendBuffer[pos++] = 0x00;
80 | sendBuffer[pos++] = 0x00;
81 | // 1 A record query
82 | sendBuffer[pos++] = 0x01;
83 | sendBuffer[pos++] = 0x00;
84 | // Internet record query
85 | sendBuffer[pos++] = 0x01;
86 |
87 | /**
88 | * UDP Send
89 | */
90 | DatagramSocket ds = null;
91 | byte[] receiveBuffer = null;
92 | try {
93 | ds = new DatagramSocket();
94 | ds.setSoTimeout(8000);
95 | DatagramPacket dp = new DatagramPacket(sendBuffer, pos, dnsServer, 53);
96 | ds.send(dp);
97 | dp = new DatagramPacket(new byte[1024], 1024);
98 | ds.receive(dp);
99 | int len = dp.getLength();
100 | receiveBuffer = new byte[len];
101 | for (int i = 0; i < len; i++) {
102 | receiveBuffer[i] = dp.getData()[i];
103 | }
104 | } catch (UnknownHostException e) {
105 | error = UNKNOWN_HOST_ERROR;
106 | } catch (SocketException e) {
107 | error = NETWORK_SOCKET_ERROR;
108 | e.printStackTrace();
109 | } catch (IOException e) {
110 | error = NETWORK_IO_ERROR;
111 | e.printStackTrace();
112 | } finally {
113 | if (ds != null)
114 | ds.close();
115 | }
116 |
117 | /**
118 | * resolve data
119 | */
120 | if (error != SUCCEED || receiveBuffer == null)
121 | return null;
122 |
123 | int queryCount, answerCount;
124 | if (receiveBuffer[0] != ID[0] || receiveBuffer[1] != ID[1]
125 | || (receiveBuffer[2] & 0x80) != 0x80)
126 | return null;
127 | queryCount = (receiveBuffer[4] << 8) | receiveBuffer[5];
128 | if (queryCount == 0)
129 | return null;
130 | answerCount = (receiveBuffer[6] << 8) | receiveBuffer[7];
131 | if (answerCount == 0)
132 | return null;
133 | // pointer restore
134 | pos = 12;
135 | // Skip the query part head
136 | for (int i = 0; i < queryCount; i++) {
137 | while (receiveBuffer[pos] != 0x00) {
138 | pos += receiveBuffer[pos] + 1;
139 | }
140 | pos += 5;
141 | }
142 | // get ip form data
143 | ArrayList iPs = new ArrayList();
144 | for (int i = 0; i < answerCount; i++) {
145 | if (receiveBuffer[pos] == (byte) 0xC0) {
146 | pos += 2;
147 | } else {
148 | while (receiveBuffer[pos] != (byte) 0x00) {
149 | pos += receiveBuffer[pos] + 1;
150 | }
151 | pos++;
152 | }
153 | byte queryType = (byte) (receiveBuffer[pos] << 8 | receiveBuffer[pos + 1]);
154 | pos += 8;
155 | int dataLength = (receiveBuffer[pos] << 8 | receiveBuffer[pos + 1]);
156 | pos += 2;
157 | // add ip
158 | if (queryType == (byte) 0x01) {
159 | int address[] = new int[4];
160 | for (int n = 0; n < 4; n++) {
161 | address[n] = receiveBuffer[pos + n];
162 | if (address[n] < 0)
163 | address[n] += 256;
164 | }
165 | iPs.add(address[0] + POINT + address[1] + POINT + address[2] + POINT + address[3]);
166 | }
167 | pos += dataLength;
168 | }
169 | return iPs;
170 | }
171 |
172 | @Override
173 | public void start() {
174 | long sTime = System.currentTimeMillis();
175 | if (server == null) {
176 | try {
177 | InetAddress[] adds = InetAddress.getAllByName(host);
178 | addresses = new ArrayList(adds.length);
179 | for (InetAddress add : adds)
180 | addresses.add(add.getHostAddress());
181 | } catch (UnknownHostException e) {
182 | error = UNKNOWN_HOST_ERROR;
183 | } catch (Exception e) {
184 | error = UNKNOWN_ERROR;
185 | }
186 | } else {
187 | try {
188 | addresses = resolve(host, server);
189 | } catch (Exception e) {
190 | if (error == SUCCEED)
191 | error = UNKNOWN_ERROR;
192 | e.printStackTrace();
193 | }
194 | }
195 | delay = System.currentTimeMillis() - sTime;
196 | }
197 |
198 | @Override
199 | public void cancel() {
200 |
201 | }
202 |
203 | public List getAddresses() {
204 | return addresses;
205 | }
206 |
207 | public long getDelay() {
208 | return delay;
209 | }
210 |
211 | @Override
212 | public String toString() {
213 | return "Delay:" + delay +
214 | " IPs:" + (addresses == null ? "[]" : addresses.toString());
215 | }
216 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/NetModel.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | * Created by QiuJu
8 | * on 2014/9/20.
9 | */
10 | public abstract class NetModel {
11 | public static final int SUCCEED = 0;
12 | public static final int UNKNOWN_ERROR = 1;
13 | public static final int TCP_LINK_ERROR = 2;
14 | public static final int UNKNOWN_HOST_ERROR = 3;
15 | public static final int NETWORK_FAULT_ERROR = 4;
16 | public static final int NETWORK_SOCKET_ERROR = 5;
17 | public static final int NETWORK_IO_ERROR = 6;
18 | public static final int MALFORMED_URL_ERROR = 7;
19 | public static final int HTTP_CODE_ERROR = 7;
20 | public static final int SERVICE_NOT_AVAILABLE = 8;
21 | public static final int DOWNLOAD_ERROR = 9;
22 | public static final int ICMP_ECHO_FAIL_ERROR = 10;
23 | public static final int HOST_UNREACHABLE_ERROR = 11;
24 | public static final int DROP_DATA_ERROR = 12;
25 |
26 |
27 | protected static final String PING = "ping";
28 | protected static final String PING_FROM = "from";
29 | protected static final String PING_PAREN_THESE_OPEN = "(";
30 | protected static final String PING_PAREN_THESE_CLOSE = ")";
31 | protected static final String PING_EXCEED = "exceed";
32 | protected static final String PING_STATISTICS = "statistics";
33 | protected static final String PING_TRANSMIT = "packets transmitted";
34 | protected static final String PING_RECEIVED = "received";
35 | protected static final String PING_ERRORS = "errors";
36 | protected static final String PING_LOSS = "packet loss";
37 | protected static final String PING_UNREACHABLE = "100%";
38 | protected static final String PING_RTT = "rtt";
39 | protected static final String PING_BREAK_LINE = "\n";
40 | protected static final String PING_RATE = "%";
41 | protected static final String PING_COMMA = ",";
42 | protected static final String PING_EQUAL = "=";
43 | protected static final String PING_SLASH = "/";
44 |
45 | protected int error = SUCCEED;
46 |
47 | public abstract void start();
48 |
49 | public abstract void cancel();
50 |
51 | public int getError() {
52 | return error;
53 | }
54 |
55 | protected static byte[] convertIpToByte(String ip) {
56 | String str[] = ip.split("\\.");
57 | byte[] bIp = new byte[str.length];
58 | try {
59 | for (int i = 0, len = str.length; i < len; i++) {
60 | bIp[i] = (byte) (Integer.parseInt(str[i], 10));
61 | }
62 | } catch (NumberFormatException e) {
63 | e.printStackTrace();
64 | }
65 | return bIp;
66 | }
67 |
68 | @SuppressWarnings("StatementWithEmptyBody")
69 | protected static void closeInputStream(InputStream in) {
70 | if (in != null) {
71 | try {
72 | in.close();
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/Ping.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import net.qiujuer.genius.command.Command;
4 |
5 | /**
6 | * Created by QiuJu
7 | * on 2014/9/21.
8 | */
9 | public class Ping extends NetModel {
10 | private boolean analysisIp;
11 | private int count, size;
12 | private String target;
13 |
14 | private String ip = null;
15 | private float lossRate = 1f;
16 | private float delay = 0;
17 | private float totalTime = 0;
18 | private transient Command command;
19 |
20 |
21 | /**
22 | * To specify the IP or domain name to Ping test and return the IP, packet loss,
23 | * delay parameter to specify the IP or domain name such as Ping test and return the IP,
24 | * packet loss, delay and other parameters
25 | *
26 | * @param aim The target
27 | */
28 | public Ping(String aim) {
29 | this(4, 32, aim, true);
30 | }
31 |
32 | /**
33 | * To specify the IP or domain name to Ping test and return the IP, packet loss,
34 | * delay parameter to specify the IP or domain name such as Ping test and return the IP,
35 | * packet loss, delay and other parameters
36 | *
37 | * @param count Packets
38 | * @param size Packet size
39 | * @param target The target
40 | */
41 | public Ping(int count, int size, String target) {
42 | this(count, size, target, true);
43 | }
44 |
45 | /**
46 | * To specify the IP or domain name to Ping test and return the IP, packet loss,
47 | * delay parameter to specify the IP or domain name such as Ping test and return the IP,
48 | * packet loss, delay and other parameters
49 | *
50 | * @param count Packets
51 | * @param size Packet size
52 | * @param target The target
53 | * @param analysisIp Whether parsing IP
54 | */
55 | public Ping(int count, int size, String target, boolean analysisIp) {
56 | this.analysisIp = analysisIp;
57 | this.count = count;
58 | this.size = size;
59 | this.target = target;
60 | }
61 |
62 | /**
63 | * *********************************************************************************************
64 | * To parse and load
65 | * *********************************************************************************************
66 | */
67 | private String launchPing() {
68 | long startTime = System.currentTimeMillis();
69 | command = new Command("/system/bin/ping",
70 | "-c", String.valueOf(count),
71 | "-s", String.valueOf(size),
72 | target);
73 | try {
74 | String res = Command.command(command);
75 | command = null;
76 | totalTime = (System.currentTimeMillis() - startTime);
77 | return res;
78 | } catch (Exception e) {
79 | return null;
80 | }
81 | }
82 |
83 | private String parseIpFromPing(String ping) {
84 | String ip = null;
85 | try {
86 | if (ping.contains(NetModel.PING)) {
87 | int indexOpen = ping.indexOf(NetModel.PING_PAREN_THESE_OPEN);
88 | int indexClose = ping.indexOf(NetModel.PING_PAREN_THESE_CLOSE);
89 | ip = ping.substring(indexOpen + 1, indexClose);
90 | }
91 | } catch (Exception e) {
92 | e.printStackTrace();
93 | }
94 | return ip;
95 | }
96 |
97 | private float parseLossFromPing(String ping) {
98 | float transmit = 0f, error = 0f, receive = 0f, lossRate = 0f;
99 | try {
100 | if (ping.contains(NetModel.PING_STATISTICS)) {
101 | String lossStr = ping.substring(ping.indexOf(NetModel.PING_BREAK_LINE, ping.indexOf(NetModel.PING_STATISTICS)) + 1);
102 | lossStr = lossStr.substring(0, lossStr.indexOf(NetModel.PING_BREAK_LINE));
103 | String strArray[] = lossStr.split(NetModel.PING_COMMA);
104 | for (String str : strArray) {
105 | if (str.contains(NetModel.PING_TRANSMIT))
106 | transmit = Float.parseFloat(str.substring(0, str.indexOf(NetModel.PING_TRANSMIT)));
107 | else if (str.contains(NetModel.PING_RECEIVED))
108 | receive = Float.parseFloat(str.substring(0, str.indexOf(NetModel.PING_RECEIVED)));
109 | else if (str.contains(NetModel.PING_ERRORS))
110 | error = Float.parseFloat(str.substring(0, str.indexOf(NetModel.PING_ERRORS)));
111 | else if (str.contains(NetModel.PING_LOSS))
112 | lossRate = Float.parseFloat(str.substring(0, str.indexOf(NetModel.PING_RATE)));
113 | }
114 | }
115 | if (transmit != 0)
116 | return error / transmit;
117 | else if (lossRate == 0)
118 | return error / (error + receive);
119 | } catch (Exception e) {
120 | e.printStackTrace();
121 | }
122 | return lossRate;
123 | }
124 |
125 | private float parseDelayFromPing(String ping) {
126 | float delay = 0;
127 | try {
128 | if (ping.contains(NetModel.PING_RTT)) {
129 | String lossStr = ping.substring(ping.indexOf(NetModel.PING_RTT));
130 | lossStr = lossStr.substring(lossStr.indexOf(NetModel.PING_EQUAL) + 2);
131 | String strArray[] = lossStr.split(NetModel.PING_SLASH);
132 | delay = Float.parseFloat(strArray[1]);
133 | }
134 | } catch (Exception e) {
135 | e.printStackTrace();
136 | }
137 | return delay;
138 | }
139 |
140 | /**
141 | * *********************************************************************************************
142 | * Public method
143 | * *********************************************************************************************
144 | */
145 |
146 | @Override
147 | public void start() {
148 | String res = launchPing();
149 | if (res != null && res.length() > 0) {
150 | res = res.toLowerCase();
151 | if (res.contains(NetModel.PING_UNREACHABLE) && !res.contains(NetModel.PING_EXCEED)) {
152 | // failed
153 | lossRate = 1f;
154 | error = HOST_UNREACHABLE_ERROR;
155 | } else {
156 | // succeed
157 | lossRate = parseLossFromPing(res);
158 | delay = parseDelayFromPing(res);
159 | if (analysisIp)
160 | ip = parseIpFromPing(res);
161 | }
162 | } else {
163 | error = DROP_DATA_ERROR;
164 | }
165 | }
166 |
167 | @Override
168 | public void cancel() {
169 | if (command != null)
170 | Command.cancel(command);
171 | }
172 |
173 | public String getIp() {
174 | return ip;
175 | }
176 |
177 | public float getLossRate() {
178 | return lossRate;
179 | }
180 |
181 | public float getDelay() {
182 | return delay;
183 | }
184 |
185 | public float getTotalTime() {
186 | return totalTime;
187 | }
188 |
189 | @Override
190 | public String toString() {
191 | return "IP:" + ip +
192 | " LossRate:" + lossRate +
193 | " Delay:" + delay +
194 | " TotalTime:" + totalTime;
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/SimplePing.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 | import java.net.UnknownHostException;
6 |
7 | /**
8 | * Created by QiuJU
9 | * on 2014/9/21.
10 | */
11 | public class SimplePing implements Runnable {
12 | private final Object mEndLock = new Object();
13 | private boolean IsEnd = false;
14 |
15 | private int arrivedCount = 0;
16 |
17 | private int Count;
18 | private int TimeOut;
19 | private String Name;
20 |
21 | private int mEndCount;
22 | private String mIp = null;
23 | private float mLossRate = 1f;
24 | private float mDelay = 0;
25 |
26 |
27 | public SimplePing(String name, int count, int timeOut) {
28 | Count = mEndCount = count;
29 | TimeOut = timeOut;
30 | Name = name;
31 | for (int i = 0; i < mEndCount; i++) {
32 | Thread thread = new Thread(this);
33 | thread.setDaemon(true);
34 | thread.start();
35 | }
36 | if (!IsEnd) {
37 | try {
38 | synchronized (mEndLock) {
39 | mEndLock.wait();
40 | }
41 | } catch (InterruptedException e) {
42 | e.printStackTrace();
43 | }
44 | }
45 | }
46 |
47 | private void setEnd(boolean isArrived, long delay, String ip) {
48 | synchronized (mEndLock) {
49 | Count--;
50 | if (isArrived) {
51 | arrivedCount++;
52 | mDelay = (mDelay + delay) / 2f;
53 | if (ip != null)
54 | mIp = ip;
55 | }
56 | }
57 | if (Count == 0)
58 | setEnd();
59 | }
60 |
61 | private void setEnd() {
62 | mLossRate = (mEndCount - arrivedCount) / mEndCount;
63 |
64 | IsEnd = true;
65 | synchronized (mEndLock) {
66 | mEndLock.notifyAll();
67 | }
68 | }
69 |
70 | @Override
71 | public void run() {
72 | long delay = 0;
73 | boolean isArrived = false;
74 | String ip = null;
75 | try {
76 | long startTime = System.currentTimeMillis();
77 | InetAddress address = InetAddress.getByName(Name);
78 | isArrived = address.isReachable(TimeOut);
79 | delay = System.currentTimeMillis() - startTime;
80 | ip = address.getHostAddress();
81 | } catch (UnknownHostException e) {
82 | e.printStackTrace();
83 | } catch (IOException e) {
84 | e.printStackTrace();
85 | } catch (Exception e) {
86 | e.printStackTrace();
87 | } finally {
88 | setEnd(isArrived, delay, ip);
89 | }
90 | }
91 |
92 | public String getIp() {
93 | return mIp;
94 | }
95 |
96 | public float getLossRate() {
97 | return mLossRate;
98 | }
99 |
100 | public float getDelay() {
101 | return mDelay;
102 | }
103 |
104 | public boolean getIsSucceed() {
105 | return arrivedCount > 0;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/SpeedRoad.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.HttpURLConnection;
7 | import java.net.InetAddress;
8 | import java.net.InetSocketAddress;
9 | import java.net.MalformedURLException;
10 | import java.net.Proxy;
11 | import java.net.URL;
12 | import java.net.UnknownHostException;
13 |
14 | /**
15 | * Created by QiuJu
16 | * on 2014/9/20.
17 | */
18 | public class SpeedRoad extends NetModel {
19 | private String urlStr, proxy;
20 | private int size, proxyPort;
21 | private long downSize, totalSize, downTime, connectTime;
22 | private float speed;
23 | private HttpURLConnection httpUrlConn = null;
24 |
25 |
26 | public SpeedRoad(String urlAddress, int size) {
27 | this(urlAddress, size, null, 0);
28 | }
29 |
30 | public SpeedRoad(String urlAddress, int size, String proxy, int proxyPort) {
31 | this.urlStr = urlAddress;
32 | this.size = size;
33 | this.proxy = proxy;
34 | this.proxyPort = proxyPort;
35 | }
36 |
37 | public float getSpeed() {
38 | return speed;
39 | }
40 |
41 | public long getDownSize() {
42 | return downSize;
43 | }
44 |
45 | public long getDownTime() {
46 | return downTime;
47 | }
48 |
49 | public long getTotalSize() {
50 | return totalSize;
51 | }
52 |
53 | public long getConnectTime() {
54 | return connectTime;
55 | }
56 |
57 | @Override
58 | public void start() {
59 | try {
60 | URL url = new URL(urlStr);
61 |
62 | //Proxy host
63 | if (proxy == null) {
64 | httpUrlConn = (HttpURLConnection) url.openConnection();
65 | } else {
66 | InetAddress inetAddress = InetAddress.getByAddress(convertIpToByte(proxy));
67 | Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(inetAddress, proxyPort));
68 | httpUrlConn = (HttpURLConnection) url.openConnection(proxy);
69 | }
70 |
71 | //set
72 | httpUrlConn.setConnectTimeout(15000);
73 | httpUrlConn.setReadTimeout(10000);
74 | httpUrlConn.setUseCaches(false);
75 | //get connectTime
76 | long beginTime = System.currentTimeMillis();
77 | httpUrlConn.connect();
78 | connectTime = System.currentTimeMillis() - beginTime;
79 | } catch (MalformedURLException e) {
80 | error = MALFORMED_URL_ERROR;
81 | } catch (UnknownHostException e) {
82 | error = UNKNOWN_HOST_ERROR;
83 | } catch (IOException e) {
84 | error = TCP_LINK_ERROR;
85 | } catch (Exception e) {
86 | error = UNKNOWN_ERROR;
87 | }
88 | //run
89 | if (error == SUCCEED)
90 | download(httpUrlConn);
91 | //close
92 | if (httpUrlConn != null) {
93 | close();
94 | }
95 | }
96 |
97 | @Override
98 | public void cancel() {
99 | if (httpUrlConn != null) {
100 | close();
101 | }
102 | }
103 |
104 | private void close() {
105 | try {
106 | OutputStream out = httpUrlConn.getOutputStream();
107 | if (out != null)
108 | out.close();
109 | } catch (Exception e) {
110 | e.printStackTrace();
111 | }
112 |
113 | try {
114 | InputStream in = httpUrlConn.getInputStream();
115 | closeInputStream(in);
116 | } catch (Exception e) {
117 | e.printStackTrace();
118 | }
119 |
120 | try {
121 | InputStream in = httpUrlConn.getErrorStream();
122 | closeInputStream(in);
123 | } catch (Exception e) {
124 | e.printStackTrace();
125 | }
126 | httpUrlConn.disconnect();
127 | httpUrlConn = null;
128 | }
129 |
130 | private void download(HttpURLConnection httpConn) {
131 | long beginTime = System.currentTimeMillis();
132 |
133 | int code;
134 | try {
135 | code = httpConn.getResponseCode();
136 | } catch (IOException e) {
137 | error = HTTP_CODE_ERROR;
138 | return;
139 | }
140 | if (code < 200 && code > 299)
141 | return;
142 | //get size
143 | long fSize = httpConn.getContentLength();
144 | long dwRead, curSize = 0;
145 | InputStream cin;
146 | try {
147 | cin = httpConn.getInputStream();
148 | } catch (IOException e) {
149 | error = SERVICE_NOT_AVAILABLE;
150 | return;
151 | }
152 | //file down
153 | if (fSize > 0) {
154 | try {
155 | byte[] buffer = new byte[32];
156 | while ((dwRead = cin.read(buffer)) != -1) {
157 | curSize += dwRead;
158 | if (curSize >= size || curSize >= fSize)
159 | break;
160 | if (curSize + buffer.length > size) {
161 | byte[] lastByte = new byte[(int) (size - curSize)];
162 | curSize += cin.read(lastByte);
163 | break;
164 | }
165 | }
166 | } catch (IOException e) {
167 | if (curSize <= 0) {
168 | error = SERVICE_NOT_AVAILABLE;
169 | return;
170 | }
171 | }
172 | //get result
173 | totalSize = fSize;
174 | downSize = curSize;
175 | downTime = System.currentTimeMillis() - beginTime;
176 | if (downTime <= 0)
177 | downTime = 1;
178 | speed = ((float) curSize * 1000) / downTime;
179 | } else {
180 | //page down
181 | try {
182 | byte[] buffer = new byte[32];
183 | while ((dwRead = cin.read(buffer)) != -1) {
184 | curSize += dwRead;
185 | if (curSize > size)
186 | break;
187 | }
188 | } catch (IOException e) {
189 | if (curSize <= 0) {
190 | error = SERVICE_NOT_AVAILABLE;
191 | return;
192 | }
193 | }
194 |
195 | //get result
196 | totalSize = curSize;
197 | downSize = size < curSize ? size : curSize;
198 | long time = (System.currentTimeMillis() - beginTime);
199 | if (time <= 0)
200 | time = 1;
201 | speed = ((float) curSize * 1000) / time;
202 | if (downSize == curSize)
203 | downTime = time;
204 | else
205 | downTime = (int) (time * ((float) downSize / curSize) + 1);
206 | }
207 | closeInputStream(cin);
208 | }
209 |
210 | @Override
211 | public String toString() {
212 | return "Speed:" + speed +
213 | " DownSize:" + downSize +
214 | " DownTime:" + downTime +
215 | " TotalSize:" + totalSize +
216 | " ConnectTime:" + connectTime;
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/Telnet.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import java.io.IOException;
4 | import java.net.InetSocketAddress;
5 | import java.net.Socket;
6 | import java.net.SocketException;
7 | import java.net.UnknownHostException;
8 |
9 | /**
10 | * @author QiuJu
11 | */
12 | public class Telnet extends NetModel {
13 | protected static final int TimeOutSize = 3000;
14 | private String host;
15 | private int port;
16 | private long delay;
17 | private boolean isConnected;
18 |
19 | public Telnet(String host, int port) {
20 | this.host = host;
21 | this.port = port;
22 | }
23 |
24 | @Override
25 | public void start() {
26 | Socket socket = null;
27 | try {
28 | Long bTime = System.currentTimeMillis();
29 | socket = new Socket();
30 | try {
31 | socket.setSoTimeout(TimeOutSize);
32 | } catch (SocketException e) {
33 | e.printStackTrace();
34 | }
35 | socket.connect(new InetSocketAddress(host, port), TimeOutSize);
36 | if (isConnected = socket.isConnected())
37 | delay = System.currentTimeMillis() - bTime;
38 | else
39 | error = TCP_LINK_ERROR;
40 | } catch (UnknownHostException e) {
41 | error = UNKNOWN_HOST_ERROR;
42 | } catch (IOException e) {
43 | error = TCP_LINK_ERROR;
44 | } finally {
45 | if (socket != null)
46 | try {
47 | socket.close();
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 | }
52 | }
53 |
54 | @Override
55 | public void cancel() {
56 |
57 | }
58 |
59 | public boolean isConnected() {
60 | return isConnected;
61 | }
62 |
63 | public long getDelay() {
64 | return delay;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "Port:" + port +
70 | " Delay:" + delay +
71 | " Connected:" + isConnected;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/nettool/TraceRoute.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.nettool;
2 |
3 | import net.qiujuer.genius.command.Command;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Collections;
7 | import java.util.Comparator;
8 | import java.util.List;
9 | import java.util.concurrent.CountDownLatch;
10 | import java.util.concurrent.TimeUnit;
11 |
12 | /**
13 | * Created by QiuJu
14 | * on 2014/9/21.
15 | */
16 | public class TraceRoute extends NetModel {
17 | private final static int OnceCount = 4;
18 | private final static int ForCount = 5;
19 | private final Object traceLock = new Object();
20 |
21 | private String target;
22 | private String ip;
23 | private List routes = null;
24 |
25 | private transient int errorCount = 0;
26 | private transient boolean done = false;
27 | private transient boolean isArrived = false;
28 | private transient List routeContainers = null;
29 | private transient List threads = null;
30 | private transient CountDownLatch mLatch = null;
31 |
32 | /**
33 | * TraceRoute domain or ip
34 | * Return the domain or ip route result
35 | *
36 | * @param target domain or ip
37 | */
38 | public TraceRoute(String target) {
39 | this.target = target;
40 | }
41 |
42 |
43 | /**
44 | * Clear List
45 | */
46 | private void clear() {
47 | if (threads != null) {
48 | synchronized (traceLock) {
49 | for (TraceThread thread : threads) {
50 | thread.cancel();
51 | }
52 | }
53 | }
54 | }
55 |
56 | private void complete(TraceThread trace, boolean isError, boolean isArrived, RouteContainer routeContainer) {
57 | if (threads != null) {
58 | synchronized (traceLock) {
59 | try {
60 | threads.remove(trace);
61 | } catch (NullPointerException e) {
62 | e.printStackTrace();
63 | }
64 | }
65 | }
66 | if (!done) {
67 | if (isError)
68 | this.errorCount++;
69 | this.isArrived = isArrived;
70 | if (routeContainers != null && routeContainer != null)
71 | routeContainers.add(routeContainer);
72 | }
73 | if (mLatch != null && mLatch.getCount() > 0)
74 | mLatch.countDown();
75 | }
76 |
77 | /**
78 | * Override Start
79 | */
80 | @Override
81 | public void start() {
82 | DnsResolve dns = new DnsResolve(target);
83 | dns.start();
84 | List ips = dns.getAddresses();
85 | if (dns.getError() != NetModel.SUCCEED || ips == null || ips.size() == 0)
86 | return;
87 | ip = ips.get(0);
88 |
89 | routeContainers = new ArrayList();
90 | threads = new ArrayList(OnceCount);
91 |
92 | for (int i = 0; i < ForCount; i++) {
93 | mLatch = new CountDownLatch(OnceCount);
94 | synchronized (traceLock) {
95 | for (int j = 1; j <= OnceCount; j++) {
96 | //get ttl
97 | final int ttl = i * OnceCount + j;
98 | //thread run get tp ttl ping information
99 | threads.add(new TraceThread(ip, ttl));
100 | }
101 | }
102 | try {
103 | mLatch.await(40, TimeUnit.SECONDS);
104 | } catch (InterruptedException e) {
105 | e.printStackTrace();
106 | }
107 |
108 | //end
109 | if (mLatch.getCount() > 0) {
110 | clear();
111 | }
112 |
113 | //clear
114 | mLatch = null;
115 | synchronized (traceLock) {
116 | threads.clear();
117 | }
118 |
119 | if (done || isArrived || errorCount > OnceCount - 1)
120 | break;
121 | }
122 |
123 | if (routeContainers.size() > 0) {
124 | //sort
125 | Collections.sort(routeContainers, new RouteContainerComparator());
126 | ArrayList routes = new ArrayList();
127 | int size = routeContainers.size();
128 | for (int s = 0; s < size; s++) {
129 | if (s > 0 && routeContainers.get(s).ip.equals(routeContainers.get(s - 1).ip)) {
130 | break;
131 | } else {
132 | routes.add(routeContainers.get(s).toString());
133 | }
134 | }
135 |
136 | routes.trimToSize();
137 | this.routes = routes;
138 | }
139 |
140 | routeContainers = null;
141 | threads = null;
142 | }
143 |
144 | /**
145 | * Override Cancel
146 | */
147 | @Override
148 | public void cancel() {
149 | done = true;
150 | clear();
151 | }
152 |
153 | /**
154 | * The Routes Target IP
155 | *
156 | * @return IP Address
157 | */
158 | public String getIp() {
159 | return ip;
160 | }
161 |
162 | /**
163 | * For routing values
164 | *
165 | * @return Routes
166 | */
167 | public List getRoutes() {
168 | return routes;
169 | }
170 |
171 | /**
172 | * Trace Route Thread
173 | */
174 | class TraceThread extends Thread {
175 | private String ip;
176 | private int ttl;
177 | private Ping ping;
178 | private Command command;
179 | private boolean isArrived;
180 | private boolean isError;
181 |
182 | public TraceThread(String ip, int ttl) {
183 | this.ip = ip;
184 | this.ttl = ttl;
185 | this.setName("TraceThread:" + ip + " " + ttl);
186 | this.setDaemon(true);
187 | this.start();
188 | }
189 |
190 | /**
191 | * TTL Route
192 | *
193 | * @param ip ip
194 | * @param ttl ttl
195 | * @return isError
196 | */
197 | private RouteContainer trace(String ip, int ttl) {
198 | String res = launchRoute(ip, ttl);
199 | if (!this.isInterrupted() && res != null && res.length() > 0) {
200 | res = res.toLowerCase();
201 | if (res.contains(PING_EXCEED) || !res.contains(PING_UNREACHABLE)) {
202 | // succeed
203 | String pIp = parseIpFromRoute(res);
204 | if (!this.isInterrupted() && pIp != null && pIp.length() > 0) {
205 | ping = new Ping(4, 32, pIp, false);
206 | ping.start();
207 | RouteContainer routeContainer = new RouteContainer(ttl, pIp, ping.getLossRate(), ping.getDelay());
208 | ping = null;
209 | isArrived = pIp.contains(ip);
210 | return routeContainer;
211 | }
212 | }
213 | }
214 | isError = true;
215 | return null;
216 | }
217 |
218 | /**
219 | * Get TTL IP
220 | *
221 | * @param ip Target IP
222 | * @param ttl TTL
223 | * @return Ping IP and TTL Result
224 | */
225 | private String launchRoute(String ip, int ttl) {
226 | command = new Command("/system/bin/ping",
227 | "-c", "4",
228 | "-s", "32",
229 | "-t", String.valueOf(ttl),
230 | ip);
231 |
232 | String str = null;
233 | try {
234 | str = Command.command(command);
235 | } catch (Exception e) {
236 | e.printStackTrace();
237 | } finally {
238 | command = null;
239 | }
240 | return str;
241 | }
242 |
243 | /**
244 | * Parsing IP address
245 | *
246 | * @param ping Ping IP and TTL Result
247 | * @return IP Address
248 | */
249 | private String parseIpFromRoute(String ping) {
250 | String ip = null;
251 | try {
252 | if (ping.contains(PING_FROM)) {
253 | // Get ip when ttl exceeded
254 | int index = ping.indexOf(PING_FROM);
255 | ip = ping.substring(index + 5);
256 | if (ip.contains(PING_PAREN_THESE_OPEN)) {
257 | int indexOpen = ip.indexOf(PING_PAREN_THESE_OPEN);
258 | int indexClose = ip.indexOf(PING_PAREN_THESE_CLOSE);
259 | ip = ip.substring(indexOpen + 1, indexClose);
260 | } else {
261 | // Get ip when after from
262 | ip = ip.substring(0, ip.indexOf("\n"));
263 | if (ip.contains(":"))
264 | index = ip.indexOf(":");
265 | else
266 | index = ip.indexOf(" ");
267 | ip = ip.substring(0, index);
268 | }
269 | } else if (ping.contains(PING)) {
270 | int indexOpen = ping.indexOf(PING_PAREN_THESE_OPEN);
271 | int indexClose = ping.indexOf(PING_PAREN_THESE_CLOSE);
272 | ip = ping.substring(indexOpen + 1, indexClose);
273 | }
274 | } catch (Exception e) {
275 | e.printStackTrace();
276 | }
277 | return ip;
278 | }
279 |
280 | @Override
281 | public void run() {
282 | super.run();
283 | RouteContainer routeContainer = trace(ip, ttl);
284 | complete(this, this.isError, this.isArrived, routeContainer);
285 | }
286 |
287 | /**
288 | * Cancel Test
289 | */
290 | public void cancel() {
291 | if (ping != null)
292 | ping.cancel();
293 | if (command != null)
294 | Command.cancel(command);
295 | try {
296 | this.interrupt();
297 | } catch (Exception e) {
298 | e.printStackTrace();
299 | }
300 | }
301 | }
302 |
303 | /**
304 | * Routing information
305 | */
306 | class RouteContainer {
307 | public String ip;
308 | public int ttl;
309 | public float loss;
310 | public float delay;
311 |
312 | public RouteContainer(int ttl, String ip, float loss, float delay) {
313 | this.ttl = ttl;
314 | this.ip = ip;
315 | this.loss = loss;
316 | this.delay = delay;
317 | }
318 |
319 | @Override
320 | public String toString() {
321 | return "Ttl:" + ttl + " " + ip + " Loss:" + loss + " Delay:" + delay;
322 | }
323 | }
324 |
325 | /**
326 | * The TraceRoute results are sorted to sort the TraceRoute result
327 | */
328 | class RouteContainerComparator implements Comparator {
329 | public int compare(RouteContainer routeContainer1, RouteContainer routeContainer2) {
330 | if (routeContainer1 == null)
331 | return 1;
332 | if (routeContainer2 == null)
333 | return -1;
334 | if (routeContainer1.ttl < routeContainer2.ttl)
335 | return -1;
336 | else if (routeContainer1.ttl == routeContainer2.ttl)
337 | return 0;
338 | else
339 | return 1;
340 | }
341 | }
342 |
343 | @Override
344 | public String toString() {
345 | return "IP:" + ip + " Routes:" + (routes == null ? "[]" : routes.toString());
346 | }
347 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/util/GeniusException.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.util;
2 |
3 | /**
4 | * Created by QiuJu
5 | * on 2014/11/24.
6 | */
7 | public class GeniusException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = -2912559384646531479L;
10 |
11 | public GeniusException(String detailMessage) {
12 | super(detailMessage);
13 | }
14 |
15 | public GeniusException(Throwable throwable) {
16 | super(throwable);
17 | }
18 |
19 | public GeniusException(String detailMessage, Throwable throwable) {
20 | super(detailMessage, throwable);
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/util/HashUtils.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.util;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.security.MessageDigest;
8 | import java.security.NoSuchAlgorithmException;
9 |
10 | /**
11 | * Created by QiuJu
12 | * on 2014/9/22.
13 | */
14 | public class HashUtils {
15 | private static final char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
16 | 'a', 'b', 'c', 'd', 'e', 'f'};
17 |
18 | private static String convertToHexString(byte[] b) {
19 | StringBuilder sb = new StringBuilder(b.length * 2);
20 | for (byte aB : b) {
21 | sb.append(HEX_DIGITS[(aB & 0xf0) >>> 4]);
22 | sb.append(HEX_DIGITS[aB & 0x0f]);
23 | }
24 | return sb.toString();
25 | }
26 |
27 | /**
28 | * Get a String's HashCode
29 | *
30 | * @param str String
31 | * @return HashCode
32 | */
33 | public static String getStringMd5(String str) {
34 | MessageDigest md5;
35 | try {
36 | md5 = MessageDigest.getInstance("MD5");
37 | } catch (NoSuchAlgorithmException e) {
38 | return null;
39 | }
40 | md5.update(str.getBytes());
41 | byte[] m = md5.digest();
42 | return convertToHexString(m);
43 | }
44 |
45 | /**
46 | * Get a File's HashCode
47 | *
48 | * @param file File
49 | * @return HashCode
50 | */
51 | public static String getFileMd5(File file) {
52 | InputStream in = null;
53 | byte[] buffer = new byte[1024];
54 | int numRead;
55 | MessageDigest md5;
56 | try {
57 | md5 = MessageDigest.getInstance("MD5");
58 | } catch (NoSuchAlgorithmException e) {
59 | return null;
60 | }
61 | try {
62 | in = new FileInputStream(file);
63 | while ((numRead = in.read(buffer)) > 0) {
64 | md5.update(buffer, 0, numRead);
65 | }
66 | return convertToHexString(md5.digest());
67 | } catch (Exception e) {
68 | return null;
69 | } finally {
70 | if (in != null)
71 | try {
72 | in.close();
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | }
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/library/src/main/java/net/qiujuer/genius/util/Tools.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.genius.util;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.telephony.TelephonyManager;
7 |
8 | import java.io.File;
9 | import java.io.FileInputStream;
10 | import java.io.FileOutputStream;
11 | import java.io.IOException;
12 | import java.lang.reflect.Method;
13 | import java.util.List;
14 |
15 | /**
16 | * Created by QiuJu
17 | * on 2014/8/13.
18 | * This is a util tools kit
19 | */
20 | public final class Tools {
21 | /**
22 | * Sleep time
23 | * Don't throw an InterruptedException exception
24 | *
25 | * @param time long time
26 | */
27 | public static void sleepIgnoreInterrupt(long time) {
28 | try {
29 | Thread.sleep(time);
30 | } catch (InterruptedException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 |
35 | /**
36 | * Copy file to file
37 | *
38 | * @param source Source File
39 | * @param target Target File
40 | * @return isCopy ok
41 | */
42 | public static boolean copyFile(File source, File target) {
43 | boolean bFlag = false;
44 | FileInputStream in = null;
45 | FileOutputStream out = null;
46 | try {
47 | if (!target.exists()) {
48 | boolean createSuccess = target.createNewFile();
49 | if (!createSuccess) {
50 | return false;
51 | }
52 | }
53 | in = new FileInputStream(source);
54 | out = new FileOutputStream(target);
55 | byte[] buffer = new byte[8 * 1024];
56 | int count;
57 | while ((count = in.read(buffer)) != -1) {
58 | out.write(buffer, 0, count);
59 | }
60 | bFlag = true;
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | bFlag = false;
64 | } finally {
65 | try {
66 | if (in != null) {
67 | in.close();
68 | }
69 | if (out != null) {
70 | out.close();
71 | }
72 | } catch (IOException e) {
73 | e.printStackTrace();
74 | }
75 | }
76 | return bFlag;
77 | }
78 |
79 | /**
80 | * Equipment is started for the first time the generated number
81 | * Are potential "9774d56d682e549c"
82 | *
83 | * @param context Context
84 | * @return Number
85 | */
86 | public static String getAndroidId(Context context) {
87 | return android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
88 | }
89 |
90 | /**
91 | * This device's SN
92 | *
93 | * @return SerialNumber
94 | */
95 | public static String getSerialNumber() {
96 | String serialNumber = android.os.Build.SERIAL;
97 | if ((serialNumber == null || serialNumber.length() == 0 || serialNumber.contains("unknown"))) {
98 | String[] keys = new String[]{"ro.boot.serialno", "ro.serialno"};
99 | for (String key : keys) {
100 | try {
101 | Method systemProperties_get = Class.forName("android.os.SystemProperties").getMethod("get", String.class);
102 | serialNumber = (String) systemProperties_get.invoke(null, key);
103 | if (serialNumber != null && serialNumber.length() > 0 && !serialNumber.contains("unknown"))
104 | break;
105 | } catch (Exception e) {
106 | e.printStackTrace();
107 | }
108 | }
109 | }
110 | return serialNumber;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/library/src/main/res/values/genius_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/library/src/main/res/values/genius_colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #ad843d
6 | #d4a14a
7 | #fbbf58
8 | #fae8c8
9 |
10 | - @color/sand_darker
11 | - @color/sand_dark
12 | - @color/sand_primary
13 | - @color/sand_light
14 |
15 |
16 |
17 | #994628
18 | #cc5d35
19 | #ff7342
20 | #ffbfa8
21 |
22 | - @color/orange_darker
23 | - @color/orange_dark
24 | - @color/orange_primary
25 | - @color/orange_light
26 |
27 |
28 |
29 | #80363c
30 | #bf505a
31 | #f56773
32 | #f5c4c8
33 |
34 | - @color/candy_darker
35 | - @color/candy_dark
36 | - @color/candy_primary
37 | - @color/candy_light
38 |
39 |
40 |
41 | #8f5e76
42 | #b57795
43 | #e898bf
44 | #e8d1dc
45 |
46 | - @color/blossom_darker
47 | - @color/blossom_dark
48 | - @color/blossom_primary
49 | - @color/blossom_light
50 |
51 |
52 |
53 | #362f4a
54 | #4f456b
55 | #695b8e
56 | #b1a2db
57 |
58 | - @color/grape_darker
59 | - @color/grape_dark
60 | - @color/grape_primary
61 | - @color/grape_light
62 |
63 |
64 |
65 | #232b35
66 | #2d3845
67 | #2d3845
68 | #c7dbf4
69 |
70 | - @color/deep_darker
71 | - @color/deep_dark
72 | - @color/deep_primary
73 | - @color/deep_light
74 |
75 |
76 |
77 | #0b6978
78 | #0e8b9e
79 | #13b7d2
80 | #b9e4eb
81 |
82 | - @color/sky_darker
83 | - @color/sky_dark
84 | - @color/sky_primary
85 | - @color/sky_light
86 |
87 |
88 |
89 | #124c38
90 | #1e7d5b
91 | #2ab081
92 | #a8e3ce
93 |
94 | - @color/grass_darker
95 | - @color/grass_dark
96 | - @color/grass_primary
97 | - @color/grass_light
98 |
99 |
100 |
101 | #050505
102 | #202020
103 | #454545
104 | #a3a3a3
105 |
106 | - @color/dark_darker
107 | - @color/dark_dark
108 | - @color/dark_primary
109 | - @color/dark_light
110 |
111 |
112 |
113 | #c8c8c8
114 | #dddddd
115 | #e8e8e8
116 | #fafafa
117 |
118 | - @color/snow_darker
119 | - @color/snow_dark
120 | - @color/snow_primary
121 | - @color/snow_light
122 |
123 |
124 |
125 | #1a3b6c
126 | #1c52a2
127 | #2d72d9
128 | #d5e3f7
129 |
130 | - @color/sea_darker
131 | - @color/sea_dark
132 | - @color/sea_primary
133 | - @color/sea_light
134 |
135 |
136 |
137 | #732219
138 | #a63124
139 | #d94130
140 | #f2b6ae
141 |
142 | - @color/blood_darker
143 | - @color/blood_dark
144 | - @color/blood_primary
145 | - @color/blood_light
146 |
147 |
148 |
--------------------------------------------------------------------------------
/maven_push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 | apply plugin: 'signing'
3 |
4 | def isReleaseBuild() {
5 | return VERSION_NAME.contains("SNAPSHOT") == false
6 | }
7 |
8 | def getReleaseRepositoryUrl() {
9 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
10 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
11 | }
12 |
13 | def getSnapshotRepositoryUrl() {
14 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
15 | : "https://oss.sonatype.org/content/repositories/snapshots/"
16 | }
17 |
18 | def getRepositoryUsername() {
19 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
20 | }
21 |
22 | def getRepositoryPassword() {
23 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
24 | }
25 |
26 | afterEvaluate { project ->
27 | uploadArchives {
28 | repositories {
29 | mavenDeployer {
30 | configurePOM(pom)
31 |
32 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
33 |
34 | repository(url: getReleaseRepositoryUrl()) {
35 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
36 | }
37 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
38 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
39 | }
40 | }
41 | }
42 | }
43 |
44 | signing {
45 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
46 | sign configurations.archives
47 | }
48 |
49 | task androidJavadocs(type: Javadoc) {
50 | failOnError false
51 | source = android.sourceSets.main.java.source
52 | options {
53 | links "http://docs.oracle.com/javase/7/docs/api/"
54 | linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
55 | }
56 | classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
57 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
58 | }
59 |
60 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
61 | classifier = 'javadoc'
62 | from androidJavadocs.destinationDir
63 | }
64 |
65 | task androidSourcesJar(type: Jar) {
66 | classifier = 'sources'
67 | from android.sourceSets.main.java.srcDirs
68 | }
69 |
70 | task apklib(type: Zip) {
71 | appendix = extension = 'apklib'
72 | from 'AndroidManifest.xml'
73 | into('res') {
74 | from 'res'
75 | }
76 | into('src') {
77 | from 'src'
78 | }
79 | }
80 |
81 | artifacts {
82 | archives androidSourcesJar
83 | archives androidJavadocsJar
84 | archives apklib
85 | }
86 | }
87 |
88 | private configurePOM(def pom) {
89 | pom.project {
90 | groupId POM_GROUP_ID
91 | artifactId POM_ARTIFACT_ID
92 | version VERSION_NAME
93 | name POM_NAME
94 | packaging POM_PACKAGING
95 | description POM_DESCRIPTION
96 | url POM_URL
97 | inceptionYear POM_INCEPTION_YEAR
98 |
99 | scm {
100 | url POM_SCM_URL
101 | connection POM_SCM_CONNECTION
102 | developerConnection POM_SCM_DEV_CONNECTION
103 | }
104 |
105 | licenses {
106 | license {
107 | name POM_LICENCE_NAME
108 | url POM_LICENCE_URL
109 | distribution POM_LICENCE_DIST
110 | comments POM_LICENCE_COMMENTS
111 | }
112 | }
113 |
114 | developers {
115 | developer {
116 | id POM_DEVELOPER_ID
117 | name POM_DEVELOPER_NAME
118 | email POM_DEVELOPER_EMAIL
119 | url POM_DEVELOPER_URL
120 | }
121 | }
122 |
123 | issueManagement {
124 | system POM_ISSUE_MANAGEMENT_SYSTEM
125 | url POM_ISSUE_MANAGEMENT_URL
126 | }
127 | }
128 | }
--------------------------------------------------------------------------------
/release/eclipse/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/release/eclipse/aidl/net/qiujuer/genius/command/ICommandInterface.aidl:
--------------------------------------------------------------------------------
1 | // ICommandInterface.aidl
2 | package net.qiujuer.genius.command;
3 |
4 | // Declare any non-default types here with import statements
5 |
6 | interface ICommandInterface {
7 | String command(String id, String params);
8 | void cancel(String id);
9 | void dispose();
10 | int getTaskCount();
11 | }
12 |
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/opensans_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/opensans_bold.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/opensans_extrabold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/opensans_extrabold.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/opensans_extralight.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/opensans_extralight.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/opensans_light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/opensans_light.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/opensans_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/opensans_regular.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/roboto_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/roboto_bold.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/roboto_extrabold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/roboto_extrabold.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/roboto_extralight.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/roboto_extralight.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/roboto_light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/roboto_light.ttf
--------------------------------------------------------------------------------
/release/eclipse/assets/fonts/roboto_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/assets/fonts/roboto_regular.ttf
--------------------------------------------------------------------------------
/release/eclipse/libs/arm64-v8a/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/arm64-v8a/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/libs/armeabi-v7a/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/armeabi-v7a/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/libs/armeabi/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/armeabi/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/libs/mips/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/mips/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/libs/mips64/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/mips64/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/libs/x86/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/x86/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/libs/x86_64/libgenius.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/eclipse/libs/x86_64/libgenius.so
--------------------------------------------------------------------------------
/release/eclipse/res/values/genius_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/release/eclipse/res/values/genius_colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #ad843d
6 | #d4a14a
7 | #fbbf58
8 | #fae8c8
9 |
10 | - @color/sand_darker
11 | - @color/sand_dark
12 | - @color/sand_primary
13 | - @color/sand_light
14 |
15 |
16 |
17 | #994628
18 | #cc5d35
19 | #ff7342
20 | #ffbfa8
21 |
22 | - @color/orange_darker
23 | - @color/orange_dark
24 | - @color/orange_primary
25 | - @color/orange_light
26 |
27 |
28 |
29 | #80363c
30 | #bf505a
31 | #f56773
32 | #f5c4c8
33 |
34 | - @color/candy_darker
35 | - @color/candy_dark
36 | - @color/candy_primary
37 | - @color/candy_light
38 |
39 |
40 |
41 | #8f5e76
42 | #b57795
43 | #e898bf
44 | #e8d1dc
45 |
46 | - @color/blossom_darker
47 | - @color/blossom_dark
48 | - @color/blossom_primary
49 | - @color/blossom_light
50 |
51 |
52 |
53 | #362f4a
54 | #4f456b
55 | #695b8e
56 | #b1a2db
57 |
58 | - @color/grape_darker
59 | - @color/grape_dark
60 | - @color/grape_primary
61 | - @color/grape_light
62 |
63 |
64 |
65 | #232b35
66 | #2d3845
67 | #2d3845
68 | #c7dbf4
69 |
70 | - @color/deep_darker
71 | - @color/deep_dark
72 | - @color/deep_primary
73 | - @color/deep_light
74 |
75 |
76 |
77 | #0b6978
78 | #0e8b9e
79 | #13b7d2
80 | #b9e4eb
81 |
82 | - @color/sky_darker
83 | - @color/sky_dark
84 | - @color/sky_primary
85 | - @color/sky_light
86 |
87 |
88 |
89 | #124c38
90 | #1e7d5b
91 | #2ab081
92 | #a8e3ce
93 |
94 | - @color/grass_darker
95 | - @color/grass_dark
96 | - @color/grass_primary
97 | - @color/grass_light
98 |
99 |
100 |
101 | #050505
102 | #202020
103 | #454545
104 | #a3a3a3
105 |
106 | - @color/dark_darker
107 | - @color/dark_dark
108 | - @color/dark_primary
109 | - @color/dark_light
110 |
111 |
112 |
113 | #c8c8c8
114 | #dddddd
115 | #e8e8e8
116 | #fafafa
117 |
118 | - @color/snow_darker
119 | - @color/snow_dark
120 | - @color/snow_primary
121 | - @color/snow_light
122 |
123 |
124 |
125 | #1a3b6c
126 | #1c52a2
127 | #2d72d9
128 | #d5e3f7
129 |
130 | - @color/sea_darker
131 | - @color/sea_dark
132 | - @color/sea_primary
133 | - @color/sea_light
134 |
135 |
136 |
137 | #732219
138 | #a63124
139 | #d94130
140 | #f2b6ae
141 |
142 | - @color/blood_darker
143 | - @color/blood_dark
144 | - @color/blood_primary
145 | - @color/blood_light
146 |
147 |
148 |
--------------------------------------------------------------------------------
/release/genius_0.9.0.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/genius_0.9.0.aar
--------------------------------------------------------------------------------
/release/genius_0.9.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/release/genius_0.9.0.jar
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 20
5 | buildToolsVersion "20.0.0"
6 |
7 | defaultConfig {
8 | applicationId "net.qiujuer.sample"
9 | minSdkVersion 15
10 | targetSdkVersion 20
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile project(':library')
25 | }
26 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\DevelopTools\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/net/qiujuer/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
31 |
34 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/sample/src/main/java/net/qiujuer/sample/BlurActivity.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.os.Build;
10 | import android.os.Bundle;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.view.ViewTreeObserver;
15 | import android.widget.LinearLayout;
16 | import android.widget.TextView;
17 |
18 | import net.qiujuer.genius.app.BlurKit;
19 | import net.qiujuer.genius.app.ToolKit;
20 |
21 |
22 | public class BlurActivity extends Activity {
23 | private LinearLayout linearLayout;
24 | private boolean scale;
25 | private TextView status;
26 |
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_blur);
32 | linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
33 | status = (TextView) findViewById(R.id.text_status);
34 | applyBlur();
35 | }
36 |
37 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
38 | private void applyBlur() {
39 | // 清理子控件背景,消除干扰
40 | clearDrawable();
41 | //添加监听
42 | linearLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
43 | @Override
44 | public boolean onPreDraw() {
45 | linearLayout.getViewTreeObserver().removeOnPreDrawListener(this);
46 | linearLayout.buildDrawingCache();
47 |
48 | Thread thread = new Thread(new Runnable() {
49 | @Override
50 | public void run() {
51 |
52 | try {
53 | final StringBuilder sb = new StringBuilder();
54 | sb.append("耗时:");
55 | for (int i = 1; i < 4; i++) {
56 | Bitmap bmp = linearLayout.getDrawingCache();
57 | sb.append(blur(bmp, i)).append(" ");
58 | }
59 |
60 | ToolKit.runOnMainThreadAsync(new Runnable() {
61 | @Override
62 | public void run() {
63 | status.setText(sb.toString());
64 | }
65 | });
66 |
67 | } catch (Exception e) {
68 | e.printStackTrace();
69 | }
70 | }
71 | });
72 | thread.setDaemon(true);
73 | thread.start();
74 | return true;
75 | }
76 | });
77 | }
78 |
79 |
80 | private long blur(Bitmap bkg, int i) {
81 | View view = null;
82 | if (i == 1)
83 | view = findViewById(R.id.text1);
84 | else if (i == 2)
85 | view = findViewById(R.id.text2);
86 | else if (i == 3)
87 | view = findViewById(R.id.text3);
88 |
89 | long startMs = System.currentTimeMillis();
90 |
91 | //设置参数:是否压缩 模糊半径
92 | float scaleFactor = 1;
93 | float radius = 20;
94 | if (scale) {
95 | scaleFactor = 8;
96 | radius = 2;
97 | }
98 |
99 | // 剪切 背景
100 | Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor),
101 | (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
102 | Canvas canvas = new Canvas(overlay);
103 | canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
104 | canvas.scale(1 / scaleFactor, 1 / scaleFactor);
105 | Paint paint = new Paint();
106 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
107 | canvas.drawBitmap(bkg, 0, 0, paint);
108 |
109 | //模糊
110 | if (i == 1)
111 | overlay = BlurKit.fastBlurInJava(overlay, (int) radius, true);
112 | else if (i == 2)
113 | overlay = BlurKit.fastBlurInJniArray(overlay, (int) radius, true);
114 | else if (i == 3)
115 | overlay = BlurKit.fastBlurInJniBitmap(overlay, (int) radius, true);
116 |
117 | setDrawable(view, overlay);
118 |
119 | return System.currentTimeMillis() - startMs;
120 | }
121 |
122 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
123 | private void clearDrawable() {
124 | findViewById(R.id.text1).setBackground(null);
125 | findViewById(R.id.text2).setBackground(null);
126 | findViewById(R.id.text3).setBackground(null);
127 | }
128 |
129 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
130 | private void setDrawable(final View view, final Bitmap overlay) {
131 | ToolKit.runOnMainThreadSync(new Runnable() {
132 | @Override
133 | public void run() {
134 | //Api Build.VERSION_CODES.JELLY_BEAN 以上支持直接setBackground
135 | view.setBackground(new BitmapDrawable(getResources(), overlay));
136 | }
137 | });
138 | }
139 |
140 |
141 | @Override
142 | public boolean onCreateOptionsMenu(Menu menu) {
143 | getMenuInflater().inflate(R.menu.menu_blur, menu);
144 | return true;
145 | }
146 |
147 | @Override
148 | public boolean onOptionsItemSelected(MenuItem item) {
149 | int id = item.getItemId();
150 |
151 | if (id == R.id.action_scale) {
152 | scale = !scale;
153 | applyBlur();
154 |
155 | if (scale)
156 | item.setTitle("直接模糊背景");
157 | else
158 | item.setTitle("压缩背景后模糊");
159 | return true;
160 | }
161 |
162 | return super.onOptionsItemSelected(item);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/sample/src/main/java/net/qiujuer/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import net.qiujuer.genius.Genius;
9 |
10 |
11 | public class MainActivity extends Activity {
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 |
17 | //初始化
18 | Genius.initialize(getApplication());
19 | }
20 |
21 | @Override
22 | protected void onDestroy() {
23 | //销毁
24 | Genius.dispose();
25 | super.onDestroy();
26 | }
27 |
28 | public void onClick(View view) {
29 | if (view.getId() == R.id.MaterialButton)
30 | startActivity(new Intent(this, MaterialActivity.class));
31 | else if (view.getId() == R.id.Other)
32 | startActivity(new Intent(this, TestCaseActivity.class));
33 | else if (view.getId() == R.id.Blur)
34 | startActivity(new Intent(this, BlurActivity.class));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sample/src/main/java/net/qiujuer/sample/MaterialActivity.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 |
7 | public class MaterialActivity extends Activity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_material);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/sample/src/main/java/net/qiujuer/sample/TestCaseActivity.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | import net.qiujuer.genius.Genius;
8 | import net.qiujuer.genius.app.ToolKit;
9 | import net.qiujuer.genius.command.Command;
10 | import net.qiujuer.genius.nettool.DnsResolve;
11 | import net.qiujuer.genius.nettool.Ping;
12 | import net.qiujuer.genius.nettool.SpeedRoad;
13 | import net.qiujuer.genius.nettool.Telnet;
14 | import net.qiujuer.genius.nettool.TraceRoute;
15 | import net.qiujuer.genius.util.FixedList;
16 | import net.qiujuer.genius.util.HashUtils;
17 | import net.qiujuer.genius.util.Log;
18 | import net.qiujuer.genius.util.Log.LogCallbackListener;
19 | import net.qiujuer.genius.util.Tools;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * Created by QiuJu
26 | * on 2014/11/25.
27 | *
28 | * 测试用例界面
29 | */
30 | public class TestCaseActivity extends Activity {
31 | private static final String TAG = TestCaseActivity.class.getSimpleName();
32 | TextView mText = null;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_test_case);
38 |
39 | mText = (TextView) findViewById(R.id.text);
40 |
41 | //添加回调
42 | Log.addCallbackListener(new LogCallbackListener() {
43 | @Override
44 | public void onLogArrived(final Log data) {
45 | //异步显示到界面
46 | ToolKit.runOnMainThreadAsync(new Runnable() {
47 | @Override
48 | public void run() {
49 | if (mText != null)
50 | mText.append("\n" + data.getMsg());
51 | }
52 | });
53 | }
54 | });
55 |
56 | //开始测试
57 | testLog();
58 | testToolKit();
59 | testHashUtils();
60 | testTools();
61 | testFixedList();
62 | testNetTool();
63 | testCommand();
64 | }
65 |
66 | @Override
67 | protected void onDestroy() {
68 | mText = null;
69 | super.onDestroy();
70 | }
71 |
72 | /**
73 | * 测试 App 工具包
74 | */
75 | void testToolKit() {
76 | // 同步模式一般用于更新界面同时等待界面更新完成后才能继续往下走的情况
77 | // 异步模式一般用于线程操作完成后统一更新主界面的情况
78 | Thread thread = new Thread(new Runnable() {
79 | @Override
80 | public void run() {
81 | // 测试运行在主线程中的情况,所以建立子线程进行调用
82 | // 方法中的操作将会切换到主线程中执行
83 | String msg = "ToolKit:";
84 | long start = System.currentTimeMillis();
85 | // 测试同步模式,在该模式下
86 | // 子线程将会等待其执行完成
87 | // 在主线程中调用该方法后才能继续往下走
88 | // 该方法首先会将要执行的命令放到队列中,等待主线程执行
89 | ToolKit.runOnMainThreadSync(new Runnable() {
90 | @Override
91 | public void run() {
92 | Tools.sleepIgnoreInterrupt(20);
93 | }
94 | });
95 | msg += "同步时间:" + (System.currentTimeMillis() - start) + ", ";
96 |
97 | start = System.currentTimeMillis();
98 | // 测试异步模式,在该模式下
99 | // 子线程调用该方法后既可继续往下走,并不会阻塞
100 | ToolKit.runOnMainThreadAsync(new Runnable() {
101 | @Override
102 | public void run() {
103 | Tools.sleepIgnoreInterrupt(20);
104 | }
105 | });
106 | msg += "异步时间:" + (System.currentTimeMillis() - start) + " ";
107 | Log.v(TAG, msg);
108 | }
109 | });
110 | thread.start();
111 | }
112 |
113 | /**
114 | * 日志测试
115 | */
116 | public void testLog() {
117 | //是否调用系统Android Log,发布时可设置为false
118 | Log.setCallLog(true);
119 |
120 | //清理存储的文件
121 | Log.clearLogFile();
122 |
123 | //是否开启写入文件,存储最大文件数量,单个文件大小(Mb)
124 | Log.setSaveLog(true, 10, 1);
125 |
126 | //设置是否监听外部存储插入操作
127 | //开启时插入外部设备(SD)时将拷贝存储的日志文件到外部存储设备
128 | //此操作依赖于是否开启写入文件功能,未开启则此方法无效
129 | //是否开启,SD卡目录
130 | Log.setCopyExternalStorage(true, "Test/Logs");
131 |
132 | //设置日志等级
133 | //VERBOSE为5到ERROR为1依次递减
134 | Log.setLevel(Log.ALL);
135 |
136 | Log.v(TAG, "测试日志 VERBOSE 级别。");
137 | Log.d(TAG, "测试日志 DEBUG 级别。");
138 | Log.i(TAG, "测试日志 INFO 级别。");
139 | Log.w(TAG, "测试日志 WARN 级别。");
140 | Log.e(TAG, "测试日志 ERROR 级别。");
141 |
142 | Log.setLevel(Log.INFO);
143 | Log.v(TAG, "二次测试日志 VERBOSE 级别。");
144 | Log.d(TAG, "二次测试日志 DEBUG 级别。");
145 | Log.i(TAG, "二次测试日志 INFO 级别。");
146 | Log.w(TAG, "二次测试日志 WARN 级别。");
147 | Log.e(TAG, "二次测试日志 ERROR 级别。");
148 |
149 | Log.setLevel(Log.ALL);
150 | }
151 |
152 | /**
153 | * 测试MD5
154 | */
155 | public void testHashUtils() {
156 | Log.i(TAG, "HashUtils:QIUJUER的MD5值为:" + HashUtils.getStringMd5("QIUJUER"));
157 | //文件MD5不做演示,传入file类即可
158 | }
159 |
160 | /**
161 | * 测试工具类
162 | */
163 | public void testTools() {
164 | Log.i(TAG, "Tools:getAndroidId:" + Tools.getAndroidId(Genius.getApplication()));
165 | Log.i(TAG, "Tools:getSerialNumber:" + Tools.getSerialNumber());
166 | }
167 |
168 | /**
169 | * 测试固定长度队列
170 | */
171 | public void testFixedList() {
172 | //初始化最大长度为5
173 | FixedList list = new FixedList(5);
174 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
175 | //添加4个元素
176 | list.add(1);
177 | list.add(2);
178 | list.add(3);
179 | list.add(4);
180 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
181 | //继续追加2个
182 | list.add(5);
183 | list.add(6);
184 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
185 | //调整最大长度
186 | list.setMaxSize(6);
187 | list.add(7);
188 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
189 | list.add(8);
190 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
191 | //缩小长度,自动删除前面多余部分
192 | list.setMaxSize(3);
193 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
194 | list.add(9);
195 | Log.i(TAG, "FixedList:" + list.size() + " ," + list.getMaxSize());
196 | //添加一个列表进去,自动删除多余部分
197 | List addList = new ArrayList();
198 | addList.add(10);
199 | addList.add(11);
200 | addList.add(12);
201 | addList.add(13);
202 | list.addAll(addList);
203 | Log.i(TAG, "FixedList:AddList:" + list.toString() + " " + list.size() + " ," + list.getMaxSize());
204 | //采用poll方式弹出元素
205 | Log.i(TAG, "FixedList:Poll:[" + list.poll() + "] " + list.size() + " ," + list.getMaxSize());
206 | Log.i(TAG, "FixedList:Poll:[" + list.poll() + "] " + list.size() + " ," + list.getMaxSize());
207 | Log.i(TAG, "FixedList:Poll:[" + list.poll() + "] " + list.size() + " ," + list.getMaxSize());
208 | //末尾插入元素与add一样
209 | list.addLast(14);
210 | list.addLast(15);
211 | list.addLast(16);
212 | list.addLast(17);
213 | list.addLast(18);
214 | Log.i(TAG, "FixedList:AddLast:" + list.toString() + " " + list.size() + " ," + list.getMaxSize());
215 | //从头部插入,默认删除尾部超出部分
216 | list.addFirst(19);
217 | list.addFirst(20);
218 | Log.i(TAG, "FixedList:AddFirst:" + list.toString() + " " + list.size() + " ," + list.getMaxSize());
219 | //Remove与poll类似不过不返回删除元素,只会删除一个
220 | list.remove();
221 | Log.i(TAG, "FixedList:Remove:" + list.toString() + " " + list.size() + " ," + list.getMaxSize());
222 | //清空操作
223 | list.clear();
224 | Log.i(TAG, "FixedList:Clear:" + list.toString() + " " + list.size() + " ," + list.getMaxSize());
225 |
226 | //使用List操作,最大长度2
227 | List list1 = new FixedList(2);
228 | list1.add(1);
229 | list1.add(2);
230 | Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString());
231 | list1.add(3);
232 | Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString());
233 | list1.add(4);
234 | Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString());
235 | list1.clear();
236 | Log.i(TAG, "FixedList:List:" + " " + list1.size() + " ," + list1.toString());
237 | }
238 |
239 | /**
240 | * 测试命令行执行
241 | */
242 | public void testCommand() {
243 | //同步
244 | Thread thread = new Thread() {
245 | public void run() {
246 | //调用方式与ProcessBuilder传参方式一样
247 | Command command = new Command("/system/bin/ping",
248 | "-c", "4", "-s", "100",
249 | "www.baidu.com");
250 | //同步方式执行
251 | String res = Command.command(command);
252 | Log.i(TAG, "\n\nCommand 同步:" + res);
253 | }
254 | };
255 | thread.setDaemon(true);
256 | thread.start();
257 |
258 | //异步
259 | Command command = new Command("/system/bin/ping",
260 | "-c", "4", "-s", "100",
261 | "www.baidu.com");
262 |
263 | //异步方式执行
264 | //采用回调方式,无需自己建立线程
265 | //传入回调后自动采用此种方式
266 | Command.command(command, new Command.CommandListener() {
267 | @Override
268 | public void onCompleted(String str) {
269 | Log.i(TAG, "\n\nCommand 异步 onCompleted:\n" + str);
270 | }
271 |
272 | @Override
273 | public void onCancel() {
274 | Log.i(TAG, "\n\nCommand 异步 onCancel");
275 | }
276 |
277 | @Override
278 | public void onError() {
279 | Log.i(TAG, "\n\nCommand 异步 onError");
280 | }
281 | });
282 | }
283 |
284 |
285 | /**
286 | * 基本网络功能测试
287 | */
288 | public void testNetTool() {
289 | //所有目标都可为IP地址
290 | Thread thread = new Thread() {
291 | public void run() {
292 | //包数,包大小,目标,是否解析IP
293 | Ping ping = new Ping(4, 32, "www.baidu.com", true);
294 | ping.start();
295 | Log.i(TAG, "Ping:" + ping.toString());
296 | //目标,可指定解析服务器
297 | DnsResolve dns = new DnsResolve("www.baidu.com");
298 | dns.start();
299 | Log.i(TAG, "DnsResolve:" + dns.toString());
300 | //目标,端口
301 | Telnet telnet = new Telnet("www.baidu.com", 80);
302 | telnet.start();
303 | Log.i(TAG, "Telnet:" + telnet.toString());
304 | //目标
305 | TraceRoute traceRoute = new TraceRoute("www.baidu.com");
306 | traceRoute.start();
307 | Log.i(TAG, "\n\nTraceRoute:" + traceRoute.toString());
308 | //测速
309 | //下载目标,下载大小
310 | SpeedRoad speedRoad = new SpeedRoad("http://down.360safe.com/se/360se_setup.exe", 1024 * 32);
311 | speedRoad.start();
312 | Log.i(TAG, "SpeedRoad:" + speedRoad.getSpeed());
313 | }
314 | };
315 | thread.setDaemon(true);
316 | thread.start();
317 | }
318 | }
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/sample/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/sample/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/blur_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/sample/src/main/res/drawable-xhdpi/blur_img.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/sample/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuyisheng/Genius-Android/acfc70788c2736e213b6c8ed5696cc0dec1b79ec/sample/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_blur.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
24 |
25 |
36 |
37 |
48 |
49 |
59 |
60 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
30 |
31 |
43 |
44 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_material.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
16 |
17 |
25 |
26 |
36 |
37 |
46 |
47 |
51 |
52 |
63 |
64 |
74 |
75 |
76 |
80 |
81 |
92 |
93 |
103 |
104 |
105 |
117 |
118 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_test_case.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
21 |
22 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_blur.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello world!
5 | Genius
6 | Genius
7 | MaterialActivity
8 | TestCaseActivity
9 | BlurActivity
10 | Settings
11 | 压缩背景后模糊
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':library'
2 |
3 |
--------------------------------------------------------------------------------