Modify support MIUI 11 and fix some bugs in SystemUIHooker

This commit is contained in:
2023-01-28 00:01:21 +08:00
parent baea7847c8
commit ce29f65ce8
3 changed files with 16 additions and 28 deletions

View File

@@ -190,15 +190,6 @@ object SystemUIHooker : YukiBaseHooker() {
}
} else BitmapCompatTool.isGrayscaleDrawable(drawable)
/**
* 是否为旧版本 MIUI 方案
*
* 拥有 “handleHeaderViews” 方法
* @return [Boolean]
*/
private val hasHandleHeaderViews
get() = NotificationHeaderViewWrapperClass.toClassOrNull()?.hasMethod { name = "handleHeaderViews" } ?: false
/**
* 处理为圆角图标
* @return [Drawable]
@@ -699,23 +690,25 @@ object SystemUIHooker : YukiBaseHooker() {
StatusBarIconViewClass.hook {
/** Hook 状态栏通知图标的颜色 */
injectMember {
method { name = "updateIconColor" }
method {
name { it == "updateDecorColor" || it == "updateIconColor" }
emptyParam()
}.all()
afterHook {
instance<ImageView>().also {
if (hasIgnoreStatusBarIconColor(it.context, field { name = "mNotification" }
.get(instance).cast<StatusBarNotification>())) it.apply {
alpha = 1f
colorFilter = null
} else it.apply {
val notification = field { name = "mNotification" }.get(it).cast<StatusBarNotification>()
val currentSetColor = field { name = "mCurrentSetColor" }.get(it).int()
if (hasIgnoreStatusBarIconColor(it.context, notification)) {
it.alpha = 1f
it.colorFilter = null
} else {
/**
* 防止图标不是纯黑的问题
* 图标在任何场景下跟随状态栏其它图标保持半透明
* MIUI 12 进行单独判断
* MIUI 11、12 进行单独判断
*/
field { name = "mCurrentSetColor" }.get(instance).int().also { color ->
alpha = if (color.isWhiteColor) 0.95f else 0.8f
setColorFilter(if (color.isWhiteColor) color else Color.BLACK)
}
it.alpha = if (currentSetColor.isWhiteColor) 0.95f else 0.8f
it.setColorFilter(if (currentSetColor.isWhiteColor) currentSetColor else Color.BLACK)
}
}
}
@@ -789,9 +782,7 @@ object SystemUIHooker : YukiBaseHooker() {
NotificationHeaderViewWrapperClass.hook {
/** 修复下拉通知图标自动设置回 APP 图标的方法 */
injectMember {
if (hasHandleHeaderViews)
method { name = "handleHeaderViews" }
else method { name = "resolveHeaderViews" }
method { name { it == "resolveHeaderViews" || it == "handleHeaderViews" || it == "resolveViews" } }
afterHook {
/** 忽略较旧版本 - 在没有 MIUI 通知栏样式的时候可能出现奇怪的问题 */
if (isNotHasAbsoluteMiuiStyle && isShowMiuiStyle) return@afterHook

View File

@@ -106,7 +106,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
showDialog {
title = "不支持的 MIUI 版本"
msg = (if (miuiVersion.isNotBlank())
"此模块目前支持 MIUI 12~14 系统,你的 MIUI 版本为 ${miuiVersion},暂不支持。\n\n" +
"此模块目前支持 MIUI 11~14 系统,你的 MIUI 版本为 ${miuiVersion},暂不支持。\n\n" +
"如果你的 MIUI 版本识别有误,请检查是否有相关插件修改了系统版本。\n\n"
else "无法获取 MIUI 版本,请检查你是否修改了系统参数或使用非官方系统。\n\n") + "若有其它疑问,你可以点击下方按钮前往项目地址进行反馈。"
confirmButton(text = "前往项目地址") {

View File

@@ -128,10 +128,7 @@ inline val isNotMIUI get() = !isMIUI
*/
val isSupportMiuiVersion
get() = when (miuiVersion) {
"12" -> true
"12.5" -> true
"13" -> true
"14" -> true
"11", "12", "12.5", "13", "14" -> true
else -> false
}