mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-07 11:10:11 +08:00
调整状态栏通知栏未适配的彩色推送图标为 APP 主题图标
This commit is contained in:
@@ -284,6 +284,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
/** 获取优化后的状态栏通知图标 */
|
/** 获取优化后的状态栏通知图标 */
|
||||||
compatStatusIcon(
|
compatStatusIcon(
|
||||||
context = it.context,
|
context = it.context,
|
||||||
|
nf = nf,
|
||||||
isGrayscaleIcon = isGrayscaleIcon(it.context, iconDrawable),
|
isGrayscaleIcon = isGrayscaleIcon(it.context, iconDrawable),
|
||||||
packageName = nf.packageName,
|
packageName = nf.packageName,
|
||||||
drawable = iconDrawable
|
drawable = iconDrawable
|
||||||
@@ -372,19 +373,28 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
/**
|
/**
|
||||||
* 自动适配状态栏小图标
|
* 自动适配状态栏小图标
|
||||||
* @param context 实例
|
* @param context 实例
|
||||||
|
* @param nf 通知实例
|
||||||
* @param isGrayscaleIcon 是否为灰度图标
|
* @param isGrayscaleIcon 是否为灰度图标
|
||||||
* @param packageName APP 包名
|
* @param packageName APP 包名
|
||||||
* @param drawable 原始图标
|
* @param drawable 原始图标
|
||||||
* @return [Pair] - ([Drawable] 图标,[Boolean] 是否替换)
|
* @return [Pair] - ([Drawable] 图标,[Boolean] 是否替换)
|
||||||
*/
|
*/
|
||||||
private fun compatStatusIcon(context: Context, isGrayscaleIcon: Boolean, packageName: String, drawable: Drawable) =
|
private fun compatStatusIcon(
|
||||||
compatCustomIcon(isGrayscaleIcon, packageName).first.also {
|
context: Context,
|
||||||
|
nf: StatusBarNotification,
|
||||||
|
isGrayscaleIcon: Boolean,
|
||||||
|
packageName: String,
|
||||||
|
drawable: Drawable
|
||||||
|
) = compatCustomIcon(isGrayscaleIcon, packageName).first.also {
|
||||||
/** 打印日志 */
|
/** 打印日志 */
|
||||||
printLogcat(tag = "StatusIcon", context, packageName, isCustom = it != null, isGrayscaleIcon)
|
printLogcat(tag = "StatusIcon", context, packageName, isCustom = it != null, isGrayscaleIcon)
|
||||||
}?.let { Pair(BitmapDrawable(context.resources, it), true) } ?: Pair(drawable, false)
|
}?.let { Pair(BitmapDrawable(context.resources, it), true) }
|
||||||
|
?: Pair(if (isGrayscaleIcon) drawable else nf.compatPushingIcon(context, drawable), !isGrayscaleIcon)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动适配通知栏小图标
|
* 自动适配通知栏小图标
|
||||||
|
* @param context 实例
|
||||||
|
* @param nf 通知实例
|
||||||
* @param isGrayscaleIcon 是否为灰度图标
|
* @param isGrayscaleIcon 是否为灰度图标
|
||||||
* @param packageName APP 包名
|
* @param packageName APP 包名
|
||||||
* @param drawable 原始图标
|
* @param drawable 原始图标
|
||||||
@@ -392,6 +402,8 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
* @param iconView 图标 [ImageView]
|
* @param iconView 图标 [ImageView]
|
||||||
*/
|
*/
|
||||||
private fun compatNotifyIcon(
|
private fun compatNotifyIcon(
|
||||||
|
context: Context,
|
||||||
|
nf: StatusBarNotification,
|
||||||
isGrayscaleIcon: Boolean,
|
isGrayscaleIcon: Boolean,
|
||||||
packageName: String,
|
packageName: String,
|
||||||
drawable: Drawable,
|
drawable: Drawable,
|
||||||
@@ -438,7 +450,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
}
|
}
|
||||||
else -> iconView.apply {
|
else -> iconView.apply {
|
||||||
/** 重新设置图标 */
|
/** 重新设置图标 */
|
||||||
setImageDrawable(drawable)
|
setImageDrawable(nf.compatPushingIcon(context, drawable))
|
||||||
/** 设置裁切到边界 */
|
/** 设置裁切到边界 */
|
||||||
clipToOutline = true
|
clipToOutline = true
|
||||||
/** 设置一个圆角轮廓裁切 */
|
/** 设置一个圆角轮廓裁切 */
|
||||||
@@ -548,6 +560,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
nf.notification.smallIcon.loadDrawable(context).also { iconDrawable ->
|
nf.notification.smallIcon.loadDrawable(context).also { iconDrawable ->
|
||||||
compatStatusIcon(
|
compatStatusIcon(
|
||||||
context = context,
|
context = context,
|
||||||
|
nf = nf,
|
||||||
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
|
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
|
||||||
packageName = nf.packageName,
|
packageName = nf.packageName,
|
||||||
drawable = iconDrawable
|
drawable = iconDrawable
|
||||||
@@ -598,13 +611,16 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
it.javaClass.method {
|
it.javaClass.method {
|
||||||
name = "getSbn"
|
name = "getSbn"
|
||||||
}.get(it).invoke<StatusBarNotification>()
|
}.get(it).invoke<StatusBarNotification>()
|
||||||
}?.notification?.also { nf ->
|
}.also { nf ->
|
||||||
nf.smallIcon.loadDrawable(context).also { iconDrawable ->
|
nf?.notification?.also {
|
||||||
|
it.smallIcon.loadDrawable(context).also { iconDrawable ->
|
||||||
compatNotifyIcon(
|
compatNotifyIcon(
|
||||||
|
context = context,
|
||||||
|
nf = nf,
|
||||||
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
|
isGrayscaleIcon = isGrayscaleIcon(context, iconDrawable),
|
||||||
packageName = context.packageName,
|
packageName = context.packageName,
|
||||||
drawable = iconDrawable,
|
drawable = iconDrawable,
|
||||||
iconColor = nf.color,
|
iconColor = it.color,
|
||||||
iconView = this
|
iconView = this
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -612,6 +628,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/** 记录实例 */
|
/** 记录实例 */
|
||||||
injectMember {
|
injectMember {
|
||||||
constructor { param(ContextClass, ViewClass, ExpandableNotificationRowClass.clazz) }
|
constructor { param(ContextClass, ViewClass, ExpandableNotificationRowClass.clazz) }
|
||||||
|
Reference in New Issue
Block a user