Skip to content

Commit 415ed30

Browse files
committed
feat: 新增开关强制对焦点通知进行反色
- 新增开关 `ENABLE_FOCUS_NOTIFICATION_FIX`,默认关闭 - 当该开关开启时,强制对焦点通知图标进行反色处理 - 调整了 SystemUIHooker 中对焦点通知图标的反色逻辑,使其在 `ENABLE_FOCUS_NOTIFICATION_FIX` 开启时生效 - 修复了当图标不是灰度图标时,也标记为需要反色的问题 Signed-off-by: ghhccghk <2137610394@qq.com>
1 parent 09a8d86 commit 415ed30

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

app/src/main/java/com/fankes/miui/notify/data/ConfigData.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ object ConfigData {
7272
/** 启用通知图标优化 */
7373
val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true)
7474

75+
/** 强制启用焦点通知反色 */
76+
val ENABLE_FOCUS_NOTIFICATION_FIX = PrefsData("_enable_focus_notification_fix", false)
77+
7578
/** 使用占位符修补未适配的通知图标 */
7679
val ENABLE_NOTIFY_ICON_FIX_PLACEHOLDER = PrefsData("_notify_icon_fix_placeholder", false)
7780

@@ -303,6 +306,16 @@ object ConfigData {
303306
putBoolean(ENABLE_NOTIFY_ICON_FIX, value)
304307
}
305308

309+
310+
/**
311+
* 是否强制启用焦点通知反色
312+
* @return [Boolean]*/
313+
var isEnableFocusNotificationFix
314+
get() = getBoolean(ENABLE_FOCUS_NOTIFICATION_FIX)
315+
set(value) {
316+
putBoolean(ENABLE_FOCUS_NOTIFICATION_FIX, value)
317+
}
318+
306319
/**
307320
* 是否使用占位符修补未适配的通知图标
308321
* @return [Boolean]

app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ object SystemUIHooker : YukiBaseHooker() {
498498
/** 处理自定义通知图标优化 */
499499
customTriple.first != null -> Pair(customTriple.first, true)
500500
/** 若不是灰度图标自动处理为圆角 */
501-
isGrayscaleIcon.not() -> Pair(notifyInstance.compatPushingIcon(context, iconDrawable).rounded(context), false)
501+
isGrayscaleIcon.not() -> Pair(notifyInstance.compatPushingIcon(context, iconDrawable).rounded(context), true)
502502
/** 否则返回原始小图标 */
503503
else -> Pair(notifyInstance.notification.smallIcon.loadDrawable(context), false)
504504
}
@@ -1002,7 +1002,7 @@ object SystemUIHooker : YukiBaseHooker() {
10021002
val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get()
10031003
if (ConfigData.isEnableModuleLog)
10041004
YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon")
1005-
if (focusedicon && ConfigData.isEnableNotifyIconFix )
1005+
if (focusedicon || ConfigData.isEnableFocusNotificationFix )
10061006
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
10071007
name = "setColorFilter"
10081008
superclass()
@@ -1024,7 +1024,7 @@ object SystemUIHooker : YukiBaseHooker() {
10241024
focusedicon == pair.second
10251025
val originalBitmap = pair.first?.toBitmap()
10261026
val bitmap = originalBitmap?.scale(50, 50)
1027-
result = Icon.createWithBitmap(bitmap).apply { if (pair.second && ConfigData.isEnableNotifyIconFix ) setTint(if (isDark) Color.BLACK else Color.WHITE) }
1027+
result = Icon.createWithBitmap(bitmap).apply { if (pair.second || ConfigData.isEnableFocusNotificationFix ) setTint(if (isDark) Color.BLACK else Color.WHITE) }
10281028
}
10291029
}
10301030
}

app/src/main/java/com/fankes/miui/notify/ui/activity/MainActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
241241
binding.miuiNotifyIconReplacementSwitch.bind(ConfigData.ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON) {
242242
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
243243
}
244+
binding.miuiFocusNotifyIconFixSwitch.bind(ConfigData.ENABLE_FOCUS_NOTIFICATION_FIX) {
245+
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
246+
}
244247
binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) {
245248
isAutoApplyChanges = false
246249
onChanged {

app/src/main/res/layout/activity_main.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,34 @@
11051105
android:textSize="12sp" />
11061106
</LinearLayout>
11071107

1108+
<LinearLayout
1109+
android:id="@+id/miui_focus_notify_icon_fix_item"
1110+
android:layout_width="match_parent"
1111+
android:layout_height="wrap_content"
1112+
android:orientation="vertical">
1113+
1114+
<com.fankes.miui.notify.ui.widget.MaterialSwitch
1115+
android:id="@+id/miui_focus_notify_icon_fix_switch"
1116+
android:layout_width="match_parent"
1117+
android:layout_height="wrap_content"
1118+
android:paddingLeft="15dp"
1119+
android:paddingRight="15dp"
1120+
android:text="是否强制启用焦点通知反色"
1121+
android:textColor="@color/colorTextGray"
1122+
android:textSize="15sp" />
1123+
1124+
<TextView
1125+
android:layout_width="match_parent"
1126+
android:layout_height="wrap_content"
1127+
android:alpha="0.6"
1128+
android:lineSpacingExtra="6dp"
1129+
android:paddingLeft="15dp"
1130+
android:paddingRight="15dp"
1131+
android:text="是否强制启用焦点通知反色,由于无法准确判断反色,所以给了个强制开关。(默认关闭)"
1132+
android:textColor="@color/colorTextDark"
1133+
android:textSize="12sp" />
1134+
</LinearLayout>
1135+
11081136
<LinearLayout
11091137
android:id="@+id/notify_icon_fix_notify_item"
11101138
android:layout_width="match_parent"

0 commit comments

Comments
 (0)