Added notification icon force system color function

This commit is contained in:
2023-04-17 22:42:35 +08:00
parent 175263c9aa
commit be8f558bf5
4 changed files with 69 additions and 4 deletions

View File

@@ -60,6 +60,9 @@ object ConfigData {
/** 通知栏中的通知图标圆角程度 */
val NOTIFY_ICON_CORNER_SIZE = PrefsData("_notify_icon_corner", 15)
/** 强制通知栏中的通知图标使用系统着色 */
val ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR = PrefsData("_notify_icon_force_system_color", false)
/** 强制通知栏中的通知图标为 APP 图标 */
val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false)
@@ -257,6 +260,16 @@ object ConfigData {
putInt(NOTIFY_ICON_CORNER_SIZE, value)
}
/**
* 是否强制通知栏中的通知图标使用系统着色
* @return [Boolean]
*/
var isEnableNotifyIconForceSystemColor
get() = getBoolean(ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR)
set(value) {
putBoolean(ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR, value)
}
/**
* 是否强制通知栏中的通知图标为 APP 图标
* @return [Boolean]

View File

@@ -438,10 +438,10 @@ object SystemUIHooker : YukiBaseHooker() {
val iconColor = notifyInstance.notification.color
/** 是否有通知栏图标颜色 */
val hasIconColor = iconColor != 0
val hasIconColor = iconColor != 0 && ConfigData.isEnableNotifyIconForceSystemColor.not()
/** 通知图标适配颜色 */
val supportColor = iconColor.let {
val supportColor = (iconColor.takeIf { ConfigData.isEnableNotifyIconForceSystemColor.not() } ?: 0).let {
when {
isUseMaterial3Style -> newStyle
it == 0 || isExpanded.not() -> oldStyle
@@ -466,7 +466,8 @@ object SystemUIHooker : YukiBaseHooker() {
if (it.third) return@also
customIcon = it.first
customIconColor = if (isUseMaterial3Style || isExpanded)
(it.second.takeIf { e -> e != 0 } ?: (if (isUseMaterial3Style) context.systemAccentColor else 0)) else 0
(it.second.takeIf { e -> e != 0 && ConfigData.isEnableNotifyIconForceSystemColor.not() }
?: (if (isUseMaterial3Style) context.systemAccentColor else 0)) else 0
}
/** 打印日志 */
loggerDebug(tag = "Notification Panel Icon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)

View File

@@ -209,9 +209,32 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} else applyChangesAndRefresh()
}
}
binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) {
isAutoApplyChanges = false
onChanged {
/** 应用更改并刷新系统界面 */
fun applyChangesAndRefresh() {
applyChangesAndReinitialize()
SystemUITool.refreshSystemUI(context = this@MainActivity)
}
if (it) showDialog {
title = "破坏性功能警告"
msg = "开启这个功能后,任何通知栏中的通知图标都会忽略图标自身的着色属性,全部使用系统默认颜色 (系统提供的统一色调) 着色。\n\n" +
"此功能仅面向一些追求图标美观度的用户,我们不推荐开启这个功能,且发生任何 BUG 都不会去修复,仍然继续开启吗?"
confirmButton { applyChangesAndRefresh() }
cancelButton { cancelChanges() }
noCancelable()
} else applyChangesAndRefresh()
}
}
binding.notifyIconForceAppIconSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) {
isAutoApplyChanges = false
onInitialize { binding.notifyIconCustomCornerItem.isVisible = isLowerAndroidR.not() && it.not() }
onInitialize {
arrayOf(
binding.notifyIconCustomCornerItem,
binding.notifyIconForceSystemColorItem
).forEach { e -> e.isVisible = isLowerAndroidR.not() && it.not() }
}
onChanged {
/** 应用更改并刷新系统界面 */
fun applyChangesAndRefresh() {

View File

@@ -862,6 +862,34 @@
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/notify_icon_force_system_color_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.fankes.miui.notify.ui.widget.MaterialSwitch
android:id="@+id/notify_icon_force_system_color_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:layout_width="match_parent"
android:layout_height="wrap_content"