Skip to content

Commit c07f3e9

Browse files
committed
新增通知面板背景透明度调节功能
1 parent ebba4d2 commit c07f3e9

4 files changed

Lines changed: 149 additions & 4 deletions

File tree

app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ object DataConst {
3838
val REMOVE_CHANGECP_NOTIFY = PrefsData("_remove_charge_complete_notify", false)
3939
val REMOVE_DNDALERT_NOTIFY = PrefsData("_remove_dndalert_notify", false)
4040
val ENABLE_NOTIFY_ICON_FIX_AUTO = PrefsData("_enable_notify_icon_fix_auto", true)
41+
val ENABLE_NOTIFY_PANEL_ALPHA = PrefsData("_enable_notify_panel_alpha", true)
42+
val NOTIFY_PANEL_ALPHA = PrefsData("_notify_panel_alpha", 185)
4143
val NOTIFY_ICON_DATAS = PrefsData("_notify_icon_datas", "")
4244
val NOTIFY_ICON_FIX_AUTO_TIME = PrefsData("_notify_icon_fix_auto_time", "07:00")
4345

app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import com.highcapable.yukihookapi.hook.bean.VariousClass
5757
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
5858
import com.highcapable.yukihookapi.hook.factory.current
5959
import com.highcapable.yukihookapi.hook.factory.field
60+
import com.highcapable.yukihookapi.hook.factory.hasMethod
6061
import com.highcapable.yukihookapi.hook.factory.method
6162
import com.highcapable.yukihookapi.hook.log.loggerD
6263
import com.highcapable.yukihookapi.hook.log.loggerE
@@ -101,6 +102,13 @@ class SystemUIHooker : YukiBaseHooker() {
101102
/** 原生存在的类 */
102103
private const val PluginManagerImplClass = "$SYSTEMUI_PACKAGE_NAME.shared.plugins.PluginManagerImpl"
103104

105+
/** 原生存在的类 */
106+
private const val NotificationBackgroundViewClass = "$SYSTEMUI_PACKAGE_NAME.statusbar.notification.row.NotificationBackgroundView"
107+
108+
/** ColorOS 存在的类 - 旧版本不存在 */
109+
private const val OplusNotificationBackgroundViewClass =
110+
"com.oplusos.systemui.statusbar.notification.row.OplusNotificationBackgroundView"
111+
104112
/** 根据多个版本存在不同的包名相同的类 */
105113
private val OplusNotificationIconAreaControllerClass = VariousClass(
106114
"com.oplusos.systemui.statusbar.phone.OplusNotificationIconAreaController",
@@ -263,6 +271,18 @@ class SystemUIHooker : YukiBaseHooker() {
263271
*/
264272
private val StatusBarNotification.isOplusPush get() = opPkg == ANDROID_PACKAGE_NAME && opPkg != packageName
265273

274+
/**
275+
* 判断通知背景是否为旧版本
276+
* @return [Boolean]
277+
*/
278+
private val isOldNotificationBackground
279+
get() = safeOfFalse {
280+
NotificationBackgroundViewClass.clazz.hasMethod {
281+
name = "drawCustom"
282+
paramCount = 2
283+
}
284+
}
285+
266286
/**
267287
* 打印日志
268288
* @param tag 标识
@@ -512,6 +532,16 @@ class SystemUIHooker : YukiBaseHooker() {
512532
}
513533
}
514534

535+
/**
536+
* 设置通知面板背景透明度
537+
* @param drawable 背景实例
538+
*/
539+
private fun modifyNotifyPanelAlpha(drawable: Drawable?) {
540+
if (prefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA))
541+
drawable?.alpha = prefs.get(DataConst.NOTIFY_PANEL_ALPHA)
542+
else drawable?.alpha = 255
543+
}
544+
515545
/** 缓存图标数据 */
516546
private fun cachingIconDatas() {
517547
iconDatas.clear()
@@ -667,6 +697,41 @@ class SystemUIHooker : YukiBaseHooker() {
667697
}
668698
}
669699
}
700+
/** 替换通知面板背景 - 新版本 */
701+
OplusNotificationBackgroundViewClass.hook {
702+
injectMember {
703+
method {
704+
name = "drawRegionBlur"
705+
paramCount = 2
706+
}
707+
beforeHook { modifyNotifyPanelAlpha(args().last().cast<Drawable>()) }
708+
}
709+
injectMember {
710+
method {
711+
name = "draw"
712+
paramCount = 2
713+
superClass(isOnlySuperClass = true)
714+
}
715+
beforeHook { modifyNotifyPanelAlpha(args().last().cast<Drawable>()) }
716+
}
717+
}.by { isOldNotificationBackground.not() }
718+
/** 替换通知面板背景 - 旧版本 */
719+
NotificationBackgroundViewClass.hook {
720+
injectMember {
721+
method {
722+
name = "draw"
723+
paramCount = 2
724+
}
725+
beforeHook { modifyNotifyPanelAlpha(args().last().cast<Drawable>()) }
726+
}
727+
injectMember {
728+
method {
729+
name = "drawCustom"
730+
paramCount = 2
731+
}
732+
beforeHook { modifyNotifyPanelAlpha(args().last().cast<Drawable>()) }
733+
}
734+
}.by { isOldNotificationBackground }
670735
/** 替换通知图标和样式 */
671736
NotificationHeaderViewWrapperClass.hook {
672737
injectMember {

app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ package com.fankes.coloros.notify.ui.activity
2626

2727
import android.content.ComponentName
2828
import android.content.pm.PackageManager
29+
import android.widget.SeekBar
30+
import android.widget.SeekBar.OnSeekBarChangeListener
2931
import androidx.core.view.isVisible
3032
import com.fankes.coloros.notify.BuildConfig
3133
import com.fankes.coloros.notify.R
@@ -123,6 +125,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
123125
binding.notifyIconFixNotifyItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
124126
binding.notifyIconAutoSyncItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
125127
binding.notifyIconAutoSyncChildItem.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO)
128+
binding.notifyPanelConfigSeekbar.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
129+
binding.notifyPanelConfigText.isVisible = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
126130
binding.devNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_DEV_NOTIFY)
127131
binding.crcpNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_CHANGECP_NOTIFY)
128132
binding.dndNotifyConfigSwitch.isChecked = modulePrefs.get(DataConst.REMOVE_DNDALERT_NOTIFY)
@@ -133,6 +137,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
133137
binding.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX)
134138
binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY)
135139
binding.notifyIconAutoSyncSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO)
140+
binding.notifyPanelConfigSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_PANEL_ALPHA)
141+
binding.notifyPanelConfigSeekbar.progress = modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA)
142+
binding.notifyPanelConfigText.text = "当前 - ${modulePrefs.get(DataConst.NOTIFY_PANEL_ALPHA)}"
136143
binding.notifyIconAutoSyncText.text = notifyIconAutoSyncTime
137144
binding.moduleEnableSwitch.setOnCheckedChangeListener { btn, b ->
138145
if (btn.isPressed.not()) return@setOnCheckedChangeListener
@@ -190,12 +197,31 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
190197
modulePrefs.put(DataConst.ENABLE_ANDROID12_STYLE, b)
191198
SystemUITool.refreshSystemUI(context = this)
192199
}
200+
binding.notifyPanelConfigSwitch.setOnCheckedChangeListener { btn, b ->
201+
if (btn.isPressed.not()) return@setOnCheckedChangeListener
202+
modulePrefs.put(DataConst.ENABLE_NOTIFY_PANEL_ALPHA, b)
203+
binding.notifyPanelConfigText.isVisible = b
204+
binding.notifyPanelConfigSeekbar.isVisible = b
205+
SystemUITool.refreshSystemUI(context = this)
206+
}
193207
binding.notifyIconAutoSyncSwitch.setOnCheckedChangeListener { btn, b ->
194208
if (btn.isPressed.not()) return@setOnCheckedChangeListener
195209
modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX_AUTO, b)
196210
binding.notifyIconAutoSyncChildItem.isVisible = b
197211
SystemUITool.refreshSystemUI(context = this, isRefreshCacheOnly = true)
198212
}
213+
binding.notifyPanelConfigSeekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
214+
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
215+
binding.notifyPanelConfigText.text = "当前 - $progress"
216+
}
217+
218+
override fun onStopTrackingTouch(seekBar: SeekBar) {
219+
modulePrefs.put(DataConst.NOTIFY_PANEL_ALPHA, seekBar.progress)
220+
SystemUITool.refreshSystemUI(context = this@MainActivity)
221+
}
222+
223+
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
224+
})
199225
/** 通知图标优化名单按钮点击事件 */
200226
binding.notifyIconFixButton.setOnClickListener { navigate<ConfigureActivity>() }
201227
/** 自动更新在线规则修改时间按钮点击事件 */

app/src/main/res/layout/activity_main.xml

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,14 @@
372372
android:elevation="0dp"
373373
android:gravity="center"
374374
android:orientation="vertical"
375-
android:paddingLeft="15dp"
376-
android:paddingTop="15dp"
377-
android:paddingRight="15dp">
375+
android:paddingTop="15dp">
378376

379377
<LinearLayout
380378
android:layout_width="match_parent"
381379
android:layout_height="wrap_content"
382-
android:gravity="center|start">
380+
android:gravity="center|start"
381+
android:paddingLeft="15dp"
382+
android:paddingRight="15dp">
383383

384384
<ImageView
385385
android:layout_width="15dp"
@@ -402,6 +402,8 @@
402402
android:layout_width="match_parent"
403403
android:layout_height="40dp"
404404
android:layout_marginTop="5dp"
405+
android:paddingLeft="15dp"
406+
android:paddingRight="15dp"
405407
android:text="启用 Android 12 通知栏风格"
406408
android:textAllCaps="false"
407409
android:textColor="@color/colorTextGray"
@@ -413,9 +415,59 @@
413415
android:layout_marginBottom="10dp"
414416
android:alpha="0.6"
415417
android:lineSpacingExtra="6dp"
418+
android:paddingLeft="15dp"
419+
android:paddingRight="15dp"
416420
android:text="无论任何版本,开启后都将使用 Android 12 原生通知图标方式为通知栏推送的通知图标增加外部圆形轮廓。\n目标为 Android 12 的系统将自动使用系统主题色着色。"
417421
android:textColor="@color/colorTextDark"
418422
android:textSize="12sp" />
423+
424+
<com.fankes.coloros.notify.ui.view.MaterialSwitch
425+
android:id="@+id/notify_panel_config_switch"
426+
android:layout_width="match_parent"
427+
android:layout_height="40dp"
428+
android:layout_marginTop="5dp"
429+
android:paddingLeft="15dp"
430+
android:paddingRight="15dp"
431+
android:text="自定义通知面板背景透明度"
432+
android:textAllCaps="false"
433+
android:textColor="@color/colorTextGray"
434+
android:textSize="15sp" />
435+
436+
<androidx.appcompat.widget.AppCompatSeekBar
437+
android:id="@+id/notify_panel_config_seekbar"
438+
android:layout_width="match_parent"
439+
android:layout_height="40dp"
440+
android:layout_marginLeft="5dp"
441+
android:layout_marginTop="5dp"
442+
android:layout_marginRight="5dp"
443+
android:max="255"
444+
android:min="0" />
445+
446+
<TextView
447+
android:id="@+id/notify_panel_config_text"
448+
android:layout_width="wrap_content"
449+
android:layout_height="wrap_content"
450+
android:ellipsize="end"
451+
android:gravity="center"
452+
android:maxWidth="100dp"
453+
android:paddingTop="5dp"
454+
android:paddingBottom="15dp"
455+
android:singleLine="true"
456+
android:text="当前 - %1"
457+
android:textColor="@color/colorTextGray"
458+
android:textSize="14sp" />
459+
460+
<TextView
461+
android:layout_width="match_parent"
462+
android:layout_height="wrap_content"
463+
android:layout_marginBottom="10dp"
464+
android:alpha="0.6"
465+
android:lineSpacingExtra="6dp"
466+
android:paddingLeft="15dp"
467+
android:paddingRight="15dp"
468+
android:text="开启自定义功能后,你可以拖拽滑动条来调整通知面板的透明度,0 为全透明,255 为不透明。"
469+
android:textColor="@color/colorTextDark"
470+
android:textSize="12sp" />
419471
</LinearLayout>
420472

421473
<LinearLayout

0 commit comments

Comments
 (0)