15 Commits
1.8 ... 1.86

Author SHA1 Message Date
d7a9f1e413 Update version to 1.86,fix more bugs. 2022-03-01 02:52:08 +08:00
edf199d9a6 Update version to 1.86,fix more bugs. 2022-03-01 02:51:09 +08:00
8d6a05e02c 修复 MIUI 在 Android 11 上最小化优先级图标的着色问题 2022-03-01 02:50:30 +08:00
c7d9b2661b 修复一个可能崩溃的问题 2022-02-27 23:29:43 +08:00
d0a32e08d9 Merge code 2022-02-27 22:48:01 +08:00
b0f9e44f8a Update version to 1.85,fix more bugs. 2022-02-27 00:51:24 +08:00
1e749d2f64 Update version to 1.85,fix more bugs. 2022-02-27 00:50:41 +08:00
c886bbd6cf Update version to 1.85,fix more bugs. 2022-02-27 00:49:32 +08:00
ec45839029 合并代码到新项目 2022-02-27 00:45:28 +08:00
6fd2294529 Merge remote-tracking branch 'origin/master' 2022-02-27 00:05:00 +08:00
Fankesyooni
5913da8183 Merge pull request #37 from naicfeng/patch-1
适配 航班管家 图标 #36
2022-02-27 00:04:38 +08:00
浅秋枫影
fcf2889668 fix iconBitmap 2022-02-27 00:01:03 +08:00
浅秋枫影
6d784f1283 适配 航班管家 图标 #36
适配 航班管家 图标 #36
2022-02-26 23:56:45 +08:00
cd8ceec765 完全修改 Hook 方案,加入新的日志打印方式 2022-02-26 22:57:11 +08:00
5325ac37d6 Update version to 1.8,fix more bugs. 2022-02-25 03:10:47 +08:00
14 changed files with 387 additions and 1444 deletions

2
.idea/misc.xml generated
View File

@@ -6,6 +6,8 @@
<entry key="app/src/main/res/drawable-night/dark_round.xml" value="0.256" />
<entry key="app/src/main/res/drawable-night/permotion_round.xml" value="0.256" />
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.44871794871794873" />
<entry key="app/src/main/res/drawable/bg_green_round.xml" value="0.255" />
<entry key="app/src/main/res/drawable/bg_yellow_round.xml" value="0.255" />
<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/activity_config.xml" value="0.42168674698795183" />

View File

@@ -1,50 +0,0 @@
# 开始贡献
欢迎为通知图标优化名单贡献宝贵资源!<br/>
## 分支规定
不管是直接 Push 代码还是提交 Pull Request都必须使 commit 指向 master 分支。
## 代码格式规范
- 1.全部提交代码必须使用 IDE(Android Studio 或 IDEA) 进行格式化,未经格式化的代码将拒绝合并提交请求
- 2.代码必须使用 4 spaces 缩进格式化
## 贡献方法
- 2022.02.25 适配数据已变更为云端更新
- 在下方的 JSON 文件中添加新的 APP 通知图标适配条目
- [NotifyIconsSupportConfig.json](https://github.com/fankes/MIUINativeNotifyIcon/blob/master/iconPack/NotifyIconsSupportConfig.json)
- 使用灰度位图转 Base64 来得到 Base64 的位图数据字符串
- [BitmapToBase64](https://github.com/fankes/BitmapToBase64)
- 新增条目的模板如下所示
```json
{
"appName": "", // APP 名称
"packageName": "", // APP 包名
"isEnabled": true, // 是否默认启用替换彩色图标 - 关闭后将全部停止替换
"isEnabledAll": false, // 是否默认启用替换全部图标
"iconBitmap": "", // 位图数据 Base64 字符串
"iconColor": "#ff232323", // 通知栏中显示的图标颜色 - 不设置使用系统默认颜色 (不设置颜色可删除此项)
"contributorName": "" // 贡献者昵称
}
```
- 图标大小建议保持在 50x50
- 提交时请将后方的注释删除,否则不予合并代码
## 同步列表地址
- Github 直连地址 [Raw](https://raw.githubusercontent.com/fankes/MIUINativeNotifyIcon/master/iconPack/NotifyIconsSupportConfig.json)
- 数据将在稍后同步至 [Surge](https://fankes.mnn.surge.sh/NotifyIconsSupportConfig.json)
## 其它要求
- 1.调试性质或大批量注释代码,禁止提交
- 2.类名和方法名仅能由开发者进行修改和提交,禁止随意修改项目名称、方法名称以及类名
- 3.禁止随意更新项目依赖以及增加新的依赖,有问题请提前提交到 issues 进行说明
- 4.禁止更新项目版本号,版本号交由开发者合并代码并发布 release 版本
- 5.代码语言要求,请统一使用 Kotlin除特殊情况外不接受其他语言的提交
- 6.以上

View File

@@ -2,7 +2,7 @@
![Eclipse Marketplace](https://img.shields.io/badge/build-passing-brightgreen)
![Eclipse Marketplace](https://img.shields.io/badge/license-AGPL3.0-blue)
![Eclipse Marketplace](https://img.shields.io/badge/version-v1.71-green)
![Eclipse Marketplace](https://img.shields.io/badge/version-v1.86-green)
<br/><br/>
<img src="https://github.com/fankes/MIUINativeNotifyIcon/blob/master/app/src/main/ic_launcher-playstore.png" width = "100" height = "100"/>
<br/>
@@ -12,7 +12,7 @@ Fix the native notification bar icon function abandoned by the MIUI development
# 开始使用
点击下载最新版本
<a href='https://github.com/fankes/MIUINativeNotifyIcon/releases'>![Eclipse Marketplace](https://img.shields.io/badge/download-v1.71-green)</a>
<a href='https://github.com/fankes/MIUINativeNotifyIcon/releases'>![Eclipse Marketplace](https://img.shields.io/badge/download-v1.86-green)</a>
<br/><br/>
⚠️ 适配说明<br/>
@@ -29,16 +29,11 @@ Fix the native notification bar icon function abandoned by the MIUI development
[Release](https://github.com/fankes/MIUINativeNotifyIcon/releases)
及[蓝奏云](https://fankes.lanzouy.com/b030o2e8h),从其他非正规渠道下载到的版本或对您造成任何影响均与我们无关。
# 开始贡献
# 贡献通知图标优化名单
由于国内厂商 APP 的不规范彩色图标影响整体图标的美观,现在开放第三方 APP 的通知图标适配<br/>
欢迎为通知图标优化名单贡献宝贵资源!<br/>
此项目是 `AndroidNotifyIconAdapt` 项目的一部分,详情请参考下方<br/>
- [CONTRIBUTING](https://github.com/fankes/MIUINativeNotifyIcon/blob/master/CONTRIBUTING.md)
# 通知测试
你可以 [点击这里](https://github.com/fankes/MIUINativeNotifyIcon/blob/master/tool/NotifyTester.apk) 下载工具测试通知图标是否生效。
- [Android 通知图标规范适配](https://github.com/fankes/AndroidNotifyIconAdapt)
# 历史背景

View File

@@ -20,7 +20,7 @@
android:value="true" />
<meta-data
android:name="xposeddescription"
android:value="MIUI 原生通知图标,修复 12.5、13 后期被破坏的彩色图标。\n开发者酷安 @星夜不荟" />
android:value="为金凡教我做事的 MIUI 修复 12.5、13 后期被破坏的彩色图标。\n开发者酷安 @星夜不荟" />
<meta-data
android:name="xposedminversion"
android:value="93" />

View File

@@ -28,7 +28,7 @@ import java.io.Serializable
/**
* 通知栏小图标 bean
* @param appName APP 名称 - 仅限默认语言区域
* @param appName APP 名称
* @param packageName 包名
* @param iconBitmap 图标位图
* @param iconColor 通知栏中显示的图标颜色 - 设置为 0 使用系统默认颜色

View File

@@ -22,6 +22,7 @@
*/
package com.fankes.miui.notify.hook
import android.app.NotificationManager
import android.content.Context
import android.graphics.Bitmap
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.DrawableClass
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.xposed.proxy.YukiHookXposedInitProxy
@@ -70,20 +72,27 @@ class HookEntry : YukiHookXposedInitProxy {
private const val NotificationHeaderViewWrapperInjectorClass =
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapperInjector"
/** MIUI 新版本存在的类 */
private const val NotificationHeaderViewWrapperClass =
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationHeaderViewWrapper"
/** MIUI 新版本存在的类 */
private const val NotificationViewWrapperClass =
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationViewWrapper"
/** 未确定是否只有旧版本存在的类 */
private const val ExpandableNotificationRowClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.ExpandableNotificationRow"
/** 原生存在的类 */
private const val ContrastColorUtilClass = "com.android.internal.util.ContrastColorUtil"
/** 根据多个版本存在不同的包名相同的类 */
private val ExpandableNotificationRowClass = VariousClass(
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.ExpandableNotificationRow",
"$SYSTEMUI_PACKAGE_NAME.statusbar.ExpandableNotificationRow"
)
/** 根据多个版本存在不同的包名相同的类 */
private val NotificationViewWrapperClass = VariousClass(
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationViewWrapper",
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationViewWrapper"
)
/** 根据多个版本存在不同的包名相同的类 */
private val NotificationHeaderViewWrapperClass = VariousClass(
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.wrapper.NotificationHeaderViewWrapper",
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationHeaderViewWrapper"
)
/** 根据多个版本存在不同的包名相同的类 */
private val NotificationUtilClass = VariousClass(
"$SYSTEMUI_PACKAGE_NAME.statusbar.notification.NotificationUtil",
@@ -132,8 +141,21 @@ class HookEntry : YukiHookXposedInitProxy {
NotificationUtilClass.clazz.hasMethod(name = "ignoreStatusBarIconColor", ExpandedNotificationClass.clazz)
}
/**
* 是否为旧版本 MIUI 方案
*
* 拥有 “handleHeaderViews” 方法
* @return [Boolean]
*/
private val PackageParam.hasHandleHeaderViews
get() = safeOfFalse {
NotificationHeaderViewWrapperClass.clazz.hasMethod(name = "handleHeaderViews")
}
/**
* 获取当前通知栏的样式
*
* - ❗新版本可能不存在这个方法
* @return [Boolean]
*/
private val PackageParam.isShowMiuiStyle
@@ -141,15 +163,6 @@ class HookEntry : YukiHookXposedInitProxy {
NotificationUtilClass.clazz.method { name = "showMiuiStyle" }.get().invoke() ?: false
}
/**
* 获取 [ExpandedNotificationClass] 的应用名称
* @param instance 通知实例
* @return [String]
*/
private fun PackageParam.findAppName(instance: Any?) = safeOf(default = "<unknown>") {
ExpandedNotificationClass.clazz.method { name = "getAppName" }.get(instance).invoke() ?: "<empty>"
}
/**
* 适配通知栏、状态栏图标
*
@@ -163,10 +176,51 @@ class HookEntry : YukiHookXposedInitProxy {
private fun StatusBarNotification.compatNotifyIcon(context: Context, iconDrawable: Drawable) = safeOf(iconDrawable) {
/** 给 MIPUSH 设置 APP 自己的图标 */
if (isXmsf && opPkgName.isNotBlank())
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadIcon(context.packageManager)
findAppIcon(context)
else iconDrawable
}
/**
* 获取推送通知的应用名称
* @param context 实例
* @return [String]
*/
private fun StatusBarNotification.findAppName(context: Context) = safeOf(default = "<unknown>") {
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadLabel(context.packageManager)
}
/**
* 获取通知栏、状态栏 APP 图标
* @param context 实例
* @return [Drawable] 适配的图标
*/
private fun StatusBarNotification.findAppIcon(context: Context) = safeOf(notification.smallIcon.loadDrawable(context)) {
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadIcon(context.packageManager)
}
/**
* 打印日志
* @param tag 标识
* @param context 实例
* @param expandedNf 通知实例
* @param isCustom 是否为通知优化生效图标
* @param isGrayscale 是否为灰度图标
*/
private fun PackageParam.printLogcat(
tag: String,
context: Context,
expandedNf: StatusBarNotification?,
isCustom: Boolean,
isGrayscale: Boolean
) {
if (prefs.getBoolean(ENABLE_MODULE_LOG)) loggerD(
msg = "$tag --> [${expandedNf?.findAppName(context)}][${expandedNf?.opPkgName}] " +
"custom [$isCustom] " +
"grayscale [$isGrayscale] " +
"xmsf [${expandedNf?.isXmsf}]"
)
}
/**
* 获取推送通知的包名
*
@@ -212,6 +266,28 @@ class HookEntry : YukiHookXposedInitProxy {
else null
}
/**
* 自动适配状态栏、通知栏自定义小图标
* @param isGrayscaleIcon 是否为灰度图标
* @param packageName APP 包名
* @return [Pair] - ([Bitmap] 位图,[Int] 颜色)
*/
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
}
}
}
return customPair ?: Pair(null, 0)
}
/**
* Hook 状态栏小图标
*
@@ -232,31 +308,21 @@ class HookEntry : YukiHookXposedInitProxy {
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.also { notifyInstance ->
/** 判断是 MIUI 样式就停止 Hook */
if (context.isMiuiNotifyStyle) {
it(notifyInstance.findAppIcon(context).toBitmap())
return@safeRun
}
/** 判断是否不是灰度图标 */
val isNotGrayscaleIcon = notifyInstance.isXmsf || !isGrayscaleIcon(context, iconDrawable)
/** 目标彩色通知 APP 图标 */
var customIcon: Bitmap? = null
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true))
run {
if (iconDatas.isNotEmpty())
iconDatas.forEach {
if ((notifyInstance.opPkgName == it.packageName ||
findAppName(notifyInstance) == it.appName) &&
isAppNotifyHookOf(it)
) {
if (isNotGrayscaleIcon || isAppNotifyHookAllOf(it))
customIcon = it.iconBitmap
return@run
}
}
}
val customIcon = compatCustomIcon(!isNotGrayscaleIcon, notifyInstance.opPkgName).first
/** 打印日志 */
if (prefs.getBoolean(ENABLE_MODULE_LOG))
loggerD(msg = "Icon --> [${findAppName(notifyInstance)}][${notifyInstance.opPkgName}] custom [${customIcon != null}] grayscale [${!isNotGrayscaleIcon}] xmsf [${notifyInstance.isXmsf}]")
printLogcat(tag = "StatusIcon", context, notifyInstance, isCustom = customIcon != null, !isNotGrayscaleIcon)
when {
/** 处理自定义通知图标优化 */
customIcon != null -> it(customIcon!!)
customIcon != null -> it(customIcon)
/** 若不是灰度图标自动处理为圆角 */
isNotGrayscaleIcon -> it(notifyInstance.compatNotifyIcon(context, iconDrawable).toBitmap())
}
@@ -270,107 +336,102 @@ class HookEntry : YukiHookXposedInitProxy {
* @param context 实例
* @param expandedNf 通知实例
* @param iconImageView 通知图标实例
* @param isExpanded 通知是否展开 - 可做最小化通知处理
*/
private fun PackageParam.hookNotifyIconOnSet(context: Context, expandedNf: StatusBarNotification?, iconImageView: ImageView) =
safeRun(msg = "AutoSetAppIconOnSet") {
/** 如果没开启修复 APP 的彩色图标 */
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
/** 是否开启修复 APP 的彩色图标 */
val isNotifyIconFix = prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
private fun PackageParam.hookNotifyIconOnSet(
context: Context,
expandedNf: StatusBarNotification?,
iconImageView: ImageView,
isExpanded: Boolean
) = safeRun(msg = "AutoSetAppIconOnSet") {
/** 判断是 MIUI 样式就停止 Hook */
if (context.isMiuiNotifyStyle) return@safeRun
/** 如果没开启修复 APP 的彩色图标 */
if (!prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) return@safeRun
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
/** 新版风格反色 */
val newStyle = if (context.isSystemInDarkMode) 0xFF2D2D2D.toInt() else Color.WHITE
/** 新版风格反色 */
val newStyle = if (context.isSystemInDarkMode) 0xFF2D2D2D.toInt() else Color.WHITE
/** 旧版风格反色 */
val oldStyle = if (context.isNotSystemInDarkMode) 0xFF707070.toInt() else Color.WHITE
/** 旧版风格反色 */
val oldStyle = if (context.isNotSystemInDarkMode) 0xFF707070.toInt() else Color.WHITE
/** 通知图标原始颜色 */
val iconColor = notifyInstance.notification.color
/** 通知图标原始颜色 */
val iconColor = notifyInstance.notification.color
/** 是否有通知栏图标颜色 */
val hasIconColor = iconColor != 0
/** 是否有通知栏图标颜色 */
val hasIconColor = iconColor != 0
/** 通知图标适配颜色 */
val supportColor = iconColor.let {
when {
isUpperOfAndroidS -> newStyle
it == 0 -> oldStyle
else -> it
}
/** 通知图标适配颜色 */
val supportColor = iconColor.let {
when {
isUpperOfAndroidS -> newStyle
it == 0 || !isExpanded -> oldStyle
else -> it
}
}
/** 获取通知小图标 */
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
/** 获取通知小图标 */
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
/** 判断图标风格 */
val isGrayscaleIcon = !notifyInstance.isXmsf && isGrayscaleIcon(context, iconDrawable)
/** 判断图标风格 */
val isGrayscaleIcon = !notifyInstance.isXmsf && isGrayscaleIcon(context, iconDrawable)
/** 自定义默认小图标 */
var customIcon: Bitmap? = null
/** 自定义默认小图标 */
var customIcon: Bitmap?
/** 自定义默认小图标颜色 */
var customIconColor = 0
if (isNotifyIconFix) run {
if (iconDatas.isNotEmpty())
iconDatas.forEach {
if ((notifyInstance.opPkgName == it.packageName ||
findAppName(notifyInstance) == it.appName) &&
isAppNotifyHookOf(it)
) {
if (!isGrayscaleIcon || isAppNotifyHookAllOf(it)) {
customIcon = it.iconBitmap
customIconColor = it.iconColor
return@run
}
}
}
/** 自定义默认小图标颜色 */
var customIconColor: Int
compatCustomIcon(isGrayscaleIcon, notifyInstance.opPkgName).also {
customIcon = it.first
customIconColor = if (isUpperOfAndroidS || isExpanded) it.second else 0
}
/** 打印日志 */
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()
}
/** 处理自定义通知图标优化 */
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 {
/** 重新设置图标 - 防止系统更改它 */
iconImageView.setImageDrawable(iconDrawable)
/** 判断如果是灰度图标就给他设置一个白色颜色遮罩 */
if (isGrayscaleIcon) iconImageView.apply {
/** 设置图标着色 */
setColorFilter(supportColor)
/** Android 12 设置图标外圈颜色 */
if (isUpperOfAndroidS && hasIconColor)
background = DrawableBuilder().rounded().solidColor(iconColor).build()
} else iconImageView.apply {
/** 重新设置图标 */
setImageDrawable(notifyInstance.compatNotifyIcon(context, iconDrawable))
/** 设置裁切到边界 */
clipToOutline = true
/** 设置一个圆角轮廓裁切 */
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, out: Outline) {
out.setRoundRect(
0, 0,
view.width, view.height, 5.dp(context)
)
}
else {
/** 重新设置图标 - 防止系统更改它 */
iconImageView.setImageDrawable(iconDrawable)
/** 判断如果是灰度图标就给他设置一个白色颜色遮罩 */
if (isGrayscaleIcon) iconImageView.apply {
/** 设置图标着色 */
setColorFilter(supportColor)
/** Android 12 设置图标外圈颜色 */
if (isUpperOfAndroidS && hasIconColor)
background = DrawableBuilder().rounded().solidColor(iconColor).build()
} else iconImageView.apply {
/** 重新设置图标 */
setImageDrawable(notifyInstance.compatNotifyIcon(context, iconDrawable))
/** 设置裁切到边界 */
clipToOutline = true
/** 设置一个圆角轮廓裁切 */
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, out: Outline) {
out.setRoundRect(
0, 0,
view.width, view.height, 5.dp(context)
)
}
/** 清除原生的背景边距设置 */
if (isUpperOfAndroidS) setPadding(0, 0, 0, 0)
/** 清除原生的主题色背景圆圈颜色 */
if (isUpperOfAndroidS) background = null
}
/** 清除原生的背景边距设置 */
if (isUpperOfAndroidS) setPadding(0, 0, 0, 0)
/** 清除原生的主题色背景圆圈颜色 */
if (isUpperOfAndroidS) background = null
}
}
}
}
/**
* Hook 通知栏小图标颜色
@@ -381,39 +442,26 @@ class HookEntry : YukiHookXposedInitProxy {
* @return [Boolean] 是否忽略通知图标颜色
*/
private fun PackageParam.hookIgnoreStatusBarIconColor(context: Context, expandedNf: StatusBarNotification?) =
if (prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) safeOfFalse {
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
expandedNf?.let { notifyInstance ->
/** 获取通知小图标 */
val iconDrawable =
notifyInstance.notification.smallIcon.loadDrawable(context)
if (!context.isMiuiNotifyStyle)
if (prefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)) 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 */
var isTargetFixApp = false
/** 如果开启了自定义通知图标优化 */
if (prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true))
run {
if (iconDatas.isNotEmpty())
iconDatas.forEach {
if ((notifyInstance.opPkgName == it.packageName ||
findAppName(notifyInstance) == it.appName) &&
isAppNotifyHookOf(it)
) {
if (isNotGrayscaleIcon || isAppNotifyHookAllOf(it)) isTargetFixApp = true
return@run
}
}
}
/**
* 只要不是灰度就返回彩色图标
* 否则不对颜色进行反色处理防止一些系统图标出现异常
*/
if (isTargetFixApp) false else isNotGrayscaleIcon
} ?: true
} else false
/** 获取目标修复彩色图标的 APP */
val isTargetFixApp = compatCustomIcon(!isNotGrayscaleIcon, notifyInstance.opPkgName).first != null
/**
* 只要不是灰度就返回彩色图标
* 否则不对颜色进行反色处理防止一些系统图标出现异常
*/
if (isTargetFixApp) false else isNotGrayscaleIcon
} ?: true
} else false
else true
override fun onHook() = encase {
configs {
@@ -443,10 +491,10 @@ class HookEntry : YukiHookXposedInitProxy {
param(ExpandedNotificationClass.clazz)
}
/**
* 因为之前的 MIUI 版本的状态栏图标颜色会全部设置为白色的 - 找不到修复的地方就直接判断版本了
* 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook
* 为了防止 MIUI 自身的版本不同造成的各种 BUG
* 判断是 MIUI 样式就停止 Hook
*/
replaceAny { if (hasIgnoreStatusBarIconColor) false else isShowMiuiStyle }
replaceAny { globalContext?.isMiuiNotifyStyle ?: isShowMiuiStyle }
}
if (hasIgnoreStatusBarIconColor)
injectMember {
@@ -478,86 +526,86 @@ class HookEntry : YukiHookXposedInitProxy {
}.onFind { isUseLegacy = true }
}
afterHook {
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
if (hasIgnoreStatusBarIconColor || !isShowMiuiStyle)
(globalContext ?: args[0] as Context).also { context ->
hookSmallIconOnSet(
context = context,
args[if (isUseLegacy) 1 else 0] as? StatusBarNotification?,
(result as Icon).loadDrawable(context)
) { icon -> result = Icon.createWithBitmap(icon) }
}
(globalContext ?: args[0] as Context).also { context ->
hookSmallIconOnSet(
context = context,
args[if (isUseLegacy) 1 else 0] as? StatusBarNotification?,
(result as Icon).loadDrawable(context)
) { icon -> result = Icon.createWithBitmap(icon) }
}
}
}
}
if (NotificationHeaderViewWrapperInjectorClass.hasClass)
NotificationHeaderViewWrapperInjectorClass.hook {
/** 修复下拉通知图标自动设置回 APP 图标的方法 */
injectMember {
var isUseLegacy = false
NotificationHeaderViewWrapperClass.hook {
/** 修复下拉通知图标自动设置回 APP 图标的方法 */
injectMember {
if (hasHandleHeaderViews)
method { name = "handleHeaderViews" }
else method { name = "resolveHeaderViews" }
afterHook {
/** 获取小图标 */
val iconImageView =
NotificationHeaderViewWrapperClass.clazz
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
/** 通知是否展开 */
var isExpanded = false
/**
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
* 获取其中的得到通知方法
*/
val expandedNf = ExpandableNotificationRowClass.clazz
.method { name = "getEntry" }
.get(NotificationViewWrapperClass.clazz.field {
name = "mRow"
}.get(instance).self?.also {
isExpanded = ExpandableNotificationRowClass.clazz.method {
name = "isExpanded"
returnType = BooleanType
}.get(it).invoke<Boolean>() == true
}).call()?.let {
it.javaClass.method {
name = "getSbn"
}.get(it).invoke<StatusBarNotification>()
} ?: ExpandableNotificationRowClass.clazz
.method { name = "getStatusBarNotification" }
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
.invoke<StatusBarNotification>()
/** 获取优先级 */
val importance =
(iconImageView.context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager?)
?.getNotificationChannel(expandedNf?.notification?.channelId)?.importance ?: 0
/** 非最小化优先级的通知全部设置为展开状态 */
if (importance != 1) isExpanded = true
/** 执行 Hook */
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView, isExpanded)
}
}
}
/** 干掉下拉通知图标自动设置回 APP 图标的方法 */
NotificationHeaderViewWrapperInjectorClass.hook {
injectMember {
method {
name = "setAppIcon"
param(ContextClass, ImageViewClass, ExpandedNotificationClass.clazz)
}.remedys {
method {
name = "setAppIcon"
param(ContextClass, ImageViewClass, ExpandedNotificationClass.clazz)
}.remedys {
method {
name = "setAppIcon"
param(ImageViewClass, ExpandedNotificationClass.clazz)
}.onFind { isUseLegacy = true }
}
replaceUnit {
if (isUseLegacy)
hookNotifyIconOnSet(
context = globalContext ?: error("GlobalContext got null"),
args[1] as? StatusBarNotification?,
args[0] as ImageView
)
else
hookNotifyIconOnSet(
context = args[0] as? Context ?: globalContext ?: error("GlobalContext got null"),
args[2] as? StatusBarNotification?,
args[1] as ImageView
)
param(ImageViewClass, ExpandedNotificationClass.clazz)
}
}
/** 干掉下拉通知图标自动设置回 APP 图标的方法 - Android 12 */
if (isUpperOfAndroidS)
injectMember {
method {
name = "resetIconBgAndPaddings"
param(ImageViewClass, ExpandedNotificationClass.clazz)
}
intercept()
}
}
else
NotificationHeaderViewWrapperClass.hook {
/** 之前的版本解决方案 */
injectMember {
method { name = "handleHeaderViews" }
afterHook {
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
if (!hasIgnoreStatusBarIconColor && isShowMiuiStyle) return@afterHook
/** 获取小图标 */
val iconImageView =
NotificationHeaderViewWrapperClass.clazz
.field { name = "mIcon" }.of<ImageView>(instance) ?: return@afterHook
/**
* 从父类中得到 mRow 变量 - [ExpandableNotificationRowClass]
* 获取其中的得到通知方法
*/
val expandedNf =
ExpandableNotificationRowClass.clazz
.method { name = "getStatusBarNotification" }
.get(NotificationViewWrapperClass.clazz.field { name = "mRow" }.get(instance).self)
.invoke<StatusBarNotification>()
/** 执行 Hook */
hookNotifyIconOnSet(iconImageView.context, expandedNf, iconImageView)
}
intercept()
}.ignoredAllFailure()
injectMember {
method {
name = "resetIconBgAndPaddings"
param(ImageViewClass, ExpandedNotificationClass.clazz)
}
}
intercept()
}.ignoredAllFailure()
}
}
}
}

View File

@@ -27,6 +27,7 @@ import android.graphics.Color
import com.fankes.miui.notify.bean.IconDataBean
import com.fankes.miui.notify.hook.HookConst.NOTIFY_ICON_DATAS
import com.fankes.miui.notify.utils.bitmap
import com.fankes.miui.notify.utils.safeOf
import com.fankes.miui.notify.utils.safeOfNan
import com.highcapable.yukihookapi.hook.factory.modulePrefs
import com.highcapable.yukihookapi.hook.param.PackageParam
@@ -50,16 +51,12 @@ class IconPackParams(private val context: Context? = null, private val param: Pa
/**
* 获取图标数据
*
* 通知栏小图标数组
*
* 默认使用包名进行匹配 - 若失败则使用 APP 名称进行匹配
* @return [Array]
* @return [Array] 通知栏小图标数组
*/
val iconDatas
get() = ArrayList<IconDataBean>().apply {
storageDataJson?.also {
if (it.isNotBlank())
if (it.isNotBlank()) runCatching {
JSONArray(it).also { array ->
for (i in 0 until array.length()) runCatching {
(array.get(i) as JSONObject).apply {
@@ -77,9 +74,20 @@ class IconPackParams(private val context: Context? = null, private val param: Pa
}
}
}
}
}
}
/**
* 拼接图标数组数据
* @param dataJson1 图标数据 JSON
* @param dataJson2 图标数据 JSON
* @return [String] 拼接后的数据
*/
fun splicingJsonArray(dataJson1: String, dataJson2: String) = safeOf(default = "[]") {
dataJson1.replace(oldValue = "]", newValue = "") + "," + dataJson2.replace(oldValue = "[", newValue = "")
}
/**
* 比较图标数据不相等
* @param dataJson 图标数据 JSON

View File

@@ -195,7 +195,7 @@ class ConfigureActivity : BaseActivity() {
runCatching {
startActivity(Intent().apply {
action = "android.intent.action.VIEW"
data = Uri.parse("https://github.com/fankes/MIUINativeNotifyIcon/blob/master/CONTRIBUTING.md")
data = Uri.parse("https://github.com/fankes/AndroidNotifyIconAdapt/blob/main/CONTRIBUTING.md")
/** 防止顶栈一样重叠在自己的 APP 中 */
flags = Intent.FLAG_ACTIVITY_NEW_TASK
})
@@ -221,45 +221,45 @@ class ConfigureActivity : BaseActivity() {
title = if (iconAllDatas.isNotEmpty()) "同步列表" else "初始化"
msg = (if (iconAllDatas.isNotEmpty()) "建议定期从云端拉取数据以获得最新的通知图标优化名单适配数据。\n\n"
else "首次装载需要从云端下载最新适配数据,后续可继续前往这里检查更新。\n\n") +
"[Github] 同步最新数据,无法连接可能需要魔法上网。\n\n[Surge] 缓存 CDN 数据,可以直连,但数据可能会有更新延迟。\n\n" +
"如果以上地址均无法使用,建议魔法上网或修改 Host 文件直连。"
confirmButton(text = "Surge") {
onRefreshing(url = "https://fankes.mnn.surge.sh/NotifyIconsSupportConfig.json")
}
cancelButton(text = "Github") {
onRefreshing(url = "https://raw.githubusercontent.com/fankes/MIUINativeNotifyIcon/master/iconPack/NotifyIconsSupportConfig.json")
}
neutralButton(text = "取消")
"通过从 Github 同步最新数据,无法连接可能需要魔法上网。"
confirmButton(text = "开始同步") { onRefreshing() }
cancelButton()
}
/**
* 开始更新数据
* @param url 使用的地址
*/
private fun onRefreshing(url: String) {
/** 开始更新数据 */
private fun onRefreshing() {
ProgressDialog(this).apply {
setDefaultStyle(context = this@ConfigureActivity)
setCancelable(false)
setTitle("同步中")
setMessage("正在同步云端数据")
setMessage("正在同步 OS 数据")
show()
}.also {
ClientRequestTool.wait(context = this, url) { isDone, content ->
it.cancel()
IconPackParams(context = this).also { params ->
if (isDone)
if (params.isCompareDifferent(content)) {
params.save(content)
filterText = ""
mockLocalData()
SystemUITool.showNeedUpdateApplySnake(context = this)
} else snake(msg = "列表数据已是最新")
else
showDialog {
title = "连接失败"
msg = "连接失败,错误如下:\n$content"
confirmButton(text = "我知道了")
}
ClientRequestTool.wait(
context = this,
url = "https://raw.githubusercontent.com/fankes/AndroidNotifyIconAdapt/main/OS/MIUI/NotifyIconsSupportConfig.json"
) { isDone1, ctOS ->
it.setMessage("正在同步 APP 数据")
ClientRequestTool.wait(
context = this,
url = "https://raw.githubusercontent.com/fankes/AndroidNotifyIconAdapt/main/APP/NotifyIconsSupportConfig.json"
) { isDone2, ctAPP ->
it.cancel()
IconPackParams(context = this).also { params ->
if (isDone1 && isDone2) params.splicingJsonArray(ctOS, ctAPP).also {
if (params.isCompareDifferent(it)) {
params.save(it)
filterText = ""
mockLocalData()
SystemUITool.showNeedUpdateApplySnake(context = this)
} else snake(msg = "列表数据已是最新")
} else
showDialog {
title = "连接失败"
msg = "连接失败,错误如下:\n${if (!isDone1) ctOS else ctAPP}"
confirmButton(text = "我知道了")
}
}
}
}
}

View File

@@ -93,11 +93,7 @@ class MainActivity : BaseActivity() {
noCancelable()
}
/** 判断是否 Hook */
YukiHookModuleStatus.isActive() -> {
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.bg_green_round)
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.ic_success)
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
}
YukiHookModuleStatus.isActive() -> {}
else ->
showDialog {
title = "模块没有激活"
@@ -208,16 +204,56 @@ class MainActivity : BaseActivity() {
}
}
/** 刷新模块状态 */
private fun refreshModuleStatus() {
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(
when {
YukiHookModuleStatus.isActive() && isMiuiNotifyStyle -> R.drawable.bg_yellow_round
YukiHookModuleStatus.isActive() -> R.drawable.bg_green_round
else -> R.drawable.bg_dark_round
}
)
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(
when {
YukiHookModuleStatus.isActive() && !isMiuiNotifyStyle -> R.mipmap.ic_success
else -> R.mipmap.ic_warn
}
)
findViewById<TextView>(R.id.main_text_status).text =
when {
YukiHookModuleStatus.isActive() && isMiuiNotifyStyle -> "模块已激活,但未在工作"
YukiHookModuleStatus.isActive() -> "模块已激活"
else -> "模块未激活"
}
}
override fun onResume() {
super.onResume()
/** MIUI 12 的版本特殊 - 所以给出提示 */
if (!isWarnDialogShowing && YukiHookModuleStatus.isActive() && miuiVersion == "12" && isMiuiNotifyStyle)
/** 刷新模块状态 */
refreshModuleStatus()
/** 经典样式启用后给出警告 */
if (!isWarnDialogShowing && YukiHookModuleStatus.isActive() && isMiuiNotifyStyle)
showDialog {
isWarnDialogShowing = true
title = "经典通知栏样式已启用"
msg = "在 MIUI 12 中启用了经典通知栏样式后状态栏图标将不再做原生处理,模块停止工作," +
"这取决于系统设置,你应当在 设置>通知管理>通知显示设置 中将样式设置为“原生样式”。"
confirmButton(text = "我知道了") { isWarnDialogShowing = false }
msg = "当你启用了经典通知栏样式后,为防止 MIUI 自身不规范 APP 图标被破坏,状态栏图标将不再做原生处理\n\n" +
"若要使用原生样式,请前往 设置>通知管理>通知显示设置 中将样式设置为“原生样式”,新版本为 设置>通知与控制中心>通知显示设置"
confirmButton(text = "去设置") {
runCatching {
startActivity(Intent().apply {
component = ComponentName(
"com.miui.notification",
"miui.notification.management.activity.NotificationDisplaySettingsActivity"
)
/** 防止顶栈一样重叠在自己的 APP 中 */
flags = Intent.FLAG_ACTIVITY_NEW_TASK
})
}.onFailure {
toast(msg = "启动失败,请手动调整设置")
}
isWarnDialogShowing = false
}
cancelButton { isWarnDialogShowing = false }
noCancelable()
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF9800" />
<corners android:radius="15dp" />
</shape>

View File

@@ -76,7 +76,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="模块未激活"
android:text="模块状态未知"
android:textColor="@color/white"
android:textSize="18sp" />

View File

@@ -5,8 +5,8 @@ plugins {
}
ext {
appVersionName = "1.8"
appVersionCode = 17
appVersionName = "1.86"
appVersionCode = 19
}
task clean(type: Delete) {

File diff suppressed because it is too large Load Diff

Binary file not shown.