Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/src/main/java/com/fankes/miui/notify/data/ConfigData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ object ConfigData {
/** 启用通知图标优化 */
val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true)

/** 强制启用焦点通知反色 */
val ENABLE_FOCUS_NOTIFICATION_FIX = PrefsData("_enable_focus_notification_fix", false)

/** 使用占位符修补未适配的通知图标 */
val ENABLE_NOTIFY_ICON_FIX_PLACEHOLDER = PrefsData("_notify_icon_fix_placeholder", false)

Expand Down Expand Up @@ -303,6 +306,16 @@ object ConfigData {
putBoolean(ENABLE_NOTIFY_ICON_FIX, value)
}


/**
* 是否强制启用焦点通知反色
* @return [Boolean]*/
var isEnableFocusNotificationFix
get() = getBoolean(ENABLE_FOCUS_NOTIFICATION_FIX)
set(value) {
putBoolean(ENABLE_FOCUS_NOTIFICATION_FIX, value)
}

/**
* 是否使用占位符修补未适配的通知图标
* @return [Boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ object SystemUIHooker : YukiBaseHooker() {
/** 仅监听一次主题壁纸颜色变化 */
private var isWallpaperColorListenerSetUp = false

/** 用来同步是否需要焦点图标染色 */
private var focusedIcon = false

/**
* 获取全局上下文
* @return [Context] or null
Expand Down Expand Up @@ -474,8 +477,12 @@ object SystemUIHooker : YukiBaseHooker() {
/** 判断是否不是灰度图标 */
val isGrayscaleIcon = notifyInstance.isXmsf.not() && isGrayscaleIcon(context, iconDrawable)

/** 读取通知是否附加包名,如果没有则使用通知包名 */
val extras = notifyInstance.notification.extras
val pkgname = extras.getString("app_package")?.takeIf { it.isNotBlank() } ?: notifyInstance.nfPkgName

/** 目标彩色通知 APP 图标 */
val customTriple = compatCustomIcon(context, isGrayscaleIcon, notifyInstance.nfPkgName)
val customTriple = compatCustomIcon(context, isGrayscaleIcon, pkgname)

/** 是否为通知优化生效图标 */
val isCustom = customTriple.first != null && customTriple.third.not()
Expand Down Expand Up @@ -573,9 +580,13 @@ object SystemUIHooker : YukiBaseHooker() {
/** 自定义默认小图标 */
var customIcon: Drawable? = null

/** 读取通知是否附加包名,如果没有则使用通知包名 */
val extras = notifyInstance.notification.extras
val pkgname = extras.getString("app_package")?.takeIf { it.isNotBlank() } ?: notifyInstance.nfPkgName

/** 自定义默认小图标颜色 */
var customIconColor = 0
compatCustomIcon(context, isGrayscaleIcon, notifyInstance.nfPkgName).also {
compatCustomIcon(context, isGrayscaleIcon, pkgname).also {
/** 不处理占位符图标 */
if (it.third) return@also
customIcon = it.first
Expand Down Expand Up @@ -985,10 +996,11 @@ object SystemUIHooker : YukiBaseHooker() {
val mIcon = firstFieldOrNull { name = "mIcon" }?.of(instance)?.get()
if (ConfigData.isEnableModuleLog)
YLog.debug("FocusedNotifPromptView DEBUG $isDark $mIcon")
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
name = "setColorFilter"
superclass()
}?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
if (focusedIcon || ConfigData.isEnableFocusNotificationFix)
mIcon?.asResolver()?.optional()?.firstMethodOrNull {
name = "setColorFilter"
superclass()
}?.invoke(if (isDark <= 0.5f) Color.WHITE else Color.BLACK)
}
}
/** 去他妈的焦点通知彩色图标 */
Expand All @@ -1003,9 +1015,13 @@ object SystemUIHooker : YukiBaseHooker() {
nf = expandedNf,
iconDrawable = small?.loadDrawable(context)
).also { pair ->
focusedIcon = pair.second
val originalBitmap = pair.first?.toBitmap()
val bitmap = originalBitmap?.scale(50, 50)
result = Icon.createWithBitmap(bitmap).apply { if (pair.second) setTint(if (isDark) Color.BLACK else Color.WHITE) }
result = Icon.createWithBitmap(bitmap).apply {
if (pair.second || ConfigData.isEnableFocusNotificationFix)
setTint(if (isDark) Color.BLACK else Color.WHITE)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.miuiNotifyIconReplacementSwitch.bind(ConfigData.ENABLE_REPLACE_MIUI_STYLE_NOTIFY_ICON) {
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
}
binding.miuiFocusNotifyIconFixSwitch.bind(ConfigData.ENABLE_FOCUS_NOTIFICATION_FIX) {
onChanged { SystemUITool.refreshSystemUI(context = this@MainActivity) }
}
binding.notifyIconForceSystemColorSwitch.bind(ConfigData.ENABLE_NOTIFY_ICON_FORCE_SYSTEM_COLOR) {
isAutoApplyChanges = false
onChanged {
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,34 @@
android:textSize="12sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/miui_focus_notify_icon_fix_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.fankes.miui.notify.ui.widget.MaterialSwitch
android:id="@+id/miui_focus_notify_icon_fix_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="是否强制启用焦点通知反色"
android:textColor="@color/colorTextGray"
android:textSize="15sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="是否强制启用焦点通知反色,由于无法准确判断反色,所以给了个强制开关。(默认关闭)"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/notify_icon_fix_notify_item"
android:layout_width="match_parent"
Expand Down