AndroidTools

中文版README
About AndroidTools
This library contains the most of tools that we use on Android development. Just add this to your module, you could simplify your code, save your valuable time, and make developing app easier. Enjoy tools, happy coding!
How to use AndroidTools
1.Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
2.Add this to your module's build.gradle file:
dependencies {
compile 'com.github.mazouri:AndroidTools:1.0'
}
3.Initiate AndroidTools in your application class:
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//[Required]
Tools.init(this);
//[Optional] if u wanna see AndroidTools internal logs, add this line.
Tools.openToolsLog(true);
}
}
4.Then U could use tools that u want like this:
// print log with tag.
Tools.log().tag(App.class.getSimpleName()).d("print log with tag()");
// is null or its length is 0. [will return false]
Tools.string().isEmpty(App.class.getSimpleName());
// is wifi connected? [will return true||false]
Tools.network().isWifiConnected(this);
Screenshots [tobeupdate]

Classify tools [tobeupdate]
You can also query by docs****.
I believe you could get the meaning of these methods by their name, so I will not translate the desc into English. Enjoy Tools!
Tools
| Tools.app() | 获取Application, 即Context |
All tools list: AppTool, ApkTool, InputMethodTool, IntentTool, ProcessTool, SnackbarTool, ToastTool, ConstantsTool, ConvertTool, DeviceTool, NetworkTool, BitmapTool, CloseTool, ExternalStorageTool, FileTool, SPTool, LogTool, RegexTool, SecureTool, ShellTool, StringTool, TimeTool, UnitTool.
AppTool
//usage examples:
Tools.appTool().getAllRunningService(Tools.app()); //获取所有运行的服务
Tools.appTool().startService(Tools.app(), MockService.class); //启动服务
| getAllRunningService |
获取所有运行的服务 |
| startService |
启动服务 |
| stopService |
停止服务 |
| bindService |
绑定服务 |
| unbindService |
解绑服务 |
| getAppVersionCode |
获取应用版本号 |
| getLauncherActivity |
获取launcher activity |
| getPackageName |
获取应用包名 |
| getTopActivityName |
获取顶层activity名称 |
| getVersionNameFromPackage |
获取应用版本名称 |
| isActivityExists |
判断是否存在Activity |
| isAppForeground |
判断App是否处于前台 |
| isProessRunning |
进程是否运行 |
| isProessRunning |
进程是否运行 |
| isRunningForeground |
判断应用是否在前台运行 |
| isServiceRunning |
服务是否运行 |
| launchActivity |
打开Activity |
ApkTool
//usage examples:
Tools.apk().getAppDetailsSettings(Tools.app()); // 获取App具体设置
| getAppDetailsSettings | 获取App具体设置 |
| getAppIcon | 获取App图标 |
| getAppName | 获取App名称 |
| getAppPath | 获取App路径 |
| getAppSignature | 获取App签名 |
| getAppSignatureSHA1 | 获取应用签名的的SHA1值 |
| getChannelFromApk | 从apk中获取版本信息 |
| installApp | 安装App |
| installAppSilent | 静默安装App |
| uninstallAppSilent | 静默卸载App |
| isAppDebug | 判断App是否是Debug版本 |
| isAppInstall | 检查手机上是否安装了指定的软件 |
| isAppRoot | 判断App是否有root权限 |
| isSystemApp | 判断App是否是系统应用 |
| launchApp | 打开App |
| uninstallApp | 卸载App |
InputMethodTool
//usage examples:
Tools.inputMethod().isActiveSoftInput(Tools.app()); // 判断输入法是否处于激活状态
| hideInputSoftFromWindowMethod | 隐藏键盘 :强制隐藏 |
| isActiveSoftInput | 判断输入负是否处于激活状态 |
| showInputSoftFromWindowMethod | 显示输入法 |
ProcessTool
//usage examples:
Tools.process().getAllBackgroundProcesses(); // 获取后台服务进程
| getAllBackgroundProcesses | 获取所有的后台服务进程 |
| getForegroundProcessName | 获取前台线程包名 |
| killAllBackgroundProcesses | 杀死所有的后台服务进程 |
| killBackgroundProcesses | 杀死后台服务进程 |
IntentTool
//usage examples:
Tools.intent().getInstallAppIntent("/sdcard/mock.apk"); // 获取安装App的意图
| getAppDetailsSettingsIntent | 获取App具体设置的意图 |
| getCaptureIntent | 获取拍照的意图 |
| getComponentIntent | 获取其他应用组件的意图 |
| getInstallAppIntent | 获取安装App的意图 |
| getLaunchAppIntent | 获取打开App的意图 |
| getShareImageIntent | 获取分享图片的意图 |
| getShareTextIntent | 获取分享文本的意图 |
| getShutdownIntent | 获取分享文本的意图 |
| getUninstallAppIntent | 获取分享文本的意图 |
SnackbarTool
//usage examples:
Tools.snackbar().dismissSnackbar()(); // 取消snackbar显示
| addView | 为snackbar添加布局 在show...Snackbar之后调用 |
| dismissSnackbar | 取消snackbar显示 |
| showIndefiniteSnackbar | 显示自定义时长snackbar |
| showLongSnackbar | 显示长时snackbar |
| showShortSnackbar | 显示短时snackbar |
ProcessTool
//usage examples:
Tools.process().getAllBackgroundProcesses(); // 获取后台服务进程
| getAllBackgroundProcesses | 获取后台服务进程 |
ToastTool
//usage examples:
Tools.toast().showToast(Toast.app, "show toast"); // 获取后台服务进程
| showToast | 显示Short型Toast |
| showToastLong | 显示Long型Toast |
ConvertTool
//usage examples:
Tools.convert().dp2px(50f); // dp转px
| bitmap2Bytes | bitmap转byteArr |
| bitmap2Drawable | bitmap转drawable |
| bits2Bytes | bits转bytes |
| byte2FitMemorySize | 字节数转合适内存大小 保留3位小数 |
| byte2MemorySize | 字节数转以unit为单位的内存大小 |
| bytes2Bitmap | byteArr转bitmap |
| bytes2Bits | bytes转bits |
| bytes2Chars | byteArr转charArr |
| bytes2Drawable | byteArr转drawable |
| bytes2HexString | byteArr转hexString |
| bytes2InputStream | byteArr转inputStream |
| bytes2OutputStream | outputStream转byteArr |
| dp2px | dp转px |
| px2dp | px转dp |
| px2sp | px转sp |
| sp2px | sp转px |
| drawable2Bitmap | drawable转bitmap |
| drawable2Bytes | drawable转byteArr |
| hexString2Bytes | hexString转byteArr |
| input2OutputStream | inputStream转outputStream |
| inputStream2Bytes | inputStream转byteArr |
| inputStream2String | inputStream转string按编码 |
| memorySize2Byte | 以unit为单位的内存大小转字节数 |
| millis2FitTimeSpan | 毫秒时间戳转合适时间长度 |
| millis2TimeSpan | 毫秒时间戳转以unit为单位的时间长度 |
| output2InputStream | outputStream转inputStream |
| outputStream2Bytes | outputStream转byteArr |
| outputStream2String | outputStream转string按编码 |
| string2InputStream | string转inputStream按编码 |
| string2OutputStream | string转outputStream按编码 |
| timeSpan2Millis | 以unit为单位的时间长度转毫秒时间戳 |
| view2Bitmap | view转Bitmap |
DeviceTool
//usage examples:
Tools.device().getAllSDCardSize(); // 获取SD大小
| coptyToClipBoard | 复制到剪切板 |
| existSDCard | 判断SDCard是否可用 |
| getAllSDCardSize | 获取SD大小 |
| getAppPackageNamelist | 获取非系统应用包名 |
| getAvailaleSDCardSize | 获取可用空间大小 |
| getIMEI | 获取IMEI |
| getLatestCameraPicture | 获取最后一次拍照的图片 |
| getLocalIPAddress | 获取本机IP地址 |
| getMac | 获取MAC地址 |
| getNavigationBarHeight | 获取navigationbar高度 |
| getScreenPix | 获取手机大小(分辨率) |
| getStatusBarHeight | 获取statusbar高度 |
| getTopBarHeight | 获取状态栏高度+标题栏(ActionBar)高度 |
| getUDID | 获取UDID |
| goHome | 主动回到Home,后台运行 |
| isOnline | 是否有网络 |
| isSoftKeyAvail | 判断是否有软控制键 |
| isSoftKeyAvail | 判断是否有软控制键 |
| vibrate | 震动 |
NetworkTool
//usage examples:
Tools.network().getDataEnabled()(); // 判断移动数据是否打开
| getDataEnabled | 判断移动数据是否打开 |
| getDomainAddress | 获取域名ip地址 |
| getIPAddress | 获取IP地址 |
| getNetType | 判断手机连接的网络类型(wifi,2G,3G,4G) |
| getNetworkOperatorName | 获取网络运营商名称 如中国移动、中国联通、中国电信 |
| is4G() | 判断网络是否是4G |
| isNetworkConnected | 判断是否连接网络 |
| isWifiConnected | 判断是否连接wifi |
| openWirelessSettings | 打开网络设置界面 3.0以下打开设置界面 |
| setDataEnabled | 打开或关闭移动数据 |
BitmapTool
//usage examples:
Tools.bitmap().toRoundCorner(); // 转化成圆bitmap
| bitmapToByte | Bitmap转bytes |
| bitmapToDrawable | Bitmap转Drawable |
| bitmapToString | bitmap转换成Base64编码String |
| byteToBitmap | bytes转Bitmap |
| compressBimap | 质量压缩图片-压缩在maxSize以内 |