Added notification icon force system color function

This commit is contained in:
2023-04-17 22:42:55 +08:00
parent 1d5759313b
commit 3503cf35b1
4 changed files with 73 additions and 3 deletions

View File

@@ -61,6 +61,9 @@ object ConfigData {
/** 通知栏中的通知图标圆角程度 */ /** 通知栏中的通知图标圆角程度 */
val NOTIFY_ICON_CORNER_SIZE = PrefsData("_notify_icon_corner", 15) 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 图标 */ /** 强制通知栏中的通知图标为 APP 图标 */
val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false) val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false)
@@ -264,6 +267,16 @@ object ConfigData {
putInt(NOTIFY_ICON_CORNER_SIZE, value) 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 图标 * 是否强制通知栏中的通知图标为 APP 图标
* @return [Boolean] * @return [Boolean]

View File

@@ -439,11 +439,17 @@ object SystemUIHooker : YukiBaseHooker() {
val md3Style = if (isUpperOfAndroidS) context.systemAccentColor else val md3Style = if (isUpperOfAndroidS) context.systemAccentColor else
(if (context.isSystemInDarkMode) 0xFF707173.toInt() else oldStyle) (if (context.isSystemInDarkMode) 0xFF707173.toInt() else oldStyle)
/** 原生通知图标颜色 */
val nativeIconColor = if (ConfigData.isEnableNotifyIconForceSystemColor) 0 else iconColor
/** 自定义通知图标颜色 */
val customIconColor = if (ConfigData.isEnableNotifyIconForceSystemColor) 0 else customTriple.second
/** 旧版图标着色 */ /** 旧版图标着色 */
val oldApplyColor = customTriple.second.takeIf { it != 0 } ?: iconColor.takeIf { it != 0 } ?: oldStyle val oldApplyColor = customIconColor.takeIf { it != 0 } ?: nativeIconColor.takeIf { it != 0 } ?: oldStyle
/** 新版图标着色 */ /** 新版图标着色 */
val newApplyColor = customTriple.second.takeIf { it != 0 } ?: iconColor.takeIf { it != 0 } ?: md3Style val newApplyColor = customIconColor.takeIf { it != 0 } ?: nativeIconColor.takeIf { it != 0 } ?: md3Style
/** 判断风格并开始 Hook */ /** 判断风格并开始 Hook */
if (ConfigData.isEnableMd3NotifyIconStyle) { if (ConfigData.isEnableMd3NotifyIconStyle) {

View File

@@ -183,9 +183,30 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
SystemUITool.refreshSystemUI(context = this@MainActivity) SystemUITool.refreshSystemUI(context = this@MainActivity)
} }
} }
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) { binding.notifyIconForceAppIconSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) {
isAutoApplyChanges = false isAutoApplyChanges = false
onInitialize { binding.notifyIconCustomCornerItem.isVisible = it.not() && ConfigData.isEnableMd3NotifyIconStyle } onInitialize {
binding.notifyIconForceSystemColorItem.isVisible = it.not()
binding.notifyIconCustomCornerItem.isVisible = it.not() && ConfigData.isEnableMd3NotifyIconStyle
}
onChanged { onChanged {
/** 应用更改并刷新系统界面 */ /** 应用更改并刷新系统界面 */
fun applyChangesAndRefresh() { fun applyChangesAndRefresh() {

View File

@@ -614,6 +614,36 @@
android:textSize="12sp" /> android:textSize="12sp" />
</LinearLayout> </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.coloros.notify.ui.widget.MaterialSwitch
android:id="@+id/notify_icon_force_system_color_switch"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginBottom="5dp"
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:layout_marginBottom="10dp"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="此选项默认关闭,开启后下拉通知栏中的通知图标将忽略图标自身的着色属性,全部使用系统默认颜色 (系统提供的统一色调) 着色,这是一个破坏原生通知图标的行为,仅针对部分有需要的用户而添加,我们不推荐开启这个功能,请根据个人偏好进行选择是否需要开启。"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"