ExtensionKit
Kotlin常用扩展方法库
Install / Use
/learn @qzc0537/ExtensionKitREADME
ExtensionKit
Kotlin常用扩展库
使用
1.project build.gradle下添加: maven { url 'https://jitpack.io' }
如下:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
2.app build.gradle下添加依赖 :
implementation 'com.github.qzc0537:ExtensionKit:latestVersion'
3.愉快的使用:
EkConfigs.initToast(application, true, null)
EkConfigs.snackBarBgColor = color(R.color.colorPrimary)
EkConfigs.snackBarTextColor = Color.WHITE
EkConfigs.logEnable = true
dialogExtBtn1.onClick {
alert {
setTheme(R.style.AppTheme)
setTitle("对话框")
setMessage("这是DSL风格的对话框")
setPositiveButton("确定") { dialog, which -> toast("ok") }
setNegativeButton("取消") { dialog, which -> toast("no") }
setNeutralButton("再想想") { dialog, which -> toast("let me think") }
}
}
dialogExtBtn2.onClick {
val items = arrayOf("男", "女")
alert {
setTitle("对话框")
setSingleChoiceItems(items, 0) { dialog, which ->
toast(items[which])
}
setPositiveButton("确定") { dialog, which -> toast("ok") }
setNegativeButton("取消") { dialog, which -> toast("no") }
setCancelable(false)
setOnKeyListener { dialog, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK) dialog.dismiss()
true
}
}
}
dialogExtBtn3.onClick {
val items = arrayOf("苹果", "香蕉", "西瓜", "哈密瓜", "葡萄")
val checkedItems = booleanArrayOf(true, true, false, false, false)
alert {
setTitle("对话框")
setMultiChoiceItems(items, checkedItems) { dialog, which, isChecked ->
toast(items[which])
}
setPositiveButton("确定") { dialog, which -> toast("ok") }
setNegativeButton("取消") { dialog, which -> toast("no") }
}
}
snackBarExtBtn.onClick {
snackBarExtBtn.snackBarIndefinite("This is snackBar")
.setAction("Your Action") {
toast("Amazing")
}
}
doAsyncBtn.onClick {
doAsync {
Thread.sleep(1000)
activityUiThread {
toast("update UI")
}
}
}
permissionBtn.onClick {
request(Manifest.permission.CAMERA) {
onGranted { toast("获取权限成功") }
onDenied { toast("获取权限失败") }
onShowRationale {
alert {
setTitle("请求权限")
setMessage("我们需要相机权限")
setPositiveButton("确定") { dialog, which -> it.retry() }
setNegativeButton("取消") { dialog, which -> }
}
}
onNeverAskAgain { goToAppInfoPage() }
}
}
private fun otherApis() {
logi("isNetworkAvailable->${isNetworkAvailable()}")
logi("isWifiConnected->${isWifiConnected()}")
logi("getNetworkType->${getNetworkType()}")
toast("Hello")
val view = layoutInflater.inflate(R.layout.layout_toast, null)
toast(view)
startActivity<MainActivity>("id" to 5)
startActivity(intentFor<MainActivity>("id" to 5).singleTop())
startActivityForResult<MainActivity>(
1024, "id" to 5,
"id" to 5,
"id" to 5
)
if (afterL) {
logi("versionName->$versionName")
for (abi in phoneSupportAbis) {
logi("versionName->$abi")
}
}
logi("screenWidth->$screenWidth screenHeight->$screenHeight")
dp2px(10)
string(R.string.app_name)
color(R.color.colorPrimary)
drawable(R.mipmap.ic_launcher)
if ("ExtensionKit".notNullEmpty()) toast("not empty") else toast("null or empty")
val obj = null
"notNullMethod".notNull(
{
toast(this)
},
{
toast("null")
}
)
putValue("username", "John")
val username = getValue("username", "")
val bitmap = decodeResource(R.mipmap.ic_launcher)
bitmap.compressQuality(80)
val data = bitmap.bitmapToByte()
data.compressSampledFromByte(20, 20)
val file = File(externalCacheDir, "launcher.jpg")
val file2 = File(getPictureDir(), "launcher.jpg")
saveToInternal(bitmap, file)
saveToGallery(bitmap, file2)
}
权限相关
Activity管理
Activity相关
App相关
View相关
Toast相关
Log相关
Dialog相关
Intent相关
Bitmap相关
File相关
Gson相关
SP相关
SnackBar相关
SystemManager相关
异步操作相关
加密相关
网络相关
MD5相关
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
