Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
R3.3.0
Browse files Browse the repository at this point in the history
为美观和增强辨识度改进UI:添加项目图标
  • Loading branch information
ryuunoakaihitomi committed Oct 24, 2020
1 parent 02b1298 commit 6a1fad1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ data class PowerInfo(
) {

companion object {
fun getLabelArray(array: Array<PowerInfo>): Array<CharSequence> {
val labelList = mutableListOf<CharSequence>()
array.forEach { labelList.add(it.label) }
return labelList.toTypedArray()
fun getLabelArray(array: Array<PowerInfo>) = getAttr(array) { label }
fun getIconResIdArray(array: Array<PowerInfo>) = getAttr(array) { iconResId }

private inline fun <reified T> getAttr(
array: Array<PowerInfo>,
member: PowerInfo.() -> T
): Array<T> {
val list = mutableListOf<T>()
array.forEach { list.add(it.member()) }
return list.toTypedArray()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -100,6 +101,7 @@ class MainActivity : AppCompatActivity() {
)
)
// 再次确认
setAdapter(null, null)
setItems(
arrayOf(
resources.getText(android.R.string.ok).emphasize(),
Expand Down Expand Up @@ -148,7 +150,6 @@ class MainActivity : AppCompatActivity() {
}

/* 去除操作选项 */
setItems(null, null)
setNeutralButton(null, null)
setOnCancelListener { powerViewModel.prepare() }
/* 主要信息 */
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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<CharSequence>, iconResId: Array<Int>) :
ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, items) {
private val iconResIdList: List<Int> = listOf(*iconResId)
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = super.getView(position, convertView, parent)
val textView = view.findViewById<TextView>(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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 6a1fad1

Please sign in to comment.