implementation 'com.hosigus:tools:1.3'
- DensityUtils
- DownloadManager
- Encryptor
- LogUtils
- NetUtils
- PermissionUtils
- ThreadUtils
- ToastUtils
- to get screen size, dp2px/px2dp, make dialog full screen
- multithreaded section downloader
- encrypt md5 string
- manage logs
- use post/get to get JSONBean from internet
- easy to deal with permission after API 23
- manage threads , async / main thread
- easy to toast , avoid repetition show toast
- How to use it ? [show me demo]
-
DownloadManager
- init manager
val option = DownloadOption(url,filePath,fileName) .listener(object : DownloadListener { //there are other functions: // 'onStart','onPaused','onCancel','onFailed(e: Exception)' override fun onDownloading(progress: Int, size: Int) { TODO("update progress") } override fun onSuccess(download:File) { TODO("use the file") } }) val manager = DownloadManager(this, option)
- use manager to control download
//start download manager.download() //pause download manager.pause()//use it if you want to keep cache for continue //continue download manager.download() //cancel download manager.cancel()//it will delete cache file,make sure you want to cancel download plan //delete the file which have download successfully manager.delete() //start print logs, you may need it when debug manager.openLog() //close print logs, I think it's useless,I'm considering about to delete it manager.closeLog()
-
PermissionUtils
- add option , it needs code(unique),permissions,callback
addOption(PermissionOption(requestCode) .permissions(arrayOf(Manifest.permission.XXX)) .callback(object : PermissionCallback { //there is another function: // onDenied(DeniedPermissions: Array<String>){} override fun onGranted() { TODO("do something needs permissions") } }))
- override fun , let me agent permission for you
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) onPermissionRequest(requestCode,permissions,grantResults) }
-
use option , execute the option/plan you made before
executeOption(this@XXXActivity, requestCode)
-
[update later]