mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-05 18:25:23 +08:00
适配最低基于 Android 9 的 MIUI
This commit is contained in:
@@ -19,7 +19,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.fankes.miui.notify"
|
||||
minSdk 29
|
||||
minSdk 26
|
||||
targetSdk 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
@@ -25,7 +25,6 @@ package com.fankes.miui.notify.hook
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Outline
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.Icon
|
||||
import android.service.notification.StatusBarNotification
|
||||
@@ -34,6 +33,7 @@ import android.view.View
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.Keep
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.fankes.miui.notify.hook.HookMedium.QQ_PACKAGE_NAME
|
||||
import com.fankes.miui.notify.hook.HookMedium.SELF_PACKAGE_NAME
|
||||
@@ -165,7 +165,7 @@ class HookMain : IXposedHookLoadPackage {
|
||||
/** 判断要设置的图标 */
|
||||
when {
|
||||
/** 如果开启了修复聊天 APP 的图标 */
|
||||
notifyInstance.opPkg == QQ_PACKAGE_NAME &&
|
||||
notifyInstance.packageName == QQ_PACKAGE_NAME &&
|
||||
XPrefUtils.getBoolean(
|
||||
HookMedium.ENABLE_CHAT_ICON_HOOK,
|
||||
default = true
|
||||
@@ -206,14 +206,14 @@ class HookMain : IXposedHookLoadPackage {
|
||||
val iconDrawable = notifyInstance.notification.smallIcon.loadDrawable(context)
|
||||
|
||||
/** 获取发送通知的 APP */
|
||||
val packageName = notifyInstance.opPkg
|
||||
val packageName = notifyInstance.packageName
|
||||
/** 如果开启了修复聊天 APP 的图标 */
|
||||
if (packageName == QQ_PACKAGE_NAME &&
|
||||
XPrefUtils.getBoolean(HookMedium.ENABLE_CHAT_ICON_HOOK, default = true)
|
||||
)
|
||||
iconImageView.apply {
|
||||
/** 设置自定义小图标 */
|
||||
setImageDrawable(BitmapDrawable(IconPackParams.qqSmallIcon))
|
||||
setImageBitmap(IconPackParams.qqSmallIcon)
|
||||
/** 上色 */
|
||||
setColorFilter(if (isUpperOfAndroidS) newStyle else oldStyle)
|
||||
}
|
||||
@@ -262,6 +262,8 @@ class HookMain : IXposedHookLoadPackage {
|
||||
SYSTEMUI_PACKAGE_NAME -> {
|
||||
/** 若不是 MIUI 系统直接停止 Hook */
|
||||
if (isNotMIUI) return
|
||||
/** 系统版本过低直接停止 Hook */
|
||||
if (isLowerAndroidP) return
|
||||
/** 若没开启模块直接停止 Hook */
|
||||
if (!XPrefUtils.getBoolean(HookMedium.ENABLE_MODULE, default = true)) return
|
||||
/** 强制回写系统的状态栏图标样式为原生 */
|
||||
@@ -288,8 +290,8 @@ class HookMain : IXposedHookLoadPackage {
|
||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||
(param.args?.get(0) as? StatusBarNotification?)?.let { notifyInstance ->
|
||||
/** 获取发送通知的 APP */
|
||||
val packageName = notifyInstance.opPkg
|
||||
|
||||
val packageName = notifyInstance.packageName
|
||||
NotificationCompat()
|
||||
/** 获取通知小图标 */
|
||||
val iconDrawable =
|
||||
notifyInstance.notification.smallIcon.loadDrawable(lpparam.globalContext)
|
||||
|
@@ -76,8 +76,9 @@ class MainActivity : AppCompatActivity() {
|
||||
/** 设置文本 */
|
||||
findViewById<TextView>(R.id.main_text_version).text = "当前版本:$moduleVersion"
|
||||
findViewById<TextView>(R.id.main_text_miui_version).text = "MIUI 版本:$miuiVersion"
|
||||
when {
|
||||
/** 判断是否为 MIUI 系统 */
|
||||
if (isNotMIUI) {
|
||||
isNotMIUI ->
|
||||
showDialog {
|
||||
title = "不是 MIUI 系统"
|
||||
msg = "此模块专为 MIUI 系统打造,当前无法识别你的系统为 MIUI,所以模块无法工作。\n" +
|
||||
@@ -85,14 +86,22 @@ class MainActivity : AppCompatActivity() {
|
||||
confirmButton(text = "退出") { finish() }
|
||||
noCancelable()
|
||||
}
|
||||
return
|
||||
/** 判断最低系统版本 */
|
||||
isLowerAndroidP ->
|
||||
showDialog {
|
||||
title = "系统版本过低"
|
||||
msg = "此模块最低支持基于 Android 9 的 MIUI 系统,你的系统版本过低不再进行适配。\n" +
|
||||
"如有问题请联系 酷安 @星夜不荟"
|
||||
confirmButton(text = "退出") { finish() }
|
||||
noCancelable()
|
||||
}
|
||||
/** 判断 Hook 状态 */
|
||||
if (isHooked()) {
|
||||
/** 判断是否 Hook */
|
||||
isHooked() -> {
|
||||
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.green_round)
|
||||
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.succcess)
|
||||
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
|
||||
} else
|
||||
}
|
||||
else ->
|
||||
showDialog {
|
||||
title = "模块没有激活"
|
||||
msg = "检测到模块没有激活,模块需要 Xposed 环境依赖," +
|
||||
@@ -102,6 +111,7 @@ class MainActivity : AppCompatActivity() {
|
||||
confirmButton(text = "我知道了")
|
||||
noCancelable()
|
||||
}
|
||||
}
|
||||
/** 初始化 View */
|
||||
val moduleEnableSwitch = findViewById<SwitchCompat>(R.id.module_enable_switch)
|
||||
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
|
||||
|
@@ -65,6 +65,12 @@ inline val Context.isNotSystemInDarkMode get() = !isSystemInDarkMode
|
||||
*/
|
||||
inline val isUpperOfAndroidS get() = Build.VERSION.SDK_INT > Build.VERSION_CODES.R
|
||||
|
||||
/**
|
||||
* 系统版本是否低于 Android 9
|
||||
* @return [Boolean] 是否符合条件
|
||||
*/
|
||||
inline val isLowerAndroidP get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.P
|
||||
|
||||
/**
|
||||
* 当前设备是否是 MIUI 定制 Android 系统
|
||||
* @return [Boolean] 是否符合条件
|
||||
|
Reference in New Issue
Block a user