增加状态栏通知图标动态更新,取消对新的开发版修复通知图标只有一个的问题

This commit is contained in:
2022-03-23 02:49:19 +08:00
parent cf80becf4e
commit ca27c17c46
11 changed files with 223 additions and 151 deletions

2
.idea/misc.xml generated
View File

@@ -12,6 +12,8 @@
<entry key="app/src/main/res/drawable/bg_orange_round.xml" value="0.2325" />
<entry key="app/src/main/res/drawable/bg_warn_round.xml" value="0.2325" />
<entry key="app/src/main/res/drawable/bg_yellow_round.xml" value="0.255" />
<entry key="app/src/main/res/drawable/ic_nf_icon_refresh.xml" value="0.2325" />
<entry key="app/src/main/res/drawable/ic_nf_icon_update.xml" value="0.2325" />
<entry key="app/src/main/res/drawable/permotion_round.xml" value="0.256" />
<entry key="app/src/main/res/drawable/white_round.xml" value="0.256" />
<entry key="app/src/main/res/layout-w1240dp/dia_source_from.xml" value="0.36484375" />

View File

@@ -29,7 +29,6 @@ object HookConst {
const val ENABLE_MODULE = "_enable_module"
const val ENABLE_MODULE_LOG = "_enable_module_log"
const val ENABLE_HIDE_ICON = "_hide_icon"
const val ENABLE_COLOR_ICON_HOOK = "_color_icon_hook"
const val ENABLE_COLOR_ICON_COMPAT = "_color_icon_compat"
const val ENABLE_NOTIFY_ICON_FIX = "_notify_icon_fix"
const val ENABLE_NOTIFY_ICON_FIX_NOTIFY = "_notify_icon_fix_notify"

View File

@@ -28,6 +28,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.Outline
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.Icon
import android.os.Build
@@ -40,7 +41,6 @@ import androidx.core.graphics.drawable.toBitmap
import com.fankes.miui.notify.application.MNNApplication.Companion.MODULE_PACKAGE_NAME
import com.fankes.miui.notify.bean.IconDataBean
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_COMPAT
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_HOOK
import com.fankes.miui.notify.hook.HookConst.ENABLE_HOOK_STATUS_ICON_COUNT
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE_LOG
@@ -62,10 +62,7 @@ import com.highcapable.yukihookapi.hook.factory.*
import com.highcapable.yukihookapi.hook.log.loggerD
import com.highcapable.yukihookapi.hook.log.loggerW
import com.highcapable.yukihookapi.hook.param.PackageParam
import com.highcapable.yukihookapi.hook.type.android.ContextClass
import com.highcapable.yukihookapi.hook.type.android.DrawableClass
import com.highcapable.yukihookapi.hook.type.android.ImageViewClass
import com.highcapable.yukihookapi.hook.type.android.IntentClass
import com.highcapable.yukihookapi.hook.type.android.*
import com.highcapable.yukihookapi.hook.type.java.BooleanType
import com.highcapable.yukihookapi.hook.type.java.IntType
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
@@ -82,9 +79,6 @@ class HookEntry : YukiHookXposedInitProxy {
private const val NotificationHeaderViewWrapperInjectorClass =
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapperInjector"
/** MIUI 大部分版本存在的类 */
private const val MiuiClockClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.views.MiuiClock"
/** 原生存在的类 */
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
@@ -97,6 +91,12 @@ class HookEntry : YukiHookXposedInitProxy {
/** 原生存在的类 */
private const val PluginManagerImplClass = "$SYSTEMUI_PACKAGE_NAME.shared.plugins.PluginManagerImpl"
/** 根据多个版本存在不同的包名相同的类 */
private val MiuiClockClass = VariousClass(
"$SYSTEMUI_PACKAGE_NAME.statusbar.views.MiuiClock",
"$SYSTEMUI_PACKAGE_NAME.statusbar.policy.MiuiClock"
)
/** 根据多个版本存在不同的包名相同的类 */
private val ExpandableNotificationRowClass = VariousClass(
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.ExpandableNotificationRow",
@@ -134,14 +134,19 @@ class HookEntry : YukiHookXposedInitProxy {
/** 是否显示通知图标 - 跟随 Hook 保存 */
private var isShowNotificationIcons = true
/** 缓存的状态栏小图标实例 */
private var statusBarIconViews = HashSet<ImageView>()
/** 缓存的通知小图标包装纸实例 */
private var notificationViewWrappers = HashSet<Any>()
/**
* 是否启用忽略彩色图标和启用通知图标优化功能
* @param isHooking 是否判断启用通知功能 - 默认:是
* @return [Boolean]
*/
private fun PackageParam.isEnableHookColorNotifyIcon(isHooking: Boolean = true) =
prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true) &&
prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) &&
prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) &&
(if (isHooking) prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true) else true)
/**
@@ -286,6 +291,29 @@ class HookEntry : YukiHookXposedInitProxy {
SystemUIApplicationClass.clazz.method { name = "getContext" }.ignoredError().get().invoke<Context>()
}
/** 刷新状态栏小图标 */
private fun PackageParam.refreshStatusBarIcons() = runInSafe {
StatusBarIconViewClass.clazz.field { name = "mNotification" }.also { result ->
statusBarIconViews.takeIf { it.isNotEmpty() }?.forEach {
/** 得到通知实例 */
val nf = result.of<StatusBarNotification>(it) ?: return
/** 刷新状态栏图标 */
compatStatusIcon(it.context, nf, nf.notification.smallIcon.loadDrawable(it.context)) { icon, _ ->
it.setImageDrawable(icon)
}
}
}
}
/** 刷新通知小图标 */
private fun PackageParam.refreshNotificationIcons() = runInSafe {
(if (hasHandleHeaderViews)
NotificationHeaderViewWrapperClass.clazz.method { name = "handleHeaderViews" }
else NotificationHeaderViewWrapperClass.clazz.method { name = "resolveHeaderViews" }).also { result ->
notificationViewWrappers.takeIf { it.isNotEmpty() }?.forEach { result.get(it).call() }
}
}
/**
* 自动适配状态栏、通知栏自定义小图标
* @param isGrayscaleIcon 是否为灰度图标
@@ -294,17 +322,16 @@ class HookEntry : YukiHookXposedInitProxy {
*/
private fun PackageParam.compatCustomIcon(isGrayscaleIcon: Boolean, packageName: String): Pair<Bitmap?, Int> {
var customPair: Pair<Bitmap?, Int>? = null
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true))
run {
if (iconDatas.isNotEmpty())
iconDatas.forEach {
if (packageName == it.packageName && isAppNotifyHookOf(it)) {
if (!isGrayscaleIcon || isAppNotifyHookAllOf(it))
customPair = Pair(it.iconBitmap, it.iconColor)
return@run
}
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)) run {
if (iconDatas.isNotEmpty())
iconDatas.forEach {
if (packageName == it.packageName && isAppNotifyHookOf(it)) {
if (!isGrayscaleIcon || isAppNotifyHookAllOf(it))
customPair = Pair(it.iconBitmap, it.iconColor)
return@run
}
}
}
}
return customPair ?: Pair(null, 0)
}
@@ -315,22 +342,20 @@ class HookEntry : YukiHookXposedInitProxy {
* @param context 实例
* @param expandedNf 通知实例
* @param iconDrawable 小图标 [Drawable]
* @param it 回调小图标 - ([Bitmap] 小图标)
* @param it 回调小图标 - ([Drawable] 小图标,[Boolean] 是否替换)
*/
private fun PackageParam.hookSmallIconOnSet(
private fun PackageParam.compatStatusIcon(
context: Context,
expandedNf: StatusBarNotification?,
iconDrawable: Drawable?,
it: (Bitmap) -> Unit
) = runInSafe(msg = "GetSmallIconOnSet") {
it: (Drawable, Boolean) -> Unit
) = runInSafe(msg = "compatStatusIcon") {
if (iconDrawable == null) return@runInSafe
/** 如果没开启修复 APP 的彩色图标 */
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@runInSafe
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.also { notifyInstance ->
/** 判断是 MIUI 样式就停止 Hook */
if (context.isMiuiNotifyStyle) {
it(notifyInstance.findAppIcon(context).toBitmap())
it(notifyInstance.findAppIcon(context), true)
return@runInSafe
}
/** 判断是否不是灰度图标 */
@@ -342,9 +367,11 @@ class HookEntry : YukiHookXposedInitProxy {
printLogcat(tag = "StatusIcon", context, notifyInstance, isCustom = customIcon != null, !isNotGrayscaleIcon)
when {
/** 处理自定义通知图标优化 */
customIcon != null -> it(customIcon)
customIcon != null -> it(BitmapDrawable(context.resources, customIcon), true)
/** 若不是灰度图标自动处理为圆角 */
isNotGrayscaleIcon -> it(notifyInstance.compatNotifyIcon(context, iconDrawable).toBitmap())
isNotGrayscaleIcon -> it(notifyInstance.compatNotifyIcon(context, iconDrawable), true)
/** 否则返回原始小图标 */
else -> it(notifyInstance.notification.smallIcon.loadDrawable(context), false)
}
}
}
@@ -356,18 +383,18 @@ class HookEntry : YukiHookXposedInitProxy {
* @param context 实例
* @param expandedNf 通知实例
* @param iconImageView 通知图标实例
* @param origColor 通知图标系统默认颜色 - Android >= 12
* @param isExpanded 通知是否展开 - 可做最小化通知处理
*/
private fun PackageParam.hookNotifyIconOnSet(
private fun PackageParam.compatNotifyIcon(
context: Context,
expandedNf: StatusBarNotification?,
iconImageView: ImageView,
origColor: Int,
isExpanded: Boolean
) = runInSafe(msg = "AutoSetAppIconOnSet") {
) = runInSafe(msg = "compatNotifyIcon") {
/** 判断是 MIUI 样式就停止 Hook */
if (context.isMiuiNotifyStyle) return@runInSafe
/** 如果没开启修复 APP 的彩色图标 */
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@runInSafe
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
@@ -410,26 +437,32 @@ class HookEntry : YukiHookXposedInitProxy {
/** 打印日志 */
printLogcat(tag = "NotifyIcon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)
/** 处理自定义通知图标优化 */
if (customIcon != null)
iconImageView.apply {
/** 设置自定义小图标 */
setImageBitmap(customIcon)
/** 上色 */
setColorFilter(if (isUpperOfAndroidS || customIconColor == 0) supportColor else customIconColor)
/** Android 12 设置图标外圈颜色 */
if (isUpperOfAndroidS && customIconColor != 0)
background = DrawableBuilder().rounded().solidColor(customIconColor).build()
}
else {
if (customIcon != null) iconImageView.apply {
/** 设置不要裁切到边界 */
clipToOutline = false
/** 设置自定义小图标 */
setImageBitmap(customIcon)
/** 上色 */
setColorFilter(if (isUpperOfAndroidS || customIconColor == 0) supportColor else customIconColor)
/** Android 12 设置图标外圈颜色 */
if (isUpperOfAndroidS && customIconColor != 0)
background = DrawableBuilder().rounded().solidColor(customIconColor).build()
/** 设置原生的背景边距 */
if (isUpperOfAndroidS) setPadding(4.dp(context), 4.dp(context), 4.dp(context), 4.dp(context))
} else {
/** 重新设置图标 - 防止系统更改它 */
iconImageView.setImageDrawable(iconDrawable)
/** 判断如果是灰度图标就给他设置一个白色颜色遮罩 */
if (isGrayscaleIcon) iconImageView.apply {
/** 设置不要裁切到边界 */
clipToOutline = false
/** 设置图标着色 */
setColorFilter(supportColor)
/** Android 12 设置图标外圈颜色 */
if (isUpperOfAndroidS && hasIconColor)
background = DrawableBuilder().rounded().solidColor(iconColor).build()
if (isUpperOfAndroidS) background =
DrawableBuilder().rounded().solidColor(if (hasIconColor) iconColor else origColor).build()
/** 设置原生的背景边距 */
if (isUpperOfAndroidS) setPadding(4.dp(context), 4.dp(context), 4.dp(context), 4.dp(context))
} else iconImageView.apply {
/** 重新设置图标 */
setImageDrawable(notifyInstance.compatNotifyIcon(context, iconDrawable))
@@ -444,10 +477,14 @@ class HookEntry : YukiHookXposedInitProxy {
)
}
}
/** 清除原生的背景边距设置 */
if (isUpperOfAndroidS) setPadding(0, 0, 0, 0)
/** 清除原生的主题色背景圆圈颜色 */
if (isUpperOfAndroidS) background = null
if (isUpperOfAndroidS) {
/** 清除原生的背景边距 */
setPadding(0, 0, 0, 0)
/** 清除原生的主题色背景圆圈颜色 */
background = null
}
/** 清除遮罩颜色 */
colorFilter = null
}
}
}
@@ -462,28 +499,26 @@ class HookEntry : YukiHookXposedInitProxy {
* @return [Boolean] 是否忽略通知图标颜色
*/
private fun PackageParam.hasIgnoreStatusBarIconColor(context: Context, expandedNf: StatusBarNotification?) =
if (!context.isMiuiNotifyStyle)
if (prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) safeOfFalse {
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
/** 获取通知小图标 */
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
if (!context.isMiuiNotifyStyle) safeOfFalse {
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
/** 获取通知小图标 */
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
/** 判断是否不是灰度图标 */
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
/** 判断是否不是灰度图标 */
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
/** 获取目标修复彩色图标的 APP */
val isTargetFixApp = compatCustomIcon(!isNotGrayscaleIcon, notifyInstance.opPkgName).first != null
/**
* 只要不是灰度就返回彩色图标
* 否则不对颜色进行反色处理防止一些系统图标出现异常
*/
(if (isTargetFixApp) false else isNotGrayscaleIcon).also {
printLogcat(tag = "IconColor", context, expandedNf, isTargetFixApp, !isNotGrayscaleIcon)
}
} ?: true.also { printLogcat(tag = "IconColor", context, expandedNf = null, isCustom = false, isGrayscale = false) }
} else false.also { printLogcat(tag = "IconColor", context, expandedNf, isCustom = false, isGrayscale = true) }
else true.also { printLogcat(tag = "IconColor", context, expandedNf, isCustom = false, isGrayscale = false) }
/** 获取目标修复彩色图标的 APP */
val isTargetFixApp = compatCustomIcon(!isNotGrayscaleIcon, notifyInstance.opPkgName).first != null
/**
* 只要不是灰度就返回彩色图标
* 否则不对颜色进行反色处理防止一些系统图标出现异常
*/
(if (isTargetFixApp) false else isNotGrayscaleIcon).also {
printLogcat(tag = "IconColor", context, expandedNf, isTargetFixApp, !isNotGrayscaleIcon)
}
} ?: true.also { printLogcat(tag = "IconColor", context, expandedNf = null, isCustom = false, isGrayscale = false) }
} else true.also { printLogcat(tag = "IconColor", context, expandedNf, isCustom = false, isGrayscale = false) }
/** 缓存图标数据 */
private fun PackageParam.cachingIconDatas() {
@@ -496,6 +531,14 @@ class HookEntry : YukiHookXposedInitProxy {
}
}
/** 刷新缓存数据 */
private fun PackageParam.recachingPrefs() {
prefs.clearCache()
cachingIconDatas()
refreshStatusBarIcons()
refreshNotificationIcons()
}
override fun onInit() = configs {
debugTag = "MIUINativeNotifyIcon"
isDebug = false
@@ -550,15 +593,15 @@ class HookEntry : YukiHookXposedInitProxy {
(globalContext ?: firstArgs as Context).also { context ->
val expandedNf = args[if (isUseLegacy) 1 else 0] as? StatusBarNotification?
/** Hook 状态栏小图标 */
hookSmallIconOnSet(
compatStatusIcon(
context = context,
expandedNf,
(result as Icon).loadDrawable(context)
) { icon -> result = Icon.createWithBitmap(icon) }
/** 刷新图标缓存 */
) { icon, isReplace -> if (isReplace) result = Icon.createWithBitmap(icon.toBitmap()) }
/** 刷新缓存 */
if (expandedNf?.compatOpPkgName == MODULE_PACKAGE_NAME &&
expandedNf.notification?.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
) cachingIconDatas()
) recachingPrefs()
}
}
}
@@ -594,13 +637,29 @@ class HookEntry : YukiHookXposedInitProxy {
}
}
}
/** 记录实例 */
injectMember {
method {
name = "setNotification"
param(StatusBarNotificationClass)
}.remedys {
method {
name = "setNotification"
param(ExpandedNotificationClass.clazz)
}
}
afterHook { if (firstArgs != null) statusBarIconViews.add(instance()) }
}
}
NotificationIconContainerClass.hook {
injectMember {
method { name = "calculateIconTranslations" }
afterHook {
/** 修复最新开发版状态栏图标只能显示一个的问题 */
instance<ViewGroup>().layoutParams.width = 9999
/** 修复部分开发版状态栏图标只能显示一个的问题 */
when (miuiIncrementalVersion.lowercase()) {
"22.3.14", "22.3.15", "22.3.16", "v13.0.1.1.16.dev", "22.3.18" ->
instance<ViewGroup>().layoutParams.width = 9999
}
}
}
injectMember {
@@ -637,6 +696,12 @@ class HookEntry : YukiHookXposedInitProxy {
method { name = "handleHeaderViews" }
else method { name = "resolveHeaderViews" }
afterHook {
/** 获取通知图标系统默认颜色 */
val origColor =
NotificationHeaderViewWrapperClass.clazz.method { name = "getOriginalIconColor" }
.ignoredError()
.get(instance).invoke<Int>() ?: 0
/** 获取小图标 */
val iconImageView =
NotificationHeaderViewWrapperClass.clazz
@@ -674,13 +739,14 @@ class HookEntry : YukiHookXposedInitProxy {
/** 非最小化优先级的通知全部设置为展开状态 */
if (importance != 1) isExpanded = true
/** 执行 Hook */
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView, isExpanded)
/** 刷新图标缓存 */
if (expandedNf?.compatOpPkgName == MODULE_PACKAGE_NAME &&
expandedNf.notification?.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
) cachingIconDatas()
compatNotifyIcon(iconImageView.context, expandedNf, iconImageView, origColor, isExpanded)
}
}
/** 记录实例 */
injectMember {
constructor { param(ContextClass, ViewClass, ExpandableNotificationRowClass.clazz) }
afterHook { notificationViewWrappers.add(instance) }
}
}
/** 干掉下拉通知图标自动设置回 APP 图标的方法 */
NotificationHeaderViewWrapperInjectorClass.hook {

View File

@@ -149,13 +149,13 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
if (!btn.isPressed) return@setOnCheckedChangeListener
putAppNotifyHookOf(it, b)
holder.adpAppAllSwitch.isEnabled = b
SystemUITool.showNeedRestartSnake(context = this@ConfigureActivity)
SystemUITool.refreshSystemUI(context = this@ConfigureActivity)
}
holder.adpAppAllSwitch.isChecked = isAppNotifyHookAllOf(it)
holder.adpAppAllSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
putAppNotifyHookAllOf(it, b)
SystemUITool.showNeedRestartSnake(context = this@ConfigureActivity)
SystemUITool.refreshSystemUI(context = this@ConfigureActivity)
}
}
return cView!!
@@ -182,14 +182,6 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
mockLocalData()
/** 更新数据 */
when {
intent?.getBooleanExtra("isShowNeedRestart", false) == true ->
showDialog {
title = "规则列表已同步至最新"
msg = "同步完成,部分通知图标可能需要重新启动系统界面才能生效。"
confirmButton(text = "重新启动") { SystemUITool.restartSystemUI(context) }
cancelButton()
noCancelable()
}
intent?.getBooleanExtra("isNewAppSupport", false) == true ->
showDialog {
val appName = intent?.getStringExtra("appName") ?: ""
@@ -209,7 +201,6 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
}
/** 清除数据 */
intent?.apply {
removeExtra("isShowNeedRestart")
removeExtra("isNewAppSupport")
removeExtra("isShowUpdDialog")
}

View File

@@ -36,7 +36,6 @@ import com.fankes.miui.notify.R
import com.fankes.miui.notify.databinding.ActivityMainBinding
import com.fankes.miui.notify.databinding.DiaStatusIconCountBinding
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_COMPAT
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_HOOK
import com.fankes.miui.notify.hook.HookConst.ENABLE_HIDE_ICON
import com.fankes.miui.notify.hook.HookConst.ENABLE_HOOK_STATUS_ICON_COUNT
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE
@@ -151,10 +150,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
var statusBarIconCount = modulePrefs.getInt(HOOK_STATUS_ICON_COUNT, default = 5)
binding.colorIconHookItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
binding.statusIconCountItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
binding.colorIconCompatSwitch.isVisible = modulePrefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)
binding.colorIconCompatText.isVisible = modulePrefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)
binding.notifyIconConfigItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true) &&
modulePrefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)
binding.notifyIconConfigItem.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
binding.notifyIconFixButton.isVisible = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
binding.notifyIconFixNotifyItem.isVisible = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
binding.statusIconCountSwitch.isChecked = modulePrefs.getBoolean(ENABLE_HOOK_STATUS_ICON_COUNT, default = true)
@@ -162,7 +158,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.moduleEnableSwitch.isChecked = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
binding.moduleEnableLogSwitch.isChecked = modulePrefs.getBoolean(ENABLE_MODULE_LOG)
binding.hideIconInLauncherSwitch.isChecked = modulePrefs.getBoolean(ENABLE_HIDE_ICON)
binding.colorIconHookSwitch.isChecked = modulePrefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)
binding.colorIconCompatSwitch.isChecked = modulePrefs.getBoolean(ENABLE_COLOR_ICON_COMPAT)
binding.notifyIconFixSwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true)
@@ -173,7 +168,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.moduleEnableLogSwitch.isVisible = b
binding.colorIconHookItem.isVisible = b
binding.statusIconCountItem.isVisible = b
binding.notifyIconConfigItem.isVisible = b && binding.colorIconHookSwitch.isChecked
binding.notifyIconConfigItem.isVisible = b
SystemUITool.showNeedRestartSnake(context = this)
}
binding.moduleEnableLogSwitch.setOnCheckedChangeListener { btn, b ->
@@ -196,30 +191,22 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.statusIconCountChildItem.isVisible = b
SystemUITool.showNeedRestartSnake(context = this)
}
binding.colorIconHookSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_COLOR_ICON_HOOK, b)
binding.notifyIconConfigItem.isVisible = b
binding.colorIconCompatSwitch.isVisible = b
binding.colorIconCompatText.isVisible = b
SystemUITool.showNeedRestartSnake(context = this)
}
binding.colorIconCompatSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_COLOR_ICON_COMPAT, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.notifyIconFixSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX, b)
binding.notifyIconFixButton.isVisible = b
binding.notifyIconFixNotifyItem.isVisible = b
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
binding.notifyIconFixNotifySwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, b)
SystemUITool.showNeedRestartSnake(context = this)
SystemUITool.refreshSystemUI(context = this)
}
/** 通知图标优化名单按钮点击事件 */
binding.notifyIconFixButton.setOnClickListener { navigate<ConfigureActivity>() }

View File

@@ -152,12 +152,18 @@ val miuiVersion
*/
val miuiVersionCode get() = safeOf(default = 0f) { miuiVersion.toFloat() }
/**
* 获取 MIUI 次版本号
* @return [String]
*/
val miuiIncrementalVersion get() = findPropString(key = "ro.system.build.version.incremental").trim()
/**
* 获取 MIUI 完全版本
* @return [String]
*/
val miuiFullVersion
get() = if (isMIUI) findPropString(key = "ro.system.build.version.incremental").let {
get() = if (isMIUI) miuiIncrementalVersion.let {
if (it.lowercase().contains("a") ||
it.lowercase().contains("b") ||
it.lowercase().contains("c") ||

View File

@@ -141,7 +141,7 @@ object IconRuleManagerTool {
dataJson2 = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]"
)
)
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> context.snake(msg = "请输入有效内容")
@@ -154,7 +154,7 @@ object IconRuleManagerTool {
jsonString.isNotBlank() && params.isNotVaildJson(jsonString) -> context.snake(msg = "不是有效的 JSON 数据")
jsonString.isNotBlank() -> {
params.save(dataJson = jsonString.takeIf { params.isJsonArray(it) } ?: "[$jsonString]")
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> context.snake(msg = "请输入有效内容")
@@ -218,7 +218,7 @@ object IconRuleManagerTool {
params.isCompareDifferent(it) -> {
params.save(it)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
@@ -267,7 +267,7 @@ object IconRuleManagerTool {
params.isCompareDifferent(content) -> {
params.save(content)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
pushWithRefresh(context)
pushAndNotifyRefresh(context)
it()
}
else -> (if (context is AppCompatActivity) context.snake(msg = "列表数据已是最新"))
@@ -360,16 +360,35 @@ object IconRuleManagerTool {
})
}.onFailure { it(false, "URL 无效") }
/**
* 刷新系统界面状态栏与通知图标
* @param context 实例
*/
fun refreshSystemUI(context: Context) {
if (context !is AppCompatActivity) return
context.showDialog {
title = "请稍后"
progressContent = "正在刷新系统界面改变"
/** 发送通知提醒宿主更新图标缓存 */
pushNotify(appContext, title = "请稍后", msg = "正在等待系统界面响应", isAction = false)
/** 刷新成功后取消通知 */
Handler().postDelayed({
context.getSystemService<NotificationManager>()?.cancel(1)
cancel()
}, 500)
noCancelable()
}
}
/**
* 推送通知图标更新通知
* @param context 实例
*/
private fun pushWithRefresh(context: Context) {
private fun pushAndNotifyRefresh(context: Context) {
if (context !is AppCompatActivity) return
SystemUITool.showNeedUpdateApplySnake(context)
pushNotify(appContext, title = "更新完成", msg = "部分通知图标需要重启系统界面生效", isAction = false)
/** 刷新成功后取消通知 */
Handler().postDelayed({ context.getSystemService<NotificationManager>()?.cancel(1) }, 1500)
/** 刷新改变 */
refreshSystemUI(context)
}
/**
@@ -404,16 +423,14 @@ object IconRuleManagerTool {
setContentText(msg)
color = OS_COLOR.toInt()
setAutoCancel(true)
setSmallIcon(R.drawable.ic_nf_icon_update)
setSmallIcon(if (isAction) R.drawable.ic_nf_icon_update else R.drawable.ic_nf_icon_refresh)
setSound(null)
setDefaults(NotificationCompat.DEFAULT_ALL)
if (isAction) setContentIntent(
PendingIntent.getActivity(
context, msg.hashCode(),
Intent(context, ConfigureActivity::class.java).apply {
putExtra("isShowNeedRestart", true)
putExtra("isShowUpdDialog", false)
}, if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
Intent(context, ConfigureActivity::class.java).apply { putExtra("isShowUpdDialog", false) },
if (Build.VERSION.SDK_INT < 31) PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_IMMUTABLE
)
)
}.build())

View File

@@ -51,6 +51,12 @@ object SystemUITool {
cancelButton()
}
/**
* 刷新系统界面状态栏与通知图标
* @param context 实例
*/
fun refreshSystemUI(context: Context) = IconRuleManagerTool.refreshSystemUI(context)
/**
* 显示需要重启系统界面的 [Snackbar]
* @param context 实例
@@ -68,6 +74,6 @@ object SystemUITool {
if (isXposedModuleActive)
if (isNotNoificationEnabled)
context.snake(msg = "无通知权限,请重启系统界面使更改生效", actionText = "立即重启") { restartSystemUI(context) }
else context.snake(msg = "数据已更新,已推送的通知将在下次生效", actionText = "立即重启") { restartSystemUI(context) }
else context.snake(msg = "通知图标优化名单已完成同步")
else context.snake(msg = "模块没有激活,更改不会生效")
}

View File

@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="@color/white"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M9.01,14H2v2h7.01v3L13,15l-3.99,-4V14zM14.99,13v-3H22V8h-7.01V5L11,9L14.99,13z" />
</vector>

View File

@@ -1,5 +1,11 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM14,13v4h-4v-4H7l5,-5 5,5h-3z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@color/white"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM14,13v4h-4v-4H7l5,-5 5,5h-3z" />
</vector>

View File

@@ -419,35 +419,15 @@
android:textSize="12sp" />
</LinearLayout>
<com.fankes.miui.notify.ui.view.MaterialSwitch
android:id="@+id/color_icon_hook_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="忽略彩色通知图标"
android:textColor="@color/colorTextGray"
android:textSize="15sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:text="此选项默认开启,开启后将自动对 APP 通知图标进行判断,保持高版本 API 的 APP 不规范的彩色图标不被着色为白、黑色块并对图标进行圆角优化,关闭后将按照 Android API 规范对 APP 通知进行图标着色,可能会出现着色为黑白、色块情况。"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
<com.fankes.miui.notify.ui.view.MaterialSwitch
android:id="@+id/color_icon_compat_switch"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content"
android:text="启用兼容模式"
android:textColor="@color/colorTextGray"
android:textSize="15sp" />
<TextView
android:id="@+id/color_icon_compat_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"