mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-09 03:54:31 +08:00
Compare commits
4 Commits
3e29a70969
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
97538445e1 | ||
30fdbdbcb2
|
|||
1675e28ca7
|
|||
|
62a40b706d |
@@ -20,10 +20,11 @@
|
||||
*
|
||||
* This file is created by fankes on 2022/3/25.
|
||||
*/
|
||||
@file:Suppress("StaticFieldLeak", "ConstPropertyName")
|
||||
@file:Suppress("ConstPropertyName")
|
||||
|
||||
package com.fankes.miui.notify.hook.entity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.WallpaperManager
|
||||
@@ -67,6 +68,7 @@ import com.fankes.miui.notify.utils.factory.isMIOS
|
||||
import com.fankes.miui.notify.utils.factory.isNotSystemInDarkMode
|
||||
import com.fankes.miui.notify.utils.factory.isSystemInDarkMode
|
||||
import com.fankes.miui.notify.utils.factory.isUpperOfAndroidS
|
||||
import com.fankes.miui.notify.utils.factory.miosVersionCode
|
||||
import com.fankes.miui.notify.utils.factory.miuiIncrementalVersion
|
||||
import com.fankes.miui.notify.utils.factory.round
|
||||
import com.fankes.miui.notify.utils.factory.runInSafe
|
||||
@@ -215,6 +217,7 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
private var isUsingCachingMethod = false
|
||||
|
||||
/** 状态栏通知图标容器 */
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private var notificationIconContainer: ViewGroup? = null
|
||||
|
||||
/** 通知栏通知控制器 */
|
||||
@@ -659,8 +662,10 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
/** 获取 [StatusBarNotification] 实例 */
|
||||
val notifyInstance = asResolver().optional().firstFieldOrNull { name = "mNotification" }?.get<StatusBarNotification>() ?: return false
|
||||
|
||||
val appContext = context.createPackageContext(notifyInstance.nfPkgName, Context.CONTEXT_IGNORE_SECURITY)
|
||||
|
||||
/** 获取通知小图标 */
|
||||
val iconDrawable = notifyInstance.notification?.smallIcon?.loadDrawable(context) ?: return false
|
||||
val iconDrawable = notifyInstance.notification?.smallIcon?.loadDrawable(appContext) ?: return false
|
||||
|
||||
/** 判断是否不是灰度图标 */
|
||||
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)
|
||||
@@ -693,6 +698,7 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
* @param animColor 动画过渡颜色
|
||||
*/
|
||||
private fun updateStatusBarIconColor(iconView: ImageView, isDarkIconMode: Boolean = this.isDarkIconMode, animColor: Int? = null) {
|
||||
if (miosVersionCode >= 3) return
|
||||
if (iconView.isGrayscaleIcon()) {
|
||||
/**
|
||||
* 防止图标不是纯黑的问题
|
||||
@@ -947,11 +953,15 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
parameters(Notification::class, Context::class)
|
||||
}?.hook()?.after {
|
||||
val nf = args().first().cast<Notification>()
|
||||
val appname = nf?.extras?.getString("miui.opPkg")
|
||||
val context = args(index = 1).cast<Context>()
|
||||
val iconBitmap = nf?.smallIcon?.loadDrawable(context)?.toBitmap()
|
||||
result = if (context != null && iconBitmap != null && !iconBitmap.isRecycled)
|
||||
iconBitmap.toDrawable(context.resources)
|
||||
else null
|
||||
if (appname != null) {
|
||||
val appContext = context?.createPackageContext(appname, Context.CONTEXT_IGNORE_SECURITY)
|
||||
val iconBitmap = nf.smallIcon?.loadDrawable(appContext)?.toBitmap()
|
||||
result = if (context != null && iconBitmap != null && !iconBitmap.isRecycled)
|
||||
iconBitmap.toDrawable(context.resources)
|
||||
else null
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 强制回写系统的状态栏图标样式为原生
|
||||
@@ -986,59 +996,61 @@ object SystemUIHooker : YukiBaseHooker() {
|
||||
}
|
||||
}
|
||||
}
|
||||
/** 焦点通知深色模式切换点 */
|
||||
FocusedNotifPromptViewClass?.resolve()?.optional()?.apply {
|
||||
firstMethodOrNull {
|
||||
name = "onDarkChanged"
|
||||
parameters(ArrayList::class, Float::class, Int::class, Int::class, Int::class, Boolean::class)
|
||||
}?.hook()?.after {
|
||||
val isDark = args(index = 1).float()
|
||||
val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get()
|
||||
if (ConfigData.isEnableModuleLog)
|
||||
YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon")
|
||||
if (focusedIcon || ConfigData.isEnableFocusNotificationFix)
|
||||
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
|
||||
name = "setColorFilter"
|
||||
superclass()
|
||||
}?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
|
||||
if (miosVersionCode < 3) {
|
||||
/** 焦点通知深色模式切换点 */
|
||||
FocusedNotifPromptViewClass?.resolve()?.optional()?.apply {
|
||||
firstMethodOrNull {
|
||||
name = "onDarkChanged"
|
||||
parameters(ArrayList::class, Float::class, Int::class, Int::class, Int::class, Boolean::class)
|
||||
}?.hook()?.after {
|
||||
val isDark = args(index = 1).float()
|
||||
val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get()
|
||||
if (ConfigData.isEnableModuleLog)
|
||||
YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon")
|
||||
if (focusedIcon || ConfigData.isEnableFocusNotificationFix)
|
||||
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
|
||||
name = "setColorFilter"
|
||||
superclass()
|
||||
}?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
|
||||
}
|
||||
}
|
||||
}
|
||||
/** 去他妈的焦点通知彩色图标 */
|
||||
FocusUtilsClass?.resolve()?.optional()?.apply {
|
||||
fun HookParam.hookTickerDarkIcon(isDark: Boolean) {
|
||||
(globalContext ?: args().first().cast())?.also { context ->
|
||||
val expandedNf = args().first().cast<StatusBarNotification?>()
|
||||
val small = expandedNf?.notification?.smallIcon
|
||||
/** Hook 状态栏小图标 */
|
||||
compatStatusIcon(
|
||||
context = context,
|
||||
nf = expandedNf,
|
||||
iconDrawable = small?.loadDrawable(context)
|
||||
).also { pair ->
|
||||
focusedIcon = pair.second
|
||||
val originalBitmap = pair.first?.toBitmap()
|
||||
val bitmap = originalBitmap?.scale(50, 50)
|
||||
result = Icon.createWithBitmap(bitmap).apply {
|
||||
if (pair.second || ConfigData.isEnableFocusNotificationFix)
|
||||
setTint(if (isDark) Color.BLACK else Color.WHITE)
|
||||
/** 去他妈的焦点通知彩色图标 */
|
||||
FocusUtilsClass?.resolve()?.optional()?.apply {
|
||||
fun HookParam.hookTickerDarkIcon(isDark: Boolean) {
|
||||
(globalContext ?: args().first().cast())?.also { context ->
|
||||
val expandedNf = args().first().cast<StatusBarNotification?>()
|
||||
val small = expandedNf?.notification?.smallIcon
|
||||
/** Hook 状态栏小图标 */
|
||||
compatStatusIcon(
|
||||
context = context,
|
||||
nf = expandedNf,
|
||||
iconDrawable = small?.loadDrawable(context)
|
||||
).also { pair ->
|
||||
focusedIcon = pair.second
|
||||
val originalBitmap = pair.first?.toBitmap()
|
||||
val bitmap = originalBitmap?.scale(50, 50)
|
||||
result = Icon.createWithBitmap(bitmap).apply {
|
||||
if (pair.second || ConfigData.isEnableFocusNotificationFix)
|
||||
setTint(if (isDark) Color.BLACK else Color.WHITE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
firstMethodOrNull {
|
||||
name = "getStatusBarTickerDarkIcon"
|
||||
parameters {
|
||||
(it.first() == classOf<StatusBarNotification>() ||
|
||||
it.first() == ExpandedNotificationClass) && it.size == 1
|
||||
}
|
||||
}?.hook()?.after { hookTickerDarkIcon(isDark = true) }
|
||||
firstMethodOrNull {
|
||||
name = "getStatusBarTickerIcon"
|
||||
parameters {
|
||||
(it.first() == classOf<StatusBarNotification>() ||
|
||||
it.first() == ExpandedNotificationClass) && it.size == 1
|
||||
}
|
||||
}?.hook()?.after { hookTickerDarkIcon(isDark = false) }
|
||||
}
|
||||
firstMethodOrNull {
|
||||
name = "getStatusBarTickerDarkIcon"
|
||||
parameters {
|
||||
(it.first() == classOf<StatusBarNotification>() ||
|
||||
it.first() == ExpandedNotificationClass) && it.size == 1
|
||||
}
|
||||
}?.hook()?.after { hookTickerDarkIcon(isDark = true) }
|
||||
firstMethodOrNull {
|
||||
name = "getStatusBarTickerIcon"
|
||||
parameters {
|
||||
(it.first() == classOf<StatusBarNotification>() ||
|
||||
it.first() == ExpandedNotificationClass) && it.size == 1
|
||||
}
|
||||
}?.hook()?.after { hookTickerDarkIcon(isDark = false) }
|
||||
}
|
||||
/** 注入状态栏通知图标实例 */
|
||||
StatusBarIconViewClass.resolve().optional().firstMethodOrNull {
|
||||
|
@@ -178,7 +178,7 @@ inline val isNotMIOS get() = !isMIOS
|
||||
val isSupportMiSystemVersion
|
||||
get() = when {
|
||||
isMIOS -> when (miosVersion) {
|
||||
"1.0", "1.1", "2.0" -> true
|
||||
"1.0", "1.1", "2.0" , "3.0"-> true
|
||||
else -> false
|
||||
}
|
||||
isMIUI -> when (miuiVersion) {
|
||||
@@ -200,6 +200,7 @@ inline val isNotSupportMiSystemVersion get() = !isSupportMiSystemVersion
|
||||
*/
|
||||
val androidVersionCodeName
|
||||
get() = when (Build.VERSION.SDK_INT) {
|
||||
36 -> "W"
|
||||
35 -> "V"
|
||||
34 -> "U"
|
||||
33 -> "T"
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
@@ -22,7 +22,7 @@ repositories:
|
||||
plugins:
|
||||
com.android.application:
|
||||
alias: android-application
|
||||
version: 8.12.1
|
||||
version: 8.13.0
|
||||
org.jetbrains.kotlin.android:
|
||||
alias: kotlin-android
|
||||
version: 2.2.10
|
||||
@@ -33,7 +33,7 @@ plugins:
|
||||
libraries:
|
||||
com.fankes.projectpromote:
|
||||
project-promote:
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
repositories:
|
||||
fankes-maven-releases
|
||||
de.robv.android.xposed:
|
||||
@@ -69,7 +69,7 @@ libraries:
|
||||
version: 1.7.1
|
||||
com.google.android.material:
|
||||
material:
|
||||
version: 1.12.0
|
||||
version: 1.13.0
|
||||
androidx.constraintlayout:
|
||||
constraintlayout:
|
||||
version: 2.2.1
|
||||
|
Reference in New Issue
Block a user