它包含大部分 Android 实用类。
本项目囊括了 Android 应用开发过程中常用的绝大部分工具类。这些工具类部分整理自网络,部分由开发者自行编写,旨在提高开发效率,减少重复造轮子。
注意:由于 Bintray / JCenter 服务已下线,原有的 Maven 仓库引入方式已失效。建议通过 JitPack 引入,或直接将
util模块作为本地 Library 导入到您的项目中。
util 文件夹复制到您的项目中。settings.gradle 中包含该模块:include ':util'
build.gradle 中添加依赖:dependencies {
implementation project(':util')
}
如果您已将此项目 Fork 并推送到 GitHub,可以通过 JitPack 引入:
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.您的用户名:android-utils:Tag版本号'
}
findViewById 替代工具类
ViewUtils
View 测量与操作相关工具类
WindowUtils
窗口与屏幕工具类
BaseApplication
基础 Application(内置全局异常捕获处理)
BaseCrashHandler
统一捕获异常并保存到文件,下次打开时可上传
RebootThreadExceptionHandler
重启线程异常处理器,发生未知异常时自动重启应用
StartAppReceiver
重启应用广播接收器
在您的 AndroidManifest.xml 中按需添加以下权限:
如果需要全局的异常捕获与应用重启功能,可在 AndroidManifest.xml 中配置内置的 Application:
发布正式版本时,若想关闭或过滤 Log 日志,只需在代码初始化处设置:
LogUtils.DEBUG_LEVEL = Log.ASSERT;
如果您的项目启用了代码混淆,请在 Proguard 规则文件 (proguard-rules.pro 或 proguard.cfg) 中添加如下代码以防止工具类被错误混淆:
-keep class com.ihongqiqu.** { *; }
-keepclassmembers class com.ihongqiqu.** { *; }
-dontwarn com.ihongqiqu.**
在造轮子之前,也可以参考 AOSP 源码中自带的一些常用 Util 类(部分列出):
// 系统
android.database.DatabaseUtils
android.transition.TransitionUtils
android.view.animation.AnimationUtils
android.view.ViewAnimationUtils
android.webkit.URLUtil
android.bluetooth.le.BluetoothLeUtils
android.gesture.GestureUtils
android.text.TextUtils
android.text.format.DateUtils
android.os.FileUtils
android.net.NetworkUtils
android.util.MathUtils
android.util.TimeUtils
android.util.ExceptionUtils
android.telephony.PhoneNumberUtils
// ...
Copyright 2014-2017 Zhenguo Jin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
暂无开放 Issues,或尚未同步最近议题。