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)
/** 替换 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)
@@ -260,6 +263,16 @@ object ConfigData {
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]

View File

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

View File

@@ -238,6 +238,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} 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) {
isAutoApplyChanges = false
onChanged {
@@ -263,6 +266,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.notifyIconCustomCornerItem,
binding.notifyIconForceSystemColorItem
).forEach { e -> e.isVisible = isLowerAndroidR.not() && it.not() }
binding.miuiNotifyIconReplacementItem.isVisible = it.not()
}
onChanged {
/** 应用更改并刷新系统界面 */

View File

@@ -883,6 +883,34 @@
android:textStyle="bold" />
</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
android:id="@+id/notify_icon_force_system_color_item"
android:layout_width="match_parent"