From 5e56c1bc57edb38b7681987a11d5c92140abc5ac Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Thu, 2 Feb 2023 00:09:15 +0800 Subject: [PATCH] Fix some system's notification icons maybe reset by the system cause wrong icon color in SystemUIHooker --- .../coloros/notify/hook/entity/SystemUIHooker.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 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 fc82375..9b16686 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 @@ -418,15 +418,24 @@ object SystemUIHooker : YukiBaseHooker() { iconView: ImageView ) = runInSafe { compatCustomIcon(context, isGrayscaleIcon, packageName).also { customPair -> + /** 设置一个用于替换的图标 */ + val placeholderView = ImageView(context) + /** 克隆之前图标的所有布局信息 */ + (iconView.parent as? ViewGroup?)?.apply { addView(placeholderView.apply { layoutParams = iconView.layoutParams }) } + ?: loggerE(msg = "Cannot got the orginal notification icon's parent view \"${nf.packageName}\"(\"${nf.opPkg}\") of $nf") + /** 将之前图标的间距设置为一个超大值以达到隐藏的效果 */ + 999.also { iconView.setPadding(it, it, it, it) } + /** 清除之前图标可能存在的背景 */ + iconView.background = null when { prefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) && isEnableHookColorNotifyIcon(isHooking = false) -> - iconView.apply { + placeholderView.apply { /** 重新设置图标 */ setImageDrawable(appIcons[packageName] ?: context.appIconOf(packageName)) /** 设置默认样式 */ setDefaultNotifyIconViewStyle() } - customPair.first != null || isGrayscaleIcon -> iconView.apply { + customPair.first != null || isGrayscaleIcon -> placeholderView.apply { /** 设置不要裁切到边界 */ clipToOutline = false /** 重新设置图标 */ @@ -467,7 +476,7 @@ object SystemUIHooker : YukiBaseHooker() { setPadding(0, 0, 0, 0) } } - else -> iconView.apply { + else -> placeholderView.apply { /** 重新设置图标 */ setImageDrawable(nf.compatPushingIcon(drawable)) /** 设置默认样式 */