fix:处理通知图标的 “app_package ” 并修复焦点通知图标的颜色 (#241)

* fix:处理通知图标的 “app_package ”并修复焦点通知图标的颜色

此提交解决了两个问题:

1.  **通知图标软件包名称:** 现在,如果通知中的 "app_package" 字符串可用,它将正确使用该字符串,并返回到通知的软件包名称。这可确保在一个应用程序代表另一个应用程序(如系统服务)发送通知时加载正确的图标。
2.  **焦点通知图标颜色:** 焦点通知图标的着色现在可根据通知图标优化配置正确应用,从而防止出现不正确的图标颜色。

Signed-off-by: ghhccghk <2137610394@qq.com>

* fix: 修复焦点通知图标逻辑异常,修复setTint导致无法正确着色

Signed-off-by: ghhccghk <2137610394@qq.com>

* fix: 修复焦点通知反色功能异常

Signed-off-by: ghhccghk <2137610394@qq.com>

* feat: 新增开关强制对焦点通知进行反色

- 新增开关 `ENABLE_FOCUS_NOTIFICATION_FIX`,默认关闭
- 当该开关开启时,强制对焦点通知图标进行反色处理
- 调整了 SystemUIHooker 中对焦点通知图标的反色逻辑,使其在 `ENABLE_FOCUS_NOTIFICATION_FIX` 开启时生效
- 修复了当图标不是灰度图标时,也标记为需要反色的问题

Signed-off-by: ghhccghk <2137610394@qq.com>

* style: some tweaks in SystemUIHooker

---------

Signed-off-by: ghhccghk <2137610394@qq.com>
Co-authored-by: fankesyooni <qzmmcn@163.com>
This commit is contained in:
李太白
2025-08-16 20:57:57 +08:00
committed by GitHub
parent 1551013414
commit 058c4534f7
4 changed files with 67 additions and 7 deletions

View File

@@ -72,6 +72,9 @@ object ConfigData {
/** 启用通知图标优化 */
val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true)
/** 强制启用焦点通知反色 */
val ENABLE_FOCUS_NOTIFICATION_FIX = PrefsData("_enable_focus_notification_fix", false)
/** 使用占位符修补未适配的通知图标 */
val ENABLE_NOTIFY_ICON_FIX_PLACEHOLDER = PrefsData("_notify_icon_fix_placeholder", false)
@@ -303,6 +306,16 @@ object ConfigData {
putBoolean(ENABLE_NOTIFY_ICON_FIX, value)
}
/**
* 是否强制启用焦点通知反色
* @return [Boolean]*/
var isEnableFocusNotificationFix
get() = getBoolean(ENABLE_FOCUS_NOTIFICATION_FIX)
set(value) {
putBoolean(ENABLE_FOCUS_NOTIFICATION_FIX, value)
}
/**
* 是否使用占位符修补未适配的通知图标
* @return [Boolean]

View File

@@ -226,6 +226,9 @@ object SystemUIHooker : YukiBaseHooker() {
/** 仅监听一次主题壁纸颜色变化 */
private var isWallpaperColorListenerSetUp = false
/** 用来同步是否需要焦点图标染色 */
private var focusedIcon = false
/**
* 获取全局上下文
* @return [Context] or null
@@ -474,8 +477,12 @@ object SystemUIHooker : YukiBaseHooker() {
/** 判断是否不是灰度图标 */
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)
/** 读取通知是否附加包名,如果没有则使用通知包名 */
val extras = notifyInstance.notification.extras
val pkgname = extras.getString("app_package")?.takeIf { it.isNotBlank() } ?: notifyInstance.nfPkgName
/** 目标彩色通知 APP 图标 */
val customTriple = compatCustomIcon(context, isGrayscaleIcon, notifyInstance.nfPkgName)
val customTriple = compatCustomIcon(context, isGrayscaleIcon, pkgname)
/** 是否为通知优化生效图标 */
val isCustom = customTriple.first != null && customTriple.third.not()
@@ -573,9 +580,13 @@ object SystemUIHooker : YukiBaseHooker() {
/** 自定义默认小图标 */
var customIcon: Drawable? = null
/** 读取通知是否附加包名,如果没有则使用通知包名 */
val extras = notifyInstance.notification.extras
val pkgname = extras.getString("app_package")?.takeIf { it.isNotBlank() } ?: notifyInstance.nfPkgName
/** 自定义默认小图标颜色 */
var customIconColor = 0
compatCustomIcon(context, isGrayscaleIcon, notifyInstance.nfPkgName).also {
compatCustomIcon(context, isGrayscaleIcon, pkgname).also {
/** 不处理占位符图标 */
if (it.third) return@also
customIcon = it.first
@@ -985,10 +996,11 @@ object SystemUIHooker : YukiBaseHooker() {
val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get()
if (ConfigData.isEnableModuleLog)
YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon")
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
name = "setColorFilter"
superclass()
}?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
if (focusedIcon || ConfigData.isEnableFocusNotificationFix)
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
name = "setColorFilter"
superclass()
}?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
}
}
/** 去他妈的焦点通知彩色图标 */
@@ -1003,9 +1015,13 @@ object SystemUIHooker : YukiBaseHooker() {
nf = expandedNf,
iconDrawable = small?.loadDrawable(context)
).also { pair ->
focusedIcon = pair.second
val originalBitmap = pair.first?.toBitmap()
val bitmap = originalBitmap?.scale(50, 50)
result = Icon.createWithBitmap(bitmap).apply { if (pair.second) setTint(if (isDark) Color.BLACK else Color.WHITE) }
result = Icon.createWithBitmap(bitmap).apply {
if (pair.second || ConfigData.isEnableFocusNotificationFix)
setTint(if (isDark) Color.BLACK else Color.WHITE)
}
}
}
}

View File

@@ -241,6 +241,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.miuiNotifyIconReplacementSwitch.bind(ConfigData.ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON) {
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
}
binding.miuiFocusNotifyIconFixSwitch.bind(ConfigData.ENABLE_FOCUS_NOTIFICATION_FIX) {
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
}
binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) {
isAutoApplyChanges = false
onChanged {

View File

@@ -1105,6 +1105,34 @@
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/miui_focus_notify_icon_fix_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.fankes.miui.notify.ui.widget.MaterialSwitch
android:id="@+id/miui_focus_notify_icon_fix_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="是否强制启用焦点通知反色"
android:textColor="@color/colorTextGray"
android:textSize="15sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="是否强制启用焦点通知反色,由于无法准确判断反色,所以给了个强制开关。(默认关闭)"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/notify_icon_fix_notify_item"
android:layout_width="match_parent"