Skip to content

Commit be8f558

Browse files
committed
Added notification icon force system color function
1 parent 175263c commit be8f558

4 files changed

Lines changed: 69 additions & 4 deletions

File tree

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
@@ -60,6 +60,9 @@ object ConfigData {
6060
/** 通知栏中的通知图标圆角程度 */
6161
val NOTIFY_ICON_CORNER_SIZE = PrefsData("_notify_icon_corner", 15)
6262

63+
/** 强制通知栏中的通知图标使用系统着色 */
64+
val ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR = PrefsData("_notify_icon_force_system_color", false)
65+
6366
/** 强制通知栏中的通知图标为 APP 图标 */
6467
val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false)
6568

@@ -257,6 +260,16 @@ object ConfigData {
257260
putInt(NOTIFY_ICON_CORNER_SIZE, value)
258261
}
259262

263+
/**
264+
* 是否强制通知栏中的通知图标使用系统着色
265+
* @return [Boolean]
266+
*/
267+
var isEnableNotifyIconForceSystemColor
268+
get() = getBoolean(ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR)
269+
set(value) {
270+
putBoolean(ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR, value)
271+
}
272+
260273
/**
261274
* 是否强制通知栏中的通知图标为 APP 图标
262275
* @return [Boolean]

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ object SystemUIHooker : YukiBaseHooker() {
438438
val iconColor = notifyInstance.notification.color
439439

440440
/** 是否有通知栏图标颜色 */
441-
val hasIconColor = iconColor != 0
441+
val hasIconColor = iconColor != 0 && ConfigData.isEnableNotifyIconForceSystemColor.not()
442442

443443
/** 通知图标适配颜色 */
444-
val supportColor = iconColor.let {
444+
val supportColor = (iconColor.takeIf { ConfigData.isEnableNotifyIconForceSystemColor.not() } ?: 0).let {
445445
when {
446446
isUseMaterial3Style -> newStyle
447447
it == 0 || isExpanded.not() -> oldStyle
@@ -466,7 +466,8 @@ object SystemUIHooker : YukiBaseHooker() {
466466
if (it.third) return@also
467467
customIcon = it.first
468468
customIconColor = if (isUseMaterial3Style || isExpanded)
469-
(it.second.takeIf { e -> e != 0 } ?: (if (isUseMaterial3Style) context.systemAccentColor else 0)) else 0
469+
(it.second.takeIf { e -> e != 0 && ConfigData.isEnableNotifyIconForceSystemColor.not() }
470+
?: (if (isUseMaterial3Style) context.systemAccentColor else 0)) else 0
470471
}
471472
/** 打印日志 */
472473
loggerDebug(tag = "Notification Panel Icon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,32 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
209209
} else applyChangesAndRefresh()
210210
}
211211
}
212+
binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) {
213+
isAutoApplyChanges = false
214+
onChanged {
215+
/** 应用更改并刷新系统界面 */
216+
fun applyChangesAndRefresh() {
217+
applyChangesAndReinitialize()
218+
SystemUITool.refreshSystemUI(context = this@MainActivity)
219+
}
220+
if (it) showDialog {
221+
title = "破坏性功能警告"
222+
msg = "开启这个功能后,任何通知栏中的通知图标都会忽略图标自身的着色属性,全部使用系统默认颜色 (系统提供的统一色调) 着色。\n\n" +
223+
"此功能仅面向一些追求图标美观度的用户,我们不推荐开启这个功能,且发生任何 BUG 都不会去修复,仍然继续开启吗?"
224+
confirmButton { applyChangesAndRefresh() }
225+
cancelButton { cancelChanges() }
226+
noCancelable()
227+
} else applyChangesAndRefresh()
228+
}
229+
}
212230
binding.notifyIconForceAppIconSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) {
213231
isAutoApplyChanges = false
214-
onInitialize { binding.notifyIconCustomCornerItem.isVisible = isLowerAndroidR.not() && it.not() }
232+
onInitialize {
233+
arrayOf(
234+
binding.notifyIconCustomCornerItem,
235+
binding.notifyIconForceSystemColorItem
236+
).forEach { e -> e.isVisible = isLowerAndroidR.not() && it.not() }
237+
}
215238
onChanged {
216239
/** 应用更改并刷新系统界面 */
217240
fun applyChangesAndRefresh() {

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,34 @@
862862
android:textStyle="bold" />
863863
</LinearLayout>
864864

865+
<LinearLayout
866+
android:id="@+id/notify_icon_force_system_color_item"
867+
android:layout_width="match_parent"
868+
android:layout_height="wrap_content"
869+
android:orientation="vertical">
870+
871+
<com.fankes.miui.notify.ui.widget.MaterialSwitch
872+
android:id="@+id/notify_icon_force_system_color_switch"
873+
android:layout_width="match_parent"
874+
android:layout_height="wrap_content"
875+
android:paddingLeft="15dp"
876+
android:paddingRight="15dp"
877+
android:text="通知栏中的图标使用系统默认着色"
878+
android:textColor="@color/colorTextGray"
879+
android:textSize="15sp" />
880+
881+
<TextView
882+
android:layout_width="match_parent"
883+
android:layout_height="wrap_content"
884+
android:alpha="0.6"
885+
android:lineSpacingExtra="6dp"
886+
android:paddingLeft="15dp"
887+
android:paddingRight="15dp"
888+
android:text="此选项默认关闭,开启后下拉通知栏中的通知图标将忽略图标自身的着色属性,全部使用系统默认颜色 (系统提供的统一色调) 着色,这是一个破坏原生通知图标的行为,仅针对部分有需要的用户而添加,我们不推荐开启这个功能,请根据个人偏好进行选择是否需要开启。"
889+
android:textColor="@color/colorTextDark"
890+
android:textSize="12sp" />
891+
</LinearLayout>
892+
865893
<LinearLayout
866894
android:layout_width="match_parent"
867895
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)