mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-10-22 21:39:21 +08:00
修复 MIUI 在 Android 11 上最小化优先级图标的着色问题
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.fankes.miui.notify.hook
|
package com.fankes.miui.notify.hook
|
||||||
|
|
||||||
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@@ -55,6 +56,7 @@ import com.highcapable.yukihookapi.hook.param.PackageParam
|
|||||||
import com.highcapable.yukihookapi.hook.type.android.ContextClass
|
import com.highcapable.yukihookapi.hook.type.android.ContextClass
|
||||||
import com.highcapable.yukihookapi.hook.type.android.DrawableClass
|
import com.highcapable.yukihookapi.hook.type.android.DrawableClass
|
||||||
import com.highcapable.yukihookapi.hook.type.android.ImageViewClass
|
import com.highcapable.yukihookapi.hook.type.android.ImageViewClass
|
||||||
|
import com.highcapable.yukihookapi.hook.type.java.BooleanType
|
||||||
import com.highcapable.yukihookapi.hook.type.java.IntType
|
import com.highcapable.yukihookapi.hook.type.java.IntType
|
||||||
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
|
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
|
||||||
|
|
||||||
@@ -334,15 +336,21 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
* @param context 实例
|
* @param context 实例
|
||||||
* @param expandedNf 通知实例
|
* @param expandedNf 通知实例
|
||||||
* @param iconImageView 通知图标实例
|
* @param iconImageView 通知图标实例
|
||||||
|
* @param isExpanded 通知是否展开 - 可做最小化通知处理
|
||||||
*/
|
*/
|
||||||
private fun PackageParam.hookNotifyIconOnSet(context: Context, expandedNf: StatusBarNotification?, iconImageView: ImageView) =
|
private fun PackageParam.hookNotifyIconOnSet(
|
||||||
safeRun(msg = "AutoSetAppIconOnSet") {
|
context: Context,
|
||||||
|
expandedNf: StatusBarNotification?,
|
||||||
|
iconImageView: ImageView,
|
||||||
|
isExpanded: Boolean
|
||||||
|
) = safeRun(msg = "AutoSetAppIconOnSet") {
|
||||||
/** 判断是 MIUI 样式就停止 Hook */
|
/** 判断是 MIUI 样式就停止 Hook */
|
||||||
if (context.isMiuiNotifyStyle) return@safeRun
|
if (context.isMiuiNotifyStyle) return@safeRun
|
||||||
/** 如果没开启修复 APP 的彩色图标 */
|
/** 如果没开启修复 APP 的彩色图标 */
|
||||||
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
|
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
|
||||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||||
expandedNf?.let { notifyInstance ->
|
expandedNf?.let { notifyInstance ->
|
||||||
|
|
||||||
/** 新版风格反色 */
|
/** 新版风格反色 */
|
||||||
val newStyle = if (context.isSystemInDarkMode) 0xFF2D2D2D.toInt() else Color.WHITE
|
val newStyle = if (context.isSystemInDarkMode) 0xFF2D2D2D.toInt() else Color.WHITE
|
||||||
|
|
||||||
@@ -359,7 +367,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
val supportColor = iconColor.let {
|
val supportColor = iconColor.let {
|
||||||
when {
|
when {
|
||||||
isUpperOfAndroidS -> newStyle
|
isUpperOfAndroidS -> newStyle
|
||||||
it == 0 -> oldStyle
|
it == 0 || !isExpanded -> oldStyle
|
||||||
else -> it
|
else -> it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +385,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
var customIconColor: Int
|
var customIconColor: Int
|
||||||
compatCustomIcon(isGrayscaleIcon, notifyInstance.opPkgName).also {
|
compatCustomIcon(isGrayscaleIcon, notifyInstance.opPkgName).also {
|
||||||
customIcon = it.first
|
customIcon = it.first
|
||||||
customIconColor = it.second
|
customIconColor = if (isUpperOfAndroidS || isExpanded) it.second else 0
|
||||||
}
|
}
|
||||||
/** 打印日志 */
|
/** 打印日志 */
|
||||||
printLogcat(tag = "NotifyIcon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)
|
printLogcat(tag = "NotifyIcon", context, notifyInstance, isCustom = customIcon != null, isGrayscaleIcon)
|
||||||
@@ -540,6 +548,9 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
NotificationHeaderViewWrapperClass.clazz
|
NotificationHeaderViewWrapperClass.clazz
|
||||||
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
|
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
|
||||||
|
|
||||||
|
/** 通知是否展开 */
|
||||||
|
var isExpanded = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
|
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
|
||||||
* 获取其中的得到通知方法
|
* 获取其中的得到通知方法
|
||||||
@@ -548,7 +559,12 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
.method { name = "getEntry" }
|
.method { name = "getEntry" }
|
||||||
.get(NotificationViewWrapperClass.clazz.field {
|
.get(NotificationViewWrapperClass.clazz.field {
|
||||||
name = "mRow"
|
name = "mRow"
|
||||||
}.get(instance).self).call()?.let {
|
}.get(instance).self?.also {
|
||||||
|
isExpanded = ExpandableNotificationRowClass.clazz.method {
|
||||||
|
name = "isExpanded"
|
||||||
|
returnType = BooleanType
|
||||||
|
}.get(it).invoke<Boolean>() == true
|
||||||
|
}).call()?.let {
|
||||||
it.javaClass.method {
|
it.javaClass.method {
|
||||||
name = "getSbn"
|
name = "getSbn"
|
||||||
}.get(it).invoke<StatusBarNotification>()
|
}.get(it).invoke<StatusBarNotification>()
|
||||||
@@ -556,8 +572,15 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
.method { name = "getStatusBarNotification" }
|
.method { name = "getStatusBarNotification" }
|
||||||
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
|
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
|
||||||
.invoke<StatusBarNotification>()
|
.invoke<StatusBarNotification>()
|
||||||
|
|
||||||
|
/** 获取优先级 */
|
||||||
|
val importance =
|
||||||
|
(iconImageView.context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager?)
|
||||||
|
?.getNotificationChannel(expandedNf?.notification?.channelId)?.importance ?: 0
|
||||||
|
/** 非最小化优先级的通知全部设置为展开状态 */
|
||||||
|
if (importance != 1) isExpanded = true
|
||||||
/** 执行 Hook */
|
/** 执行 Hook */
|
||||||
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView)
|
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView, isExpanded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,8 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
appVersionName = "1.85"
|
appVersionName = "1.86"
|
||||||
appVersionCode = 18
|
appVersionCode = 19
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
task clean(type: Delete) {
|
||||||
|
Reference in New Issue
Block a user