style: format code in SystemUIHooker

This commit is contained in:
2024-12-07 00:48:06 +08:00
parent 3cc2787a88
commit 992db5c4cf

View File

@@ -32,7 +32,6 @@ import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.graphics.Color import android.graphics.Color
import android.graphics.Outline import android.graphics.Outline
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.os.Build import android.os.Build
@@ -341,7 +340,7 @@ object SystemUIHooker : YukiBaseHooker() {
* @return [Drawable] * @return [Drawable]
*/ */
private fun Drawable.rounded(context: Context) = private fun Drawable.rounded(context: Context) =
safeOf(default = this) { BitmapDrawable(context.resources, toBitmap().round(10.dpFloat(context))) } safeOf(default = this) { toBitmap().round(10.dpFloat(context)).toDrawable(context.resources) }
/** /**
* 适配通知栏、状态栏来自系统推送的彩色 APP 图标 * 适配通知栏、状态栏来自系统推送的彩色 APP 图标
@@ -890,28 +889,23 @@ object SystemUIHooker : YukiBaseHooker() {
* 强制修改 getCustomAppIcon 获取的图标为 smallIcon * 强制修改 getCustomAppIcon 获取的图标为 smallIcon
* 部分系统没有 "getCustomAppIcon" 这个方法 - 所以直接忽略 * 部分系统没有 "getCustomAppIcon" 这个方法 - 所以直接忽略
*/ */
if (hasMethod { name = "getCustomAppIcon" }){ if (hasMethod { name = "getCustomAppIcon" })
method{ method {
name = "getCustomAppIcon" name = "getCustomAppIcon"
param(NotificationClass, ContextClass) param(NotificationClass, ContextClass)
}.hook().after { }.hook().after {
val nf = args(0).cast<Notification>() val nf = args().first().cast<Notification>()
val ct = args(1).cast<Context>() val context = args(index = 1).cast<Context>()
val smail = nf?.smallIcon?.loadDrawable(ct)?.toBitmap() val iconBitmap = nf?.smallIcon?.loadDrawable(context)?.toBitmap()
if (smail != null && !smail.isRecycled) { result = if (context != null && iconBitmap != null && !iconBitmap.isRecycled)
if (ct != null) { iconBitmap.toDrawable(context.resources)
result = BitmapDrawable(ct.resources, smail) else null
}
} else {
result = null
}
} }
}
/** /**
* 强制回写系统的状态栏图标样式为原生 * 强制回写系统的状态栏图标样式为原生
* 部分系统没有 "getSmallIcon" 这个方法 - 所以直接忽略 * 部分系统没有 "getSmallIcon" 这个方法 - 所以直接忽略
*/ */
if (hasMethod { name = "getSmallIcon" }){ if (hasMethod { name = "getSmallIcon" })
method { method {
name = "getSmallIcon" name = "getSmallIcon"
param { it[0] extends StatusBarNotificationClass && it[1] == IntType } param { it[0] extends StatusBarNotificationClass && it[1] == IntType }
@@ -935,7 +929,6 @@ object SystemUIHooker : YukiBaseHooker() {
).also { pair -> if (pair.second) result = Icon.createWithBitmap(pair.first?.toBitmap()) } ).also { pair -> if (pair.second) result = Icon.createWithBitmap(pair.first?.toBitmap()) }
} }
} }
}
} }
/** 去他妈的焦点通知彩色图标 */ /** 去他妈的焦点通知彩色图标 */
FocusUtils?.apply { FocusUtils?.apply {
@@ -948,8 +941,8 @@ object SystemUIHooker : YukiBaseHooker() {
param(ExpandedNotificationClass) param(ExpandedNotificationClass)
} }
}.hook().after { }.hook().after {
(globalContext ?: args().first().cast())?.also { context -> globalContext?.also { context ->
val expandedNf = args(0).cast<StatusBarNotification?>() val expandedNf = args().first().cast<StatusBarNotification?>()
/** Hook 状态栏小图标 */ /** Hook 状态栏小图标 */
compatStatusIcon( compatStatusIcon(
context = context, context = context,