mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-05 10:15:31 +08:00
Fix status bar icon color in some MIUI like MIPUSH notification cannot reverse color problem in SystemUIHooker
This commit is contained in:
@@ -61,6 +61,7 @@ import com.highcapable.yukihookapi.hook.log.loggerD
|
|||||||
import com.highcapable.yukihookapi.hook.log.loggerW
|
import com.highcapable.yukihookapi.hook.log.loggerW
|
||||||
import com.highcapable.yukihookapi.hook.type.android.*
|
import com.highcapable.yukihookapi.hook.type.android.*
|
||||||
import com.highcapable.yukihookapi.hook.type.java.BooleanType
|
import com.highcapable.yukihookapi.hook.type.java.BooleanType
|
||||||
|
import com.highcapable.yukihookapi.hook.type.java.FloatType
|
||||||
import com.highcapable.yukihookapi.hook.type.java.IntType
|
import com.highcapable.yukihookapi.hook.type.java.IntType
|
||||||
import top.defaults.drawabletoolbox.DrawableBuilder
|
import top.defaults.drawabletoolbox.DrawableBuilder
|
||||||
|
|
||||||
@@ -88,6 +89,9 @@ object SystemUIHooker : YukiBaseHooker() {
|
|||||||
private const val NotificationChildrenContainerClass =
|
private const val NotificationChildrenContainerClass =
|
||||||
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.stack.NotificationChildrenContainer"
|
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.stack.NotificationChildrenContainer"
|
||||||
|
|
||||||
|
/** 原生存在的类 */
|
||||||
|
private const val NotificationIconAreaControllerClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.phone.NotificationIconAreaController"
|
||||||
|
|
||||||
/** 原生存在的类 */
|
/** 原生存在的类 */
|
||||||
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
|
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
|
||||||
|
|
||||||
@@ -146,6 +150,9 @@ object SystemUIHooker : YukiBaseHooker() {
|
|||||||
/** 缓存的通知图标优化数组 */
|
/** 缓存的通知图标优化数组 */
|
||||||
private var iconDatas = ArrayList<IconDataBean>()
|
private var iconDatas = ArrayList<IconDataBean>()
|
||||||
|
|
||||||
|
/** 当前是否处于深色图标模式 - 跟随 Hook 保存 */
|
||||||
|
private var isDarkIconMode = false
|
||||||
|
|
||||||
/** 是否显示通知图标 - 跟随 Hook 保存 */
|
/** 是否显示通知图标 - 跟随 Hook 保存 */
|
||||||
private var isShowNotificationIcons = true
|
private var isShowNotificationIcons = true
|
||||||
|
|
||||||
@@ -542,6 +549,30 @@ object SystemUIHooker : YukiBaseHooker() {
|
|||||||
} ?: true.also { printLogcat(tag = "IconColor", context, expandedNf = null, isCustom = false, isGrayscale = false) }
|
} ?: true.also { printLogcat(tag = "IconColor", context, expandedNf = null, isCustom = false, isGrayscale = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新状态栏通知图标颜色
|
||||||
|
* @param container 当前通知图标容器实例
|
||||||
|
* @param isDarkIconMode 是否为深色图标模式
|
||||||
|
*/
|
||||||
|
private fun updateStatusBarIconColor(container: ViewGroup, isDarkIconMode: Boolean = this.isDarkIconMode) {
|
||||||
|
if (container.childCount > 0) container.children.forEach {
|
||||||
|
(it as? ImageView?)?.also { iconView ->
|
||||||
|
val notification = iconView.current().field { name = "mNotification" }.cast<StatusBarNotification>()
|
||||||
|
if (hasIgnoreStatusBarIconColor(iconView.context, notification)) {
|
||||||
|
iconView.alpha = 1f
|
||||||
|
iconView.colorFilter = null
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
* 防止图标不是纯黑的问题
|
||||||
|
* 图标在任何场景下跟随状态栏其它图标保持半透明
|
||||||
|
*/
|
||||||
|
iconView.alpha = if (isDarkIconMode) 0.8f else 0.95f
|
||||||
|
iconView.setColorFilter(if (isDarkIconMode) Color.BLACK else Color.WHITE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 [NotificationViewWrapperClass] 中获取 [ExpandableNotificationRowClass]
|
* 从 [NotificationViewWrapperClass] 中获取 [ExpandableNotificationRowClass]
|
||||||
* @return [Pair] - ([Boolean] 通知是否展开,[Any] 通知 Row 实例)
|
* @return [Pair] - ([Boolean] 通知是否展开,[Any] 通知 Row 实例)
|
||||||
@@ -686,33 +717,49 @@ object SystemUIHooker : YukiBaseHooker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** 注入状态栏通知图标实例 */
|
/** 注入状态栏通知图标容器管理实例 */
|
||||||
StatusBarIconViewClass.hook {
|
NotificationIconAreaControllerClass.hook {
|
||||||
/** Hook 状态栏通知图标的颜色 */
|
/** Hook 深色图标模式改变 */
|
||||||
injectMember {
|
injectMember {
|
||||||
method {
|
method {
|
||||||
name { it == "updateDecorColor" || it == "updateIconColor" }
|
name = "onDarkChanged"
|
||||||
emptyParam()
|
param(RectClass, FloatType, IntType)
|
||||||
}.all()
|
}
|
||||||
afterHook {
|
afterHook {
|
||||||
instance<ImageView>().also {
|
field { name = "mNotificationIcons" }.get(instance).cast<ViewGroup>()?.also {
|
||||||
val notification = field { name = "mNotification" }.get(it).cast<StatusBarNotification>()
|
/** 重新设置通知图标容器实例 */
|
||||||
val currentSetColor = field { name = "mCurrentSetColor" }.get(it).int()
|
notificationIconContainer = it
|
||||||
if (hasIgnoreStatusBarIconColor(it.context, notification)) {
|
when (args(index = 1).float()) {
|
||||||
it.alpha = 1f
|
1.0f -> {
|
||||||
it.colorFilter = null
|
isDarkIconMode = true
|
||||||
} else {
|
updateStatusBarIconColor(it, isDarkIconMode = true)
|
||||||
/**
|
}
|
||||||
* 防止图标不是纯黑的问题
|
0.0f -> {
|
||||||
* 图标在任何场景下跟随状态栏其它图标保持半透明
|
isDarkIconMode = false
|
||||||
* MIUI 11、12 进行单独判断
|
updateStatusBarIconColor(it, isDarkIconMode = false)
|
||||||
*/
|
}
|
||||||
it.alpha = if (currentSetColor.isWhiteColor) 0.95f else 0.8f
|
else -> updateStatusBarIconColor(it, isDarkIconMode = false)
|
||||||
it.setColorFilter(if (currentSetColor.isWhiteColor) currentSetColor else Color.BLACK)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** Hook 更新通知图标事件 */
|
||||||
|
injectMember {
|
||||||
|
method {
|
||||||
|
name = "updateNotificationIcons"
|
||||||
|
paramCount = 1
|
||||||
|
}
|
||||||
|
afterHook {
|
||||||
|
field { name = "mNotificationIcons" }.get(instance).cast<ViewGroup>()?.also {
|
||||||
|
/** 重新设置通知图标容器实例 */
|
||||||
|
notificationIconContainer = it
|
||||||
|
updateStatusBarIconColor(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** 注入状态栏通知图标实例 */
|
||||||
|
StatusBarIconViewClass.hook {
|
||||||
/** 注册广播 */
|
/** 注册广播 */
|
||||||
injectMember {
|
injectMember {
|
||||||
method {
|
method {
|
||||||
|
Reference in New Issue
Block a user