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 d378bc8..518295c 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 @@ -39,7 +39,8 @@ object DataConst { 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", false) - val NOTIFY_PANEL_ALPHA = PrefsData("_notify_panel_alpha", 185) + val ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP = PrefsData("_enable_notify_media_panel_auto_exp", false) + val NOTIFY_PANEL_ALPHA = PrefsData("_notify_panel_alpha_pst", 75) 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 413e96f..5cf8512 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 @@ -29,6 +29,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.content.res.ColorStateList import android.graphics.Bitmap import android.graphics.Color import android.graphics.Outline @@ -96,19 +97,34 @@ object SystemUIHooker : YukiBaseHooker() { /** 原生存在的类 */ private const val IconManagerClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.icon.IconManager" - /** ColorOS 存在的类 - 旧版本不存在 */ - private const val OplusContrastColorUtilClass = "com.oplusos.util.OplusContrastColorUtil" - /** 原生存在的类 */ private const val PluginManagerImplClass = "$SYSTEMUI_PACKAGE_NAME.shared.plugins.PluginManagerImpl" /** 原生存在的类 */ private const val NotificationBackgroundViewClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.NotificationBackgroundView" + /** 原生存在的类 */ + private const val PlayerViewHolderClass = "$SYSTEMUI_PACKAGE_NAME.media.PlayerViewHolder" + + /** 原生存在的类 */ + private const val MediaDataClass = "$SYSTEMUI_PACKAGE_NAME.media.MediaData" + + /** ColorOS 存在的类 - 旧版本不存在 */ + private const val OplusContrastColorUtilClass = "com.oplusos.util.OplusContrastColorUtil" + /** ColorOS 存在的类 - 旧版本不存在 */ private const val OplusNotificationBackgroundViewClass = "com.oplusos.systemui.statusbar.notification.row.OplusNotificationBackgroundView" + /** ColorOS 存在的类 - 旧版本不存在 */ + private const val OplusMediaControlPanelClass = "com.oplusos.systemui.media.OplusMediaControlPanel" + + /** ColorOS 存在的类 - 旧版本不存在 */ + private const val OplusMediaViewControllerClass = "com.oplusos.systemui.media.OplusMediaViewController" + + /** ColorOS 存在的类 - 旧版本不存在 */ + private const val BasePlayViewHolderClass = "com.oplusos.systemui.media.base.BasePlayViewHolder" + /** 根据多个版本存在不同的包名相同的类 */ private val OplusNotificationIconAreaControllerClass = VariousClass( "com.oplusos.systemui.statusbar.phone.OplusNotificationIconAreaController", @@ -188,6 +204,9 @@ object SystemUIHooker : YukiBaseHooker() { /** 状态栏通知图标数组 */ private var notificationIconInstances = ArrayList() + /** 媒体通知 [View] */ + private var notificationPlayerView: View? = null + /** 通知栏通知控制器 */ private var notificationPresenter: Any? = null @@ -365,6 +384,7 @@ object SystemUIHooker : YukiBaseHooker() { emptyParam() }.call() } + modifyNotifyPanelAlpha(notificationPlayerView, isTint = true) } /** @@ -535,14 +555,25 @@ object SystemUIHooker : YukiBaseHooker() { * 设置通知面板背景透明度 * @param view 背景 View 实例 * @param drawable 背景实例 + * @param isTint 是否着色 [view] */ - private fun modifyNotifyPanelAlpha(view: View?, drawable: Drawable?) { + private fun modifyNotifyPanelAlpha(view: View?, drawable: Drawable? = null, isTint: Boolean = false) { prefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA).also { isEnabled -> + val currentAlpha = prefs.get(DataConst.NOTIFY_PANEL_ALPHA) + val currendColor = if (view?.context?.isSystemInDarkMode == true) 0xFF404040.toInt() else 0xFFFAFAFA.toInt() /** 设置通知面板背景透明度 */ when { - isEnabled.not() -> drawable?.alpha = 255 - view?.parent?.parent?.javaClass?.name?.contains(other = "ChildrenContainer") == true -> drawable?.alpha = 0 - else -> drawable?.alpha = prefs.get(DataConst.NOTIFY_PANEL_ALPHA) + isEnabled.not() -> { + if (isTint) view?.backgroundTintList = ColorStateList.valueOf(currendColor) + else drawable?.setTint(currendColor) + } + isTint.not() && view?.parent?.parent?.javaClass?.name?.contains(other = "ChildrenContainer") == true -> drawable?.alpha = 0 + else -> { + currendColor.colorAlphaOf(currentAlpha / 100f).also { + if (isTint) view?.backgroundTintList = ColorStateList.valueOf(it) + else drawable?.setTint(it) + } + } } /** 移除阴影效果 */ if (isEnabled) view?.elevation = 0f @@ -757,6 +788,47 @@ object SystemUIHooker : YukiBaseHooker() { } } } + /** 替换媒体通知面板背景 - 设置媒体通知自动展开 */ + OplusMediaControlPanelClass.hook { + injectMember { + method { + name = "bind" + paramCount = 2 + } + afterHook { + /** 得到当前实例 */ + val holder = field { + name = "mViewHolder" + superClass(isOnlySuperClass = true) + }.get(instance).any() + /** 记录媒体通知 [View] */ + notificationPlayerView = PlayerViewHolderClass.clazz.method { + name = "getPlayer" + emptyParam() + }.get(holder).invoke() + /** 设置背景着色 */ + modifyNotifyPanelAlpha(notificationPlayerView, isTint = true) + /** 当前是否正在播放 */ + val isPlaying = MediaDataClass.clazz.method { + name = "isPlaying" + emptyParam() + }.get(args().first().any()).boolean() + + /** 当前通知是否展开 */ + val isExpanded = OplusMediaViewControllerClass.clazz.method { + name = "getExpanded" + emptyParam() + }.get(field { name = "mOplusMediaViewController" }.get(instance).self).boolean() + /** 符合条件后执行 */ + if (prefs.get(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP).not() || isExpanded || isPlaying.not()) return@afterHook + /** 模拟手动展开通知 */ + BasePlayViewHolderClass.clazz.method { + name = "getExpandButton" + emptyParam() + }.get(holder).invoke()?.performClick() + } + } + }.ignoredHookClassNotFoundFailure() /** 替换通知图标和样式 */ 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 5a32436..3e051fb 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 @@ -127,10 +127,12 @@ class MainActivity : BaseActivity() { binding.notifyIconAutoSyncChildItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO) binding.notifyPanelConfigSeekbar.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA) binding.notifyPanelConfigTextPanel.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA) + binding.notifyPanelConfigWarnPanel.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) binding.a12StyleConfigSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_ANDROID12_STYLE) + binding.notifyMediaPanelAutoExpSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP) binding.moduleEnableSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE) binding.moduleEnableLogSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE_LOG) binding.hideIconInLauncherSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HIDE_ICON) @@ -139,8 +141,13 @@ class MainActivity : BaseActivity() { 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).toString() + binding.notifyPanelConfigText.text = "${modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA)}%" binding.notifyIconAutoSyncText.text = notifyIconAutoSyncTime + /** 媒体通知自动展开仅支持 12.1 - 旧版本适配过于复杂已放弃 */ + if (colorOSNumberVersion != "V12.1") { + binding.notifyMediaPanelAutoExpSwitch.isVisible = false + binding.notifyMediaPanelAutoExpText.isVisible = false + } binding.moduleEnableSwitch.setOnCheckedChangeListener { btn, b -> if (btn.isPressed.not()) return@setOnCheckedChangeListener modulePrefs.put(DataConst.ENABLE_MODULE, b) @@ -197,10 +204,16 @@ class MainActivity : BaseActivity() { modulePrefs.put(DataConst.ENABLE_ANDROID12_STYLE, b) SystemUITool.refreshSystemUI(context = this) } + binding.notifyMediaPanelAutoExpSwitch.setOnCheckedChangeListener { btn, b -> + if (btn.isPressed.not()) return@setOnCheckedChangeListener + modulePrefs.put(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP, b) + SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true) + } binding.notifyPanelConfigSwitch.setOnCheckedChangeListener { btn, b -> if (btn.isPressed.not()) return@setOnCheckedChangeListener modulePrefs.put(DataConst.ENABLE_NOTIFY_PANEL_ALPHA, b) binding.notifyPanelConfigTextPanel.isVisible = b + binding.notifyPanelConfigWarnPanel.isVisible = b binding.notifyPanelConfigSeekbar.isVisible = b SystemUITool.refreshSystemUI(context = this) } @@ -212,7 +225,7 @@ class MainActivity : BaseActivity() { } binding.notifyPanelConfigSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - binding.notifyPanelConfigText.text = progress.toString() + binding.notifyPanelConfigText.text = "$progress%" } override fun onStopTrackingTouch(seekBar: SeekBar) { diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt index 8951f46..0ebef5f 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt @@ -138,14 +138,20 @@ val colorOSFullVersion get() = "${if (isRealmeUI) "RealmeUI " else ""}$colorOSVe * 获取 ColorOS 版本 * @return [String] */ -val colorOSVersion +val colorOSVersion get() = "$colorOSNumberVersion ${Build.DISPLAY}" + +/** + * 获取 ColorOS 数字版本 + * @return [String] + */ +val colorOSNumberVersion get() = safeOf(default = "无法获取") { (classOf(name = "com.oplus.os.OplusBuild").let { it.field { name = "VERSIONS" }.ignoredError().get().array().takeIf { e -> e.isNotEmpty() } ?.get(it.method { name = "getOplusOSVERSION" }.ignoredError().get().int() - 1) } ?: findPropString( key = "ro.system.build.fingerprint", default = "无法获取" - ).split("ssi:")[1].split("/")[0].trim()) + " ${Build.DISPLAY}" + ).split("ssi:")[1].split("/")[0].trim()) } /** diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a4143fd..c8cbcef 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -421,6 +421,31 @@ android:textColor="@color/colorTextDark" android:textSize="12sp" /> + + + + + android:max="100" + android:min="0" + android:progress="75" /> @@ -473,7 +499,7 @@ android:gravity="center" android:maxWidth="100dp" android:singleLine="true" - android:text="%1" + android:text="75%" android:textColor="@color/colorTextGray" android:textSize="15sp" android:textStyle="bold" /> @@ -487,21 +513,42 @@ android:lineSpacingExtra="6dp" android:paddingLeft="15dp" android:paddingRight="15dp" - android:text="开启自定义功能后,你可以拖拽滑动条来调整通知面板的透明度,0 为全透明,255 为不透明。" + android:text="开启自定义功能后,你可以拖拽滑动条来调整通知面板的透明度,0% 为全透明,100% 为不透明。" android:textColor="@color/colorTextDark" android:textSize="12sp" /> - + android:orientation="vertical"> + + + + +