mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-07 03:05:51 +08:00
完全修复 MIUI 12 状态栏小图标无法对 MIPUSH 生效的问题,优化 MIPUSH 未经过适配的图标为 APP 图标包的图标
This commit is contained in:
@@ -28,6 +28,7 @@ import android.graphics.Color
|
|||||||
import android.graphics.Outline
|
import android.graphics.Outline
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
|
import android.os.Build
|
||||||
import android.service.notification.StatusBarNotification
|
import android.service.notification.StatusBarNotification
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewOutlineProvider
|
import android.view.ViewOutlineProvider
|
||||||
@@ -139,11 +140,56 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
ExpandedNotificationClass.clazz.method(name = "getAppName")?.call(instance) ?: "<empty>"
|
ExpandedNotificationClass.clazz.method(name = "getAppName")?.call(instance) ?: "<empty>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 适配通知栏、状态栏图标
|
||||||
|
*
|
||||||
|
* 适配第三方图标包对系统包管理器更换图标后的彩色图标
|
||||||
|
*
|
||||||
|
* 自动识别 MIPUSH 图标
|
||||||
|
* @param context 实例
|
||||||
|
* @param iconDrawable 原始图标
|
||||||
|
* @return [Drawable] 适配的图标
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
else iconDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取推送通知的包名
|
||||||
|
*
|
||||||
|
* 自动兼容旧版本系统
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
private val StatusBarNotification.compatOpPkgName
|
||||||
|
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) opPkg else packageName ?: ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断通知是否来自 MIPUSH
|
* 判断通知是否来自 MIPUSH
|
||||||
* @return [Boolean]
|
* @return [Boolean]
|
||||||
*/
|
*/
|
||||||
private val StatusBarNotification.isXmsf get() = opPkgName == "com.xiaomi.xmsf"
|
private val StatusBarNotification.isXmsf get() = compatOpPkgName == "com.xiaomi.xmsf"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取推送通知的包名
|
||||||
|
*
|
||||||
|
* 自动判断 MIPUSH
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
private val StatusBarNotification.opPkgName get() = if (isXmsf) xmsfPkgName else compatOpPkgName
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 MIPUSH 通知真实包名
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
private val StatusBarNotification.xmsfPkgName: String
|
||||||
|
get() {
|
||||||
|
val xmsfPkg = notification.extras.getString("xmsf_target_package") ?: ""
|
||||||
|
val targetPkg = notification.extras.getString("target_package") ?: ""
|
||||||
|
return xmsfPkg.ifBlank { targetPkg.ifBlank { compatOpPkgName } }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全局上下文
|
* 获取全局上下文
|
||||||
@@ -196,7 +242,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
/** 如果开启了修复 APP 的彩色图标 */
|
/** 如果开启了修复 APP 的彩色图标 */
|
||||||
customIcon != null && prefs.getBoolean(ENABLE_NOTIFY_ICON_HOOK, default = true) -> it(customIcon!!)
|
customIcon != null && prefs.getBoolean(ENABLE_NOTIFY_ICON_HOOK, default = true) -> it(customIcon!!)
|
||||||
/** 若不是灰度图标自动处理为圆角 */
|
/** 若不是灰度图标自动处理为圆角 */
|
||||||
isNotGrayscaleIcon -> it(iconDrawable.toBitmap().round(15.dp(context)))
|
isNotGrayscaleIcon -> it(expandedNf.compatNotifyIcon(context, iconDrawable).toBitmap().round(15.dp(context)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,6 +333,9 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
if (isUpperOfAndroidS && hasIconColor)
|
if (isUpperOfAndroidS && hasIconColor)
|
||||||
background = DrawableBuilder().rounded().solidColor(iconColor).build()
|
background = DrawableBuilder().rounded().solidColor(iconColor).build()
|
||||||
} else iconImageView.apply {
|
} else iconImageView.apply {
|
||||||
|
/** 重新设置图标 */
|
||||||
|
setImageDrawable(expandedNf.compatNotifyIcon(context, iconDrawable))
|
||||||
|
/** 设置裁切到边界 */
|
||||||
clipToOutline = true
|
clipToOutline = true
|
||||||
/** 设置一个圆角轮廓裁切 */
|
/** 设置一个圆角轮廓裁切 */
|
||||||
outlineProvider = object : ViewOutlineProvider() {
|
outlineProvider = object : ViewOutlineProvider() {
|
||||||
@@ -434,16 +483,18 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
/** 获取通知实例 */
|
/** 获取通知实例 */
|
||||||
val expandedNf = field { name = "mNotification" }.of<StatusBarNotification>(instance)
|
val expandedNf = field { name = "mNotification" }.of<StatusBarNotification>(instance)
|
||||||
|
|
||||||
|
/** 对于之前没有通知图标色彩判断功能的版本判断是 MIUI 样式就停止 Hook */
|
||||||
|
if (!hasIgnoreStatusBarIconColor() && isShowMiuiStyle()) return@afterHook
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 强制设置图标 - 防止 MIPUSH 不生效
|
* 强制重新进行设置图标
|
||||||
* 由于之前版本没有 [hasIgnoreStatusBarIconColor] 判断 - MIPUSH 的图标颜色也是白色的
|
* 防止 MIPUSH 不生效
|
||||||
* 所以之前的版本取消这个 Hook - 实在找不到设置图标的地方 - 状态栏图标就彩色吧
|
|
||||||
*/
|
*/
|
||||||
if (hasIgnoreStatusBarIconColor() && expandedNf?.isXmsf == true)
|
if (expandedNf?.isXmsf == true)
|
||||||
hookSmallIconOnSet(
|
hookSmallIconOnSet(
|
||||||
context = iconImageView.context,
|
context = iconImageView.context,
|
||||||
expandedNf,
|
expandedNf,
|
||||||
expandedNf.notification?.smallIcon?.loadDrawable(iconImageView.context)
|
expandedNf.notification?.smallIcon?.loadDrawable(iconImageView.context),
|
||||||
) { icon -> iconImageView.setImageBitmap(icon) }
|
) { icon -> iconImageView.setImageBitmap(icon) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1065,30 +1065,6 @@ object IconPackParams {
|
|||||||
iconColor = 0xff4478ee.toInt(),
|
iconColor = 0xff4478ee.toInt(),
|
||||||
contributorName = "fankes"
|
contributorName = "fankes"
|
||||||
),
|
),
|
||||||
IconDataBean(
|
|
||||||
isEnabled = true,
|
|
||||||
isEnabledAll = false,
|
|
||||||
appName = "阅读",
|
|
||||||
packageName = "com.duokan.reader",
|
|
||||||
iconBitmap = ("iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARzQklUCAgI\n" +
|
|
||||||
"CHwIZIgAAAMYSURBVGiB7ZrPq1RlGMc/z7gR8se2gshUyrJFdMlcRFx0YwsthBZhiEElIiX2D+RC\n" +
|
|
||||||
"ECJqU6AXFSIkcKUFZRCMkvYD0ZWLCqmNGWpBCtoPF58WM9Iw3jnnPe85d8696AfOZu7zPOf7mZn3\n" +
|
|
||||||
"nHdmbjCEugB4GXgaeApYOVzTEj8BZ4EfgKmI+G1kpbpLPe/s51f17VESW9tOl8HUsMSGthPVYDdA\n" +
|
|
||||||
"9EW+AtY28k4eP/8CT8xTXwV2tJ2mBvOAqx1gRdtJGuD5DjDRdooGWBnqNWBhQvGfwHHge+BC/9hE\n" +
|
|
||||||
"b209NGMRU0m8MnTVBwpm7Gz4StRVJweObllDisi5xCekyUt4d2h2qUinJN8/wOYUkYj4FNifUjsT\n" +
|
|
||||||
"lIm8FxFnU4dFxGv01tHYKRM5mDHzRE6QuhSKRMT5jJmz8hWZMxSKqE+OK0hdyl6RNRkzX88JUpcy\n" +
|
|
||||||
"kUo7YnUCeCk/Tj5lIuvUvRXmfVQnTB1SFvtWdVdRgbpIPUmbn++rbBvUyaHeJeoO9UrVPUjThGpF\n" +
|
|
||||||
"99+BK8AlYLKkdmzkiMxK7owb4lzirshsYy6IXEspKhP5JQpoIGQZr0TEYuBMaWXCvWZDQe+RGbzH\n" +
|
|
||||||
"He2f45GU4pS31vqCvx1K6M/l/YTz/0+C7CV1cUH/6TpP+wg+HJh/IqUhda/1ZoHIhHohN/E0XFaX\n" +
|
|
||||||
"9WevSm1KFbmsPlogs0a9UT3zbVxUnxuY+0VqY5Xdb+F6UDeq5yoGH+SU+vjAvN1VmquIqG4pkVlk\n" +
|
|
||||||
"7+e7qxVm/qF+4MA6VF+smKuyiOr2Ipl+kMfUd9TP+0Gn4zt1s7pwqLeyRK6I6p4ymaFwy9XV6gr1\n" +
|
|
||||||
"XnX+iLosiToiqofsfdlQG/U+9d0aWWqJ3GJfrpC6QN2u/lw3RJOfEKeAL4FjEXGjROBZYGP/GPm7\n" +
|
|
||||||
"SxVC/RF4uIlhff4Gvga+GXr8QWA5sBS4v8HzAT2Rj+n9y8acpgOcajtEA3wW6j3AMeCZttNk8hew\n" +
|
|
||||||
"thMR14G3gJstB8rljYj4tgMQEaeBbS0HymFvRBy47VF1nfpJ3Wv6GOhasu+7JbRaPdxy2Onoqi9M\n" +
|
|
||||||
"l/k/quraov1V/EcAAAAASUVORK5CYII=").bitmap,
|
|
||||||
iconColor = 0xfff28b3f.toInt(),
|
|
||||||
contributorName = "fankes"
|
|
||||||
),
|
|
||||||
IconDataBean(
|
IconDataBean(
|
||||||
isEnabled = true,
|
isEnabled = true,
|
||||||
isEnabledAll = false,
|
isEnabledAll = false,
|
||||||
|
@@ -115,8 +115,6 @@ class MainActivity : BaseActivity() {
|
|||||||
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
|
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
|
||||||
val colorIconHookSwitch = findViewById<SwitchCompat>(R.id.color_icon_fix_switch)
|
val colorIconHookSwitch = findViewById<SwitchCompat>(R.id.color_icon_fix_switch)
|
||||||
val notifyIconHookSwitch = findViewById<SwitchCompat>(R.id.notify_icon_fix_switch)
|
val notifyIconHookSwitch = findViewById<SwitchCompat>(R.id.notify_icon_fix_switch)
|
||||||
/** 设置旧版本警告 */
|
|
||||||
findViewById<View>(R.id.config_notify_app_icon_warn).isVisible = miuiVersion == "12"
|
|
||||||
/** 获取 Sp 存储的信息 */
|
/** 获取 Sp 存储的信息 */
|
||||||
notifyIconConfigItem.isVisible = modulePrefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)
|
notifyIconConfigItem.isVisible = modulePrefs.getBoolean(ENABLE_COLOR_ICON_HOOK, default = true)
|
||||||
moduleEnableLogSwitch.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
|
moduleEnableLogSwitch.isVisible = modulePrefs.getBoolean(ENABLE_MODULE, default = true)
|
||||||
|
@@ -33,7 +33,6 @@ import android.graphics.*
|
|||||||
import android.graphics.Bitmap.createBitmap
|
import android.graphics.Bitmap.createBitmap
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.service.notification.StatusBarNotification
|
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
|
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
|
||||||
@@ -148,12 +147,6 @@ val miuiFullVersion
|
|||||||
get() = if (isMIUI) (miuiVersion + " " + findPropString(key = "ro.system.build.version.incremental"))
|
get() = if (isMIUI) (miuiVersion + " " + findPropString(key = "ro.system.build.version.incremental"))
|
||||||
else "不是 MIUI 系统"
|
else "不是 MIUI 系统"
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取推送通知的包名
|
|
||||||
* @return [String]
|
|
||||||
*/
|
|
||||||
val StatusBarNotification.opPkgName get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) opPkg else packageName ?: ""
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到安装包信息
|
* 得到安装包信息
|
||||||
* @return [PackageInfo]
|
* @return [PackageInfo]
|
||||||
|
@@ -269,20 +269,6 @@
|
|||||||
android:text="此选项默认开启,开启后将对优化名单内 APP 通知小图标进行色彩修复,特别是通过 MIPUSH 推送的通知,它们始终是彩色的,修复后使得它们的图标看起来更加符合原生规范。"
|
android:text="此选项默认开启,开启后将对优化名单内 APP 通知小图标进行色彩修复,特别是通过 MIPUSH 推送的通知,它们始终是彩色的,修复后使得它们的图标看起来更加符合原生规范。"
|
||||||
android:textColor="@color/colorTextDark"
|
android:textColor="@color/colorTextDark"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/config_notify_app_icon_warn"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:layout_marginRight="5dp"
|
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:alpha="0.6"
|
|
||||||
android:lineSpacingExtra="6dp"
|
|
||||||
android:text="⚠️ 你的 MIUI 版本过低,状态栏上 MIPUSH 的彩色图标由于不能识别反色将不会被优化为黑白小图标,仅在通知栏生效。"
|
|
||||||
android:textColor="#FF9800"
|
|
||||||
android:textSize="12sp"
|
|
||||||
android:visibility="gone" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
Reference in New Issue
Block a user