mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-06 02:35:32 +08:00
更新通知图标优化名单功能并优化代码和相关功能
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
package com.fankes.miui.notify.bean
|
package com.fankes.miui.notify.bean
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import com.fankes.miui.notify.utils.base64
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,4 +36,6 @@ data class IconDataBean(
|
|||||||
var packageName: String,
|
var packageName: String,
|
||||||
var iconBitmap: Bitmap,
|
var iconBitmap: Bitmap,
|
||||||
var contributorName: String
|
var contributorName: String
|
||||||
) : Serializable
|
) : Serializable {
|
||||||
|
override fun toString() = ("$appName$packageName").base64
|
||||||
|
}
|
@@ -180,7 +180,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
IconPackParams.iconDatas.forEach {
|
IconPackParams.iconDatas.forEach {
|
||||||
if ((notifyInstance.opPkgName == it.packageName ||
|
if ((notifyInstance.opPkgName == it.packageName ||
|
||||||
findAppName(notifyInstance) == it.appName) &&
|
findAppName(notifyInstance) == it.appName) &&
|
||||||
HookMedium.isAppNotifyHookOf(it.packageName)
|
HookMedium.isAppNotifyHookOf(it)
|
||||||
) {
|
) {
|
||||||
customIcon = Icon.createWithBitmap(it.iconBitmap)
|
customIcon = Icon.createWithBitmap(it.iconBitmap)
|
||||||
return@run
|
return@run
|
||||||
@@ -210,6 +210,9 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
runWithoutError(error = "AutoSetAppIconOnSet") {
|
runWithoutError(error = "AutoSetAppIconOnSet") {
|
||||||
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
/** 获取通知对象 - 由于 MIUI 的版本迭代不规范性可能是空的 */
|
||||||
(param.args?.get(if (isNew) 2 else 1) as? StatusBarNotification?)?.let { notifyInstance ->
|
(param.args?.get(if (isNew) 2 else 1) as? StatusBarNotification?)?.let { notifyInstance ->
|
||||||
|
/** 是否 Hook 彩色通知图标 */
|
||||||
|
val isHookColorIcon = HookMedium.getBoolean(HookMedium.ENABLE_COLOR_ICON_HOOK, default = true)
|
||||||
|
|
||||||
/** 获取 [Context] */
|
/** 获取 [Context] */
|
||||||
val context = if (isNew) param.args[0] as Context else globalContext
|
val context = if (isNew) param.args[0] as Context else globalContext
|
||||||
|
|
||||||
@@ -227,12 +230,12 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
|
|
||||||
/** 自定义默认小图标 */
|
/** 自定义默认小图标 */
|
||||||
var customIcon: Bitmap? = null
|
var customIcon: Bitmap? = null
|
||||||
if (HookMedium.getBoolean(HookMedium.ENABLE_COLOR_ICON_HOOK, default = true))
|
if (isHookColorIcon)
|
||||||
run {
|
run {
|
||||||
IconPackParams.iconDatas.forEach {
|
IconPackParams.iconDatas.forEach {
|
||||||
if ((notifyInstance.opPkgName == it.packageName ||
|
if ((notifyInstance.opPkgName == it.packageName ||
|
||||||
findAppName(notifyInstance) == it.appName) &&
|
findAppName(notifyInstance) == it.appName) &&
|
||||||
HookMedium.isAppNotifyHookOf(it.packageName)
|
HookMedium.isAppNotifyHookOf(it)
|
||||||
) {
|
) {
|
||||||
customIcon = it.iconBitmap
|
customIcon = it.iconBitmap
|
||||||
return@run
|
return@run
|
||||||
@@ -250,29 +253,33 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
else {
|
else {
|
||||||
/** 重新设置图标 - 防止系统更改它 */
|
/** 重新设置图标 - 防止系统更改它 */
|
||||||
iconImageView.setImageDrawable(iconDrawable)
|
iconImageView.setImageDrawable(iconDrawable)
|
||||||
/** 判断如果是灰度图标就给他设置一个白色颜色遮罩 */
|
/*判断是否开启 Hook 彩色图标*/
|
||||||
if (isGrayscaleIcon(context, iconDrawable))
|
if (isHookColorIcon) {
|
||||||
iconImageView.setColorFilter(if (isUpperOfAndroidS) newStyle else oldStyle)
|
/** 判断如果是灰度图标就给他设置一个白色颜色遮罩 */
|
||||||
else
|
if (isGrayscaleIcon(context, iconDrawable))
|
||||||
iconImageView.apply {
|
iconImageView.setColorFilter(if (isUpperOfAndroidS) newStyle else oldStyle)
|
||||||
clipToOutline = true
|
else
|
||||||
/** 设置一个圆角轮廓裁切 */
|
iconImageView.apply {
|
||||||
outlineProvider = object : ViewOutlineProvider() {
|
clipToOutline = true
|
||||||
override fun getOutline(view: View, out: Outline) {
|
/** 设置一个圆角轮廓裁切 */
|
||||||
out.setRoundRect(
|
outlineProvider = object : ViewOutlineProvider() {
|
||||||
0,
|
override fun getOutline(view: View, out: Outline) {
|
||||||
0,
|
out.setRoundRect(
|
||||||
view.width,
|
0,
|
||||||
view.height,
|
0,
|
||||||
5.dp(context)
|
view.width,
|
||||||
)
|
view.height,
|
||||||
|
5.dp(context)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/** 清除原生的背景边距设置 */
|
||||||
|
if (isUpperOfAndroidS) setPadding(0, 0, 0, 0)
|
||||||
|
/** 清除原生的主题色背景圆圈颜色 */
|
||||||
|
if (isUpperOfAndroidS) setBackgroundDrawable(null)
|
||||||
}
|
}
|
||||||
/** 清除原生的背景边距设置 */
|
/** 否则一律设置灰度图标 */
|
||||||
if (isUpperOfAndroidS) setPadding(0, 0, 0, 0)
|
} else iconImageView.setColorFilter(if (isUpperOfAndroidS) newStyle else oldStyle)
|
||||||
/** 清除原生的主题色背景圆圈颜色 */
|
|
||||||
if (isUpperOfAndroidS) setBackgroundDrawable(null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +336,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
IconPackParams.iconDatas.forEach {
|
IconPackParams.iconDatas.forEach {
|
||||||
if ((notifyInstance.opPkgName == it.packageName ||
|
if ((notifyInstance.opPkgName == it.packageName ||
|
||||||
lpparam.findAppName(notifyInstance) == it.appName) &&
|
lpparam.findAppName(notifyInstance) == it.appName) &&
|
||||||
HookMedium.isAppNotifyHookOf(it.packageName)
|
HookMedium.isAppNotifyHookOf(it)
|
||||||
) {
|
) {
|
||||||
isTargetApp = true
|
isTargetApp = true
|
||||||
return@run
|
return@run
|
||||||
|
@@ -29,6 +29,7 @@ import android.widget.Toast
|
|||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
|
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
|
||||||
import com.fankes.miui.notify.application.MNNApplication.Companion.isMineStarted
|
import com.fankes.miui.notify.application.MNNApplication.Companion.isMineStarted
|
||||||
|
import com.fankes.miui.notify.bean.IconDataBean
|
||||||
import com.fankes.miui.notify.utils.FileUtils
|
import com.fankes.miui.notify.utils.FileUtils
|
||||||
import com.fankes.miui.notify.utils.XPrefUtils
|
import com.fankes.miui.notify.utils.XPrefUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -56,16 +57,16 @@ object HookMedium {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取此 APP 的通知图标是否被 Hook
|
* 获取此 APP 的通知图标是否被 Hook
|
||||||
* @param packageName 包名
|
* @param bean 图标 bean
|
||||||
*/
|
*/
|
||||||
fun isAppNotifyHookOf(packageName: String) = getBoolean(key = "${packageName}_icon", default = true)
|
fun isAppNotifyHookOf(bean: IconDataBean) = getBoolean(key = bean.toString(), default = true)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置 Hook 此 APP 的通知图标
|
* 设置 Hook 此 APP 的通知图标
|
||||||
* @param packageName 包名
|
* @param bean 图标 bean
|
||||||
* @param isHook 是否 Hook
|
* @param isHook 是否 Hook
|
||||||
*/
|
*/
|
||||||
fun putAppNotifyHookOf(packageName: String, isHook: Boolean) = putBoolean(key = "${packageName}_icon", bool = isHook)
|
fun putAppNotifyHookOf(bean: IconDataBean, isHook: Boolean) = putBoolean(key = bean.toString(), bool = isHook)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取保存的值
|
* 获取保存的值
|
||||||
|
@@ -74,10 +74,10 @@ class ConfigureActivity : BaseActivity() {
|
|||||||
holder.appName.text = it.appName
|
holder.appName.text = it.appName
|
||||||
holder.pkgName.text = it.packageName
|
holder.pkgName.text = it.packageName
|
||||||
holder.cbrName.text = "贡献者:" + it.contributorName
|
holder.cbrName.text = "贡献者:" + it.contributorName
|
||||||
holder.switch.isChecked = HookMedium.isAppNotifyHookOf(it.packageName)
|
holder.switch.isChecked = HookMedium.isAppNotifyHookOf(it)
|
||||||
holder.switch.setOnCheckedChangeListener { btn, b ->
|
holder.switch.setOnCheckedChangeListener { btn, b ->
|
||||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
HookMedium.putAppNotifyHookOf(it.packageName, b)
|
HookMedium.putAppNotifyHookOf(it, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cView!!
|
return cView!!
|
||||||
|
@@ -165,6 +165,12 @@ val Number.dp get() = (toFloat() * appContext.resources.displayMetrics.density).
|
|||||||
*/
|
*/
|
||||||
fun Number.dp(context: Context) = toFloat() * context.resources.displayMetrics.density
|
fun Number.dp(context: Context) = toFloat() * context.resources.displayMetrics.density
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base64 加密
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
val String.base64: String get() = Base64.encodeToString(toByteArray(), Base64.DEFAULT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base64 解密为字节流
|
* Base64 解密为字节流
|
||||||
* @return [ByteArray]
|
* @return [ByteArray]
|
||||||
|
Reference in New Issue
Block a user