From 6a1fad121515495037e1af3975741444d9ccd3f5 Mon Sep 17 00:00:00 2001 From: ryuunoakaihitomi <22442525+ryuunoakaihitomi@users.noreply.github.com> Date: Sat, 24 Oct 2020 10:25:56 +0800 Subject: [PATCH] =?UTF-8?q?R3.3.0=20=E4=B8=BA=E7=BE=8E=E8=A7=82=E5=92=8C?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E8=BE=A8=E8=AF=86=E5=BA=A6=E6=94=B9=E8=BF=9B?= =?UTF-8?q?UI=EF=BC=9A=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E5=9B=BE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 ++++----- .../powerpanel/desc/PowerInfo.kt | 14 ++++++++--- .../powerpanel/ui/main/MainActivity.kt | 23 ++++++----------- .../powerpanel/ui/main/PowerItemAdapter.kt | 25 +++++++++++++++++++ .../powerpanel/util/BlackMagic.kt | 4 +-- .../ryuunoakaihitomi/powerpanel/util/Utils.kt | 13 ++++++++++ build.gradle | 2 +- 7 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerItemAdapter.kt diff --git a/app/build.gradle b/app/build.gradle index 28ad8a3..6db78cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' /* 崩溃分析插件 */ apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' @@ -14,13 +13,13 @@ android { //targetSdkVersion compileSdkVersion targetSdkVersion 30 // 版本号:发布日期 - versionCode 20201007 + versionCode 20201024 /* 版本名说明: R3.0.0 Refactoring 第三次重构+功能更新+缺陷修复 */ - versionName "R3.2.4" + versionName "R3.3.0" resConfigs "en", "zh-rCN" // 致用户:可以在这里禁用Firebase,将以下值设为true final def disableFirebase = false @@ -59,11 +58,12 @@ dependencies { implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" /* 崩溃报告组件 */ - implementation 'com.google.firebase:firebase-analytics-ktx:17.6.0' - implementation 'com.google.firebase:firebase-crashlytics:17.2.2' + implementation platform('com.google.firebase:firebase-bom:25.12.0') + implementation 'com.google.firebase:firebase-analytics-ktx' + implementation 'com.google.firebase:firebase-crashlytics' /* --- 使用的非Google提供开源库 --- */ // PowerAct - implementation 'github.ryuunoakaihitomi.poweract:poweract:1.2.4' + implementation 'github.ryuunoakaihitomi.poweract:poweract:1.2.5' // Toasty implementation 'com.github.GrenderG:Toasty:1.5.0' // libsu diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerInfo.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerInfo.kt index ae6937f..5d50c6b 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerInfo.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerInfo.kt @@ -14,10 +14,16 @@ data class PowerInfo( ) { companion object { - fun getLabelArray(array: Array): Array { - val labelList = mutableListOf() - array.forEach { labelList.add(it.label) } - return labelList.toTypedArray() + fun getLabelArray(array: Array) = getAttr(array) { label } + fun getIconResIdArray(array: Array) = getAttr(array) { iconResId } + + private inline fun getAttr( + array: Array, + member: PowerInfo.() -> T + ): Array { + val list = mutableListOf() + array.forEach { list.add(it.member()) } + return list.toTypedArray() } } } \ No newline at end of file diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt index b576551..8286dd5 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt @@ -2,11 +2,7 @@ package github.ryuunoakaihitomi.powerpanel.ui.main import android.content.DialogInterface import android.content.pm.PackageManager -import android.graphics.Typeface import android.os.Bundle -import android.text.SpannableString -import android.text.style.StyleSpan -import android.text.style.TypefaceSpan import android.widget.AdapterView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity @@ -16,7 +12,6 @@ import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.toBitmap -import androidx.core.text.set import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.ViewModelProvider @@ -86,7 +81,13 @@ class MainActivity : AppCompatActivity() { } mainDialog = AlertDialog.Builder(this).apply { setTitle(powerViewModel.title.value) - setItems(PowerInfo.getLabelArray(it)) { dialog, which -> + setAdapter( + PowerItemAdapter( + this@MainActivity, + PowerInfo.getLabelArray(it), + PowerInfo.getIconResIdArray(it) + ) + ) { dialog, which -> val item = it[which] /* 如果为特权模式且不为锁屏,再次确认 */ if (powerViewModel.rootMode.value == true @@ -100,6 +101,7 @@ class MainActivity : AppCompatActivity() { ) ) // 再次确认 + setAdapter(null, null) setItems( arrayOf( resources.getText(android.R.string.ok).emphasize(), @@ -148,7 +150,6 @@ class MainActivity : AppCompatActivity() { } /* 去除操作选项 */ - setItems(null, null) setNeutralButton(null, null) setOnCancelListener { powerViewModel.prepare() } /* 主要信息 */ @@ -233,12 +234,4 @@ class MainActivity : AppCompatActivity() { }) powerViewModel.prepare() } -} - -private fun CharSequence.emphasize(): SpannableString = let { - val spannableString = SpannableString(it) - val range = 0..it.length - spannableString[range] = StyleSpan(Typeface.BOLD) - spannableString[range] = TypefaceSpan("monospace") - spannableString } \ No newline at end of file diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerItemAdapter.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerItemAdapter.kt new file mode 100644 index 0000000..f399c61 --- /dev/null +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerItemAdapter.kt @@ -0,0 +1,25 @@ +package github.ryuunoakaihitomi.powerpanel.ui.main + +import android.content.Context +import android.view.View +import android.view.ViewConfiguration +import android.view.ViewGroup +import android.widget.ArrayAdapter +import android.widget.TextView +import androidx.core.content.res.ResourcesCompat + +private typealias RC = ResourcesCompat + +class PowerItemAdapter(context: Context, items: Array, iconResId: Array) : + ArrayAdapter(context, android.R.layout.simple_list_item_1, items) { + private val iconResIdList: List = listOf(*iconResId) + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val view = super.getView(position, convertView, parent) + val textView = view.findViewById(android.R.id.text1) + textView.compoundDrawablePadding = ViewConfiguration.get(context).scaledTouchSlop + val drawable = RC.getDrawable(context.resources, iconResIdList[position], null)?.mutate() + drawable?.setTint(textView.textColors.defaultColor) + textView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null) + return view + } +} \ No newline at end of file diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/BlackMagic.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/BlackMagic.kt index 97bb67e..aaa5ece 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/BlackMagic.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/BlackMagic.kt @@ -18,15 +18,13 @@ object BlackMagic { private const val TAG = "BlackMagic" + @SuppressLint("PrivateApi") fun toastBugFix() { if (Build.VERSION.SDK_INT < Q) { runCatching { - @SuppressLint("DiscouragedPrivateApi") val getService = Toast::class.java.getDeclaredMethod("getService") getService.isAccessible = true val iNotificationManager = getService.invoke(null) - - @SuppressLint("PrivateApi") val iNotificationManagerProxy = Proxy.newProxyInstance( Toast::class.java.classLoader, arrayOf(Class.forName("android.app.INotificationManager")) diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Utils.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Utils.kt index 2d02e66..e6f70e0 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Utils.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Utils.kt @@ -3,11 +3,16 @@ package github.ryuunoakaihitomi.powerpanel.util import android.app.Activity import android.content.Context import android.content.Intent +import android.graphics.Typeface import android.net.Uri import android.os.Build import android.provider.Browser import android.service.quicksettings.Tile +import android.text.SpannableString +import android.text.style.StyleSpan +import android.text.style.TypefaceSpan import androidx.annotation.RequiresApi +import androidx.core.text.set import es.dmoral.toasty.Toasty @@ -34,4 +39,12 @@ fun Tile.updateState(state: Int) { this.state = state updateTile() } +} + +fun CharSequence.emphasize(): SpannableString = let { + val spannableString = SpannableString(it) + val range = 0..it.length + spannableString[range] = StyleSpan(Typeface.BOLD) + spannableString[range] = TypefaceSpan("monospace") + spannableString } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 745b587..be75a9e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.2' + classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" /* Crashlytics */