feat: add classic (MIUI) style notification icon replacement

This commit is contained in:
2023-11-03 12:18:18 +08:00
parent 8f01e649fe
commit 1f71fbda9a
4 changed files with 64 additions and 21 deletions

View File

@@ -60,6 +60,9 @@ object ConfigData {
/** 通知栏中的通知图标圆角程度 */ /** 通知栏中的通知图标圆角程度 */
val NOTIFY_ICON_CORNER_SIZE = PrefsData("_notify_icon_corner", 15) val NOTIFY_ICON_CORNER_SIZE = PrefsData("_notify_icon_corner", 15)
/** 替换 MIUI 样式通知栏的通知图标 */
val ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON = PrefsData("_replace_miui_style_notify_icon", true)
/** 强制通知栏中的通知图标使用系统着色 */ /** 强制通知栏中的通知图标使用系统着色 */
val ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR = PrefsData("_notify_icon_force_system_color", false) val ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR = PrefsData("_notify_icon_force_system_color", false)
@@ -260,6 +263,16 @@ object ConfigData {
putInt(NOTIFY_ICON_CORNER_SIZE, value) putInt(NOTIFY_ICON_CORNER_SIZE, value)
} }
/**
* 是否替换 MIUI 样式通知栏的通知图标
* @return [Boolean]
*/
var isEnableReplaceMiuiStyleNotifyIcon
get() = getBoolean(ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON)
set(value) {
putBoolean(ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON, value)
}
/** /**
* 是否强制通知栏中的通知图标使用系统着色 * 是否强制通知栏中的通知图标使用系统着色
* @return [Boolean] * @return [Boolean]

View File

@@ -269,6 +269,13 @@ object SystemUIHooker : YukiBaseHooker() {
return xmsfPkg.ifBlank { targetPkg.ifBlank { packageName } } return xmsfPkg.ifBlank { targetPkg.ifBlank { packageName } }
} }
/**
* 获取 MIUI 自己设置的通知图标
* @return [Icon] or null
*/
@Suppress("DEPRECATION")
private val StatusBarNotification.miuiAppIcon get() = notification?.extras?.getParcelable<Icon?>("miui.appIcon")
/** /**
* 打印日志 * 打印日志
* @param tag 标识 * @param tag 标识
@@ -528,11 +535,8 @@ object SystemUIHooker : YukiBaseHooker() {
loggerDebug(tag = "Notification Panel Icon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon) loggerDebug(tag = "Notification Panel Icon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)
/** 处理自定义通知图标优化 */ /** 处理自定义通知图标优化 */
when { when {
ConfigData.isEnableNotifyIconForceAppIcon -> { ConfigData.isEnableNotifyIconForceAppIcon ->
@Suppress("DEPRECATION") setDefaultNotifyIcon(drawable = notifyInstance.miuiAppIcon?.loadDrawable(context) ?: context.appIconOf(notifyInstance.nfPkgName))
val miuiAppIcon = notifyInstance.notification?.extras?.getParcelable<Icon?>("miui.appIcon")
setDefaultNotifyIcon(drawable = miuiAppIcon?.loadDrawable(context) ?: context.appIconOf(notifyInstance.nfPkgName))
}
customIcon != null -> iconView.apply { customIcon != null -> iconView.apply {
/** 设置不要裁切到边界 */ /** 设置不要裁切到边界 */
clipToOutline = false clipToOutline = false
@@ -982,14 +986,11 @@ object SystemUIHooker : YukiBaseHooker() {
/** 修改 MIUI 风格通知栏的通知图标 */ /** 修改 MIUI 风格通知栏的通知图标 */
MiuiNotificationViewWrapperClass?.apply { MiuiNotificationViewWrapperClass?.apply {
constructor().hook().after { constructor().hook().after {
val nf = instance.getRowPair().second.getSbn() ?: return@after
field { name = "mAppIcon" }.get(instance).cast<ImageView>()?.clone { field { name = "mAppIcon" }.get(instance).cast<ImageView>()?.clone {
compatNotifyIcon( if (ConfigData.isEnableReplaceMiuiStyleNotifyIcon || ConfigData.isEnableNotifyIconForceAppIcon)
context = context, compatNotifyIcon(context, nf, iconView = this, isUseMaterial3Style = true, isMiuiPanel = true)
nf = instance.getRowPair().second.getSbn(), else setImageDrawable(nf.miuiAppIcon?.loadDrawable(context) ?: context.appIconOf(nf.packageName))
iconView = this,
isUseMaterial3Style = true,
isMiuiPanel = true
)
} }
} }
} }
@@ -1001,15 +1002,12 @@ object SystemUIHooker : YukiBaseHooker() {
param(BooleanType) param(BooleanType)
}.hook().after { }.hook().after {
field { name = "mAppIcon" }.get(instance).cast<ImageView>()?.apply { field { name = "mAppIcon" }.get(instance).cast<ImageView>()?.apply {
compatNotifyIcon( val nf = NotificationChildrenContainerClass.field {
context = context, name = "mContainingNotification"
nf = NotificationChildrenContainerClass.field { }.get(instance).any()?.getSbn() ?: return@after
name = "mContainingNotification" if (ConfigData.isEnableReplaceMiuiStyleNotifyIcon || ConfigData.isEnableNotifyIconForceAppIcon)
}.get(instance).any()?.getSbn(), compatNotifyIcon(context, nf, iconView = this, isUseMaterial3Style = true, isMiuiPanel = true)
iconView = this, else setImageDrawable(nf.miuiAppIcon?.loadDrawable(context) ?: context.appIconOf(nf.packageName))
isUseMaterial3Style = true,
isMiuiPanel = true
)
} }
} }
} }

View File

@@ -238,6 +238,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} else applyChangesAndRefresh() } else applyChangesAndRefresh()
} }
} }
binding.miuiNotifyIconReplacementSwitch.bind(ConfigData.ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON) {
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
}
binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) { binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) {
isAutoApplyChanges = false isAutoApplyChanges = false
onChanged { onChanged {
@@ -263,6 +266,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.notifyIconCustomCornerItem, binding.notifyIconCustomCornerItem,
binding.notifyIconForceSystemColorItem binding.notifyIconForceSystemColorItem
).forEach { e -> e.isVisible = isLowerAndroidR.not() && it.not() } ).forEach { e -> e.isVisible = isLowerAndroidR.not() && it.not() }
binding.miuiNotifyIconReplacementItem.isVisible = it.not()
} }
onChanged { onChanged {
/** 应用更改并刷新系统界面 */ /** 应用更改并刷新系统界面 */

View File

@@ -883,6 +883,34 @@
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/miui_notify_icon_replacement_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_notify_icon_replacement_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="此选项默认开启,开启后经典 (MIUI) 样式的下拉通知栏中的通知图标将同样应用替换后的通知图标,否则将保持系统自己设置的图标。(此功能无法对所有系统版本兼容)"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/notify_icon_force_system_color_item" android:id="@+id/notify_icon_force_system_color_item"
android:layout_width="match_parent" android:layout_width="match_parent"