mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-05 10:15:33 +08:00
修复媒体通知面板不能被透明的问题,新增媒体通知自动展开功能
This commit is contained in:
@@ -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")
|
||||
|
||||
|
@@ -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>()
|
||||
|
||||
/** 媒体通知 [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<View>()?.performClick()
|
||||
}
|
||||
}
|
||||
}.ignoredHookClassNotFoundFailure()
|
||||
/** 替换通知图标和样式 */
|
||||
NotificationHeaderViewWrapperClass.hook {
|
||||
injectMember {
|
||||
|
@@ -127,10 +127,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
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<ActivityMainBinding>() {
|
||||
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<ActivityMainBinding>() {
|
||||
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<ActivityMainBinding>() {
|
||||
}
|
||||
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) {
|
||||
|
@@ -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<String>().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())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -421,6 +421,31 @@
|
||||
android:textColor="@color/colorTextDark"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<com.fankes.coloros.notify.ui.view.MaterialSwitch
|
||||
android:id="@+id/notify_media_panel_auto_exp_switch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="启用媒体通知播放时自动展开"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/colorTextGray"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notify_media_panel_auto_exp_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:alpha="0.6"
|
||||
android:lineSpacingExtra="6dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="ColorOS 的媒体通知在播放的时候默认是折叠状态,开启后只要推送媒体通知以及恢复播放状态都会自动展开通知。"
|
||||
android:textColor="@color/colorTextDark"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<com.fankes.coloros.notify.ui.view.MaterialSwitch
|
||||
android:id="@+id/notify_panel_config_switch"
|
||||
android:layout_width="match_parent"
|
||||
@@ -440,8 +465,9 @@
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:max="255"
|
||||
android:min="0" />
|
||||
android:max="100"
|
||||
android:min="0"
|
||||
android:progress="75" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/notify_panel_config_text_panel"
|
||||
@@ -461,7 +487,7 @@
|
||||
android:gravity="center"
|
||||
android:maxWidth="100dp"
|
||||
android:singleLine="true"
|
||||
android:text="当前值"
|
||||
android:text="当前"
|
||||
android:textColor="@color/colorTextGray"
|
||||
android:textSize="13.5sp" />
|
||||
|
||||
@@ -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" />
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:id="@+id/notify_panel_config_warn_panel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:alpha="0.6"
|
||||
android:lineSpacingExtra="6dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="此功能为实验性功能,后期不一定继续维护,且仅在 ColorOS 12.1 测试通过,不能保证可以在任何系统版本中生效,以及和各种通知栏主题模块配合使用,如有冲突请关闭此功能或禁用相关重复功能的主题模块。\n已知问题:悬浮通知也会被透明,在透明度较低的时候下拉会有阴影光晕,后期看需求再解决。"
|
||||
android:textColor="@color/colorTextDark"
|
||||
android:textSize="12sp" />
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:alpha="0.6"
|
||||
android:lineSpacingExtra="6dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="此功能为实验性功能,后期不一定继续维护,且仅在 ColorOS 12.1 测试通过,不能保证可以在任何系统版本中生效,以及和各种通知栏主题模块配合使用,如有冲突请关闭此功能或禁用相关重复功能的主题模块。"
|
||||
android:textColor="@color/colorTextDark"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:alpha="0.6"
|
||||
android:lineSpacingExtra="6dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="已知问题:\n(1) 悬浮通知也会被透明,在透明度较低的时候下拉会有阴影光晕,松手释放后恢复正常,后期看需求再解决。\n(2) 媒体通知可能在低于 ColorOS 12.1 的系统上无法生效透明度,旧版本不再适配,该问题不会被修复。"
|
||||
android:textColor="@color/colorTextDark"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
Reference in New Issue
Block a user