diff --git a/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt b/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt index bbd2adf..f9622dd 100644 --- a/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt +++ b/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt @@ -38,6 +38,8 @@ object DataConst { val REMOVE_CHANGECP_NOTIFY = PrefsData("_remove_charge_complete_notify", false) val REMOVE_DNDALERT_NOTIFY = PrefsData("_remove_dndalert_notify", false) val ENABLE_NOTIFY_ICON_FIX_AUTO = PrefsData("_enable_notify_icon_fix_auto", true) + val ENABLE_NOTIFY_PANEL_ALPHA = PrefsData("_enable_notify_panel_alpha", true) + val NOTIFY_PANEL_ALPHA = PrefsData("_notify_panel_alpha", 185) val NOTIFY_ICON_DATAS = PrefsData("_notify_icon_datas", "") val NOTIFY_ICON_FIX_AUTO_TIME = PrefsData("_notify_icon_fix_auto_time", "07:00") diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index 2467327..4f87f6f 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -57,6 +57,7 @@ import com.highcapable.yukihookapi.hook.bean.VariousClass import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker import com.highcapable.yukihookapi.hook.factory.current import com.highcapable.yukihookapi.hook.factory.field +import com.highcapable.yukihookapi.hook.factory.hasMethod import com.highcapable.yukihookapi.hook.factory.method import com.highcapable.yukihookapi.hook.log.loggerD import com.highcapable.yukihookapi.hook.log.loggerE @@ -101,6 +102,13 @@ class SystemUIHooker : YukiBaseHooker() { /** 原生存在的类 */ private const val PluginManagerImplClass = "$SYSTEMUI_PACKAGE_NAME.shared.plugins.PluginManagerImpl" + /** 原生存在的类 */ + private const val NotificationBackgroundViewClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.NotificationBackgroundView" + + /** ColorOS 存在的类 - 旧版本不存在 */ + private const val OplusNotificationBackgroundViewClass = + "com.oplusos.systemui.statusbar.notification.row.OplusNotificationBackgroundView" + /** 根据多个版本存在不同的包名相同的类 */ private val OplusNotificationIconAreaControllerClass = VariousClass( "com.oplusos.systemui.statusbar.phone.OplusNotificationIconAreaController", @@ -263,6 +271,18 @@ class SystemUIHooker : YukiBaseHooker() { */ private val StatusBarNotification.isOplusPush get() = opPkg == ANDROID_PACKAGE_NAME && opPkg != packageName + /** + * 判断通知背景是否为旧版本 + * @return [Boolean] + */ + private val isOldNotificationBackground + get() = safeOfFalse { + NotificationBackgroundViewClass.clazz.hasMethod { + name = "drawCustom" + paramCount = 2 + } + } + /** * 打印日志 * @param tag 标识 @@ -512,6 +532,16 @@ class SystemUIHooker : YukiBaseHooker() { } } + /** + * 设置通知面板背景透明度 + * @param drawable 背景实例 + */ + private fun modifyNotifyPanelAlpha(drawable: Drawable?) { + if (prefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)) + drawable?.alpha = prefs.get(DataConst.NOTIFY_PANEL_ALPHA) + else drawable?.alpha = 255 + } + /** 缓存图标数据 */ private fun cachingIconDatas() { iconDatas.clear() @@ -667,6 +697,41 @@ class SystemUIHooker : YukiBaseHooker() { } } } + /** 替换通知面板背景 - 新版本 */ + OplusNotificationBackgroundViewClass.hook { + injectMember { + method { + name = "drawRegionBlur" + paramCount = 2 + } + beforeHook { modifyNotifyPanelAlpha(args().last().cast()) } + } + injectMember { + method { + name = "draw" + paramCount = 2 + superClass(isOnlySuperClass = true) + } + beforeHook { modifyNotifyPanelAlpha(args().last().cast()) } + } + }.by { isOldNotificationBackground.not() } + /** 替换通知面板背景 - 旧版本 */ + NotificationBackgroundViewClass.hook { + injectMember { + method { + name = "draw" + paramCount = 2 + } + beforeHook { modifyNotifyPanelAlpha(args().last().cast()) } + } + injectMember { + method { + name = "drawCustom" + paramCount = 2 + } + beforeHook { modifyNotifyPanelAlpha(args().last().cast()) } + } + }.by { isOldNotificationBackground } /** 替换通知图标和样式 */ NotificationHeaderViewWrapperClass.hook { injectMember { diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt index bbd59fe..9c5d0b9 100644 --- a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt @@ -26,6 +26,8 @@ package com.fankes.coloros.notify.ui.activity import android.content.ComponentName import android.content.pm.PackageManager +import android.widget.SeekBar +import android.widget.SeekBar.OnSeekBarChangeListener import androidx.core.view.isVisible import com.fankes.coloros.notify.BuildConfig import com.fankes.coloros.notify.R @@ -123,6 +125,8 @@ class MainActivity : BaseActivity() { binding.notifyIconFixNotifyItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) binding.notifyIconAutoSyncItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) binding.notifyIconAutoSyncChildItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO) + binding.notifyPanelConfigSeekbar.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA) + binding.notifyPanelConfigText.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA) binding.devNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_DEV_NOTIFY) binding.crcpNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_CHANGECP_NOTIFY) binding.dndNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_DNDALERT_NOTIFY) @@ -133,6 +137,9 @@ class MainActivity : BaseActivity() { binding.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY) binding.notifyIconAutoSyncSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO) + binding.notifyPanelConfigSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA) + binding.notifyPanelConfigSeekbar.progress = modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA) + binding.notifyPanelConfigText.text = "当前 - ${modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA)}" binding.notifyIconAutoSyncText.text = notifyIconAutoSyncTime binding.moduleEnableSwitch.setOnCheckedChangeListener { btn, b -> if (btn.isPressed.not()) return@setOnCheckedChangeListener @@ -190,12 +197,31 @@ class MainActivity : BaseActivity() { modulePrefs.put(DataConst.ENABLE_ANDROID12_STYLE, b) SystemUITool.refreshSystemUI(context = this) } + binding.notifyPanelConfigSwitch.setOnCheckedChangeListener { btn, b -> + if (btn.isPressed.not()) return@setOnCheckedChangeListener + modulePrefs.put(DataConst.ENABLE_NOTIFY_PANEL_ALPHA, b) + binding.notifyPanelConfigText.isVisible = b + binding.notifyPanelConfigSeekbar.isVisible = b + SystemUITool.refreshSystemUI(context = this) + } binding.notifyIconAutoSyncSwitch.setOnCheckedChangeListener { btn, b -> if (btn.isPressed.not()) return@setOnCheckedChangeListener modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO, b) binding.notifyIconAutoSyncChildItem.isVisible = b SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true) } + binding.notifyPanelConfigSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + binding.notifyPanelConfigText.text = "当前 - $progress" + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + modulePrefs.put(DataConst.NOTIFY_PANEL_ALPHA, seekBar.progress) + SystemUITool.refreshSystemUI(context = this@MainActivity) + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) {} + }) /** 通知图标优化名单按钮点击事件 */ binding.notifyIconFixButton.setOnClickListener { navigate() } /** 自动更新在线规则修改时间按钮点击事件 */ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a5d9021..eb61ab7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -372,14 +372,14 @@ android:elevation="0dp" android:gravity="center" android:orientation="vertical" - android:paddingLeft="15dp" - android:paddingTop="15dp" - android:paddingRight="15dp"> + android:paddingTop="15dp"> + android:gravity="center|start" + android:paddingLeft="15dp" + android:paddingRight="15dp"> + + + + + + + +