Small Kotlin extension functions for Android that make your app development with Kotlin more fun!
activity.checkAllPermissions(setOf(CAMERA, WRITE_EXTERNAL_STORAGE)) {
// Execute if all permissions granted
} ?: "Permissions not granted!".logWarning()
activity.requestPermissions(arrayOf(WRITE_EXTERNAL_STORAGE), 123456)
context.getAlarmManager()
context.registerReceiver(broadcastReceiver { context, intent -> intent.log() }, IntentFilter("Action Filter!"))
activity.progressDialog(R.string.title) {
// Do your backgroud task
}
activity.confirmationDialog(R.string.title, R.string.message) {
// Code to control OK
}
activity.singleChoiceDialog(R.string.title, listOf("Element 1", "Element 2"), R.string.notSelected) { selectedItem ->
// Do something with the selected String
}
longToast(R.string.translatedString)
toast("Hello there!") // Avoid this, you really should always use resources
myView.invisible()
myView.disable()
myViewGroup.disableChildren()
myView.doAnimation(R.anim.myAnimation)
myView.slideUp()
byteArray.toBitmap()
byteArray.toDrawable()
myBitmap.toPNG()
"tvName".findViewByName(activity)
closeKeyboard()
showKeyboard()
myEditText.textString = "Simpler than setText(text, TextView.BufferType.NORMAL)"
"@string/that_useful_string".getStringResourceByName(activity)
myBundle.toMap()
myMap.toBundle()
Date().format("MM/dd/yyyy")
val downloadDir = defaultDownloadDirectory
val picturesDir = defaultPicturesDirectory
File(getPictureDirectory(), "image.png").asBitmap()
File(getPictureDirectory(), "image.png").asDrawable()
File(getDownloadDirectory(), "BestApp.apk").installAPK(activity)
File(getDownloadDirectory(), "SystemApp.apk").installSystemAPK(activity)
File(getDownloadDirectory(), "StealthApp.apk").installAPKNoPrompt(activity)
File("IsThisFileLegit.apk").md5()
File("A File With Names.txt").grep("^J".toRegex())
File("uselss file").delete().ifFalse { "Why I can't delete this useless file!".log() }
"Ada Lovelace".log("OMGLOG")
0.log("INTLOG!")
listOf("Ada", "Boole", "Dijkstra").log("LISTLOG!")
arrayOf("Ada", "Boole", "Dijkstra").log("OMGARRAYSWORKTOO!")
listOf("Ada", "Von Neumann", "Turing")
.log("Original list")
.filter { it.contains("a") }
.log("Filtered list")
"Ada Lovelace".logDebug("OMGLOG")
0.logInfo("INTLOG!")
listOf("Ada", "Boole", "Dijkstra").logWarning("LISTLOG!")
arrayOf("Ada", "Boole", "Dijkstra").logError("OMGARRAYSWORKTOO!")
try {
throw Exception("Something nasty happened")
} catch (e: Exception) {
e.log("Your exception tag")
}
"Ada Lovelace".log()
ignoreErrors {
throw IOException("File not found!")
}
logExecutionTime {
(0..100_000).forEach { it.log("A number") }
}
logCallTrace()
"ls -l /data".runCommand()
"ls -l /system".runCommandAsSu()
reboot()
shutdown()
listOf(1.toByte(), 2.toByte()).toTypedArray().toHex().log("My sweet little array")
val byteArray = base64String.decode()
val base64String = byteArray.encode()