From 6a4e96923ebbbe61db641eac733a7c3c1bcd0182 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Fri, 25 Mar 2022 15:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=8A=B6=E6=80=81=E6=A0=8F?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=A0=8F=E6=9C=AA=E9=80=82=E9=85=8D=E7=9A=84?= =?UTF-8?q?=E5=BD=A9=E8=89=B2=E6=8E=A8=E9=80=81=E5=9B=BE=E6=A0=87=E4=B8=BA?= =?UTF-8?q?=20APP=20=E4=B8=BB=E9=A2=98=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notify/hook/entity/SystemUIHooker.kt | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index 6005f0c..a532e31 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -284,6 +284,7 @@ class SystemUIHooker : YukiBaseHooker() { /** 获取优化后的状态栏通知图标 */ compatStatusIcon( context = it.context, + nf = nf, isGrayscaleIcon = isGrayscaleIcon(it.context, iconDrawable), packageName = nf.packageName, drawable = iconDrawable @@ -372,19 +373,28 @@ class SystemUIHooker : YukiBaseHooker() { /** * 自动适配状态栏小图标 * @param context 实例 + * @param nf 通知实例 * @param isGrayscaleIcon 是否为灰度图标 * @param packageName APP 包名 * @param drawable 原始图标 * @return [Pair] - ([Drawable] 图标,[Boolean] 是否替换) */ - private fun compatStatusIcon(context: Context, isGrayscaleIcon: Boolean, packageName: String, drawable: Drawable) = - compatCustomIcon(isGrayscaleIcon, packageName).first.also { - /** 打印日志 */ - printLogcat(tag = "StatusIcon", context, packageName, isCustom = it != null, isGrayscaleIcon) - }?.let { Pair(BitmapDrawable(context.resources, it), true) } ?: Pair(drawable, false) + private fun compatStatusIcon( + context: Context, + nf: StatusBarNotification, + isGrayscaleIcon: Boolean, + packageName: String, + drawable: Drawable + ) = compatCustomIcon(isGrayscaleIcon, packageName).first.also { + /** 打印日志 */ + printLogcat(tag = "StatusIcon", context, packageName, isCustom = it != null, isGrayscaleIcon) + }?.let { Pair(BitmapDrawable(context.resources, it), true) } + ?: Pair(if (isGrayscaleIcon) drawable else nf.compatPushingIcon(context, drawable), !isGrayscaleIcon) /** * 自动适配通知栏小图标 + * @param context 实例 + * @param nf 通知实例 * @param isGrayscaleIcon 是否为灰度图标 * @param packageName APP 包名 * @param drawable 原始图标 @@ -392,6 +402,8 @@ class SystemUIHooker : YukiBaseHooker() { * @param iconView 图标 [ImageView] */ private fun compatNotifyIcon( + context: Context, + nf: StatusBarNotification, isGrayscaleIcon: Boolean, packageName: String, drawable: Drawable, @@ -438,7 +450,7 @@ class SystemUIHooker : YukiBaseHooker() { } else -> iconView.apply { /** 重新设置图标 */ - setImageDrawable(drawable) + setImageDrawable(nf.compatPushingIcon(context, drawable)) /** 设置裁切到边界 */ clipToOutline = true /** 设置一个圆角轮廓裁切 */ @@ -548,6 +560,7 @@ class SystemUIHooker : YukiBaseHooker() { nf.notification.smallIcon.loadDrawable(context).also { iconDrawable -> compatStatusIcon( context = context, + nf = nf, isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable), packageName = nf.packageName, drawable = iconDrawable @@ -598,15 +611,19 @@ class SystemUIHooker : YukiBaseHooker() { it.javaClass.method { name = "getSbn" }.get(it).invoke() - }?.notification?.also { nf -> - nf.smallIcon.loadDrawable(context).also { iconDrawable -> - compatNotifyIcon( - isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable), - packageName = context.packageName, - drawable = iconDrawable, - iconColor = nf.color, - iconView = this - ) + }.also { nf -> + nf?.notification?.also { + it.smallIcon.loadDrawable(context).also { iconDrawable -> + compatNotifyIcon( + context = context, + nf = nf, + isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable), + packageName = context.packageName, + drawable = iconDrawable, + iconColor = it.color, + iconView = this + ) + } } } }