Skip to content

Commit

Permalink
自定义系统主题色
Browse files Browse the repository at this point in the history
  • Loading branch information
hosizoraru committed May 21, 2023
1 parent 71067d9 commit 5e812da
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,74 @@ import star.sky.voyager.R
@BMPage("scope_system_ui", "System UI", hideMenu = false)
class SystemUIPage : BasePage() {
override fun onCreate() {
val monetBinding = GetDataBinding({
MIUIActivity.safeSP.getBoolean(
"monet_theme",
false
)
}) { view, flags, data ->
if (flags == 1) view.visibility = if (data as Boolean) View.VISIBLE else View.GONE
}
TextSummaryWithSwitch(
TextSummaryV(
textId = R.string.monet_theme,
), SwitchV("monet_theme", false, dataBindingSend = monetBinding.bindingSend)
)
TextSummaryWithArrow(
TextSummaryV(
textId = R.string.your_theme_accent_color,
onClickListener = {
MIUIDialog(activity) {
setTitle(R.string.your_theme_accent_color)
setEditText(
"",
"${activity.getString(R.string.current)}${
MIUIActivity.safeSP.getString("your_theme_accent_color", "#0d84ff")
}"
)
setLButton(textId = R.string.cancel) {
dismiss()
}
setRButton(textId = R.string.done) {
if (getEditText() != "") {
MIUIActivity.safeSP.putAny(
"your_theme_accent_color",
getEditText()
)
}
dismiss()
}
}.show()
}), dataBindingRecv = monetBinding.binding.getRecv(1)
)
TextSummaryWithArrow(
TextSummaryV(
textId = R.string.your_theme_neutral_color,
onClickListener = {
MIUIDialog(activity) {
setTitle(R.string.your_theme_neutral_color)
setEditText(
"",
"${activity.getString(R.string.current)}${
MIUIActivity.safeSP.getString("your_theme_neutral_color", "#A6CDE7")
}"
)
setLButton(textId = R.string.cancel) {
dismiss()
}
setRButton(textId = R.string.done) {
if (getEditText() != "") {
MIUIActivity.safeSP.putAny(
"your_theme_neutral_color",
getEditText()
)
}
dismiss()
}
}.show()
}), dataBindingRecv = monetBinding.binding.getRecv(1)
)
Line()
TitleText(textId = R.string.status_bar)
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.double_tap_to_sleep),
Expand Down Expand Up @@ -712,6 +780,7 @@ class SystemUIPage : BasePage() {
TextSummaryWithSwitch(
TextSummaryV(
textId = R.string.blur_lock_screen_button,
tipsId = R.string.only_official_default_themes_are_supported
), SwitchV("blur_lock_screen_button")
)
TextSummaryWithSwitch(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/star/sky/voyager/hook/apps/SystemUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import star.sky.voyager.hook.hooks.systemui.LockScreenClockDisplaySeconds
import star.sky.voyager.hook.hooks.systemui.LockScreenCurrent
import star.sky.voyager.hook.hooks.systemui.LockScreenDoubleTapToSleep
import star.sky.voyager.hook.hooks.systemui.MaximumNumberOfNotificationIcons
import star.sky.voyager.hook.hooks.systemui.MonetTheme
import star.sky.voyager.hook.hooks.systemui.NoPasswordHook
import star.sky.voyager.hook.hooks.systemui.NotificationSettingsNoWhiteList
import star.sky.voyager.hook.hooks.systemui.NotificationWeather
Expand All @@ -45,6 +46,7 @@ object SystemUI : AppRegister() {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
autoInitHooks(
lpparam,
MonetTheme, // 自定义系统主题色
StatusBarDoubleTapToSleep, // 状态栏-双击锁定屏幕
StatusBarBattery, // 状态栏显示关于电池
StatusBarLayout, // 状态栏布局
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,38 @@ object BlurLockScreenButton : HookRegister() {
loadClassOrNull(
"com.android.systemui.statusbar.phone.KeyguardBottomAreaView"
)?.methodFinder()?.forEach { method ->
method.createHook {
after { param ->
val mLeftAffordanceView = getValueByField(
param.thisObject,
"mLeftAffordanceView"
) as ImageView
val mRightAffordanceView = getValueByField(
param.thisObject,
"mRightAffordanceView"
) as ImageView
if (method.name != "onAttachedToWindow") {
method.createHook {
after { param ->
val mLeftAffordanceView = getValueByField(
param.thisObject,
"mLeftAffordanceView"
) as ImageView
val mRightAffordanceView = getValueByField(
param.thisObject,
"mRightAffordanceView"
) as ImageView

val keyguardBottomAreaView = param.thisObject as View
val leftBlurDrawable = createBlurDrawable(
keyguardBottomAreaView,
40,
100,
Color.argb(60, 255, 255, 255)
)
val leftLayerDrawable = LayerDrawable(arrayOf(leftBlurDrawable))
val rightBlurDrawable = createBlurDrawable(
keyguardBottomAreaView,
40,
100,
Color.argb(60, 255, 255, 255)
)
val rightLayerDrawable = LayerDrawable(arrayOf(rightBlurDrawable))
leftLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
rightLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
mLeftAffordanceView.background = leftLayerDrawable
mRightAffordanceView.background = rightLayerDrawable
val keyguardBottomAreaView = param.thisObject as View
val leftBlurDrawable = createBlurDrawable(
keyguardBottomAreaView,
40,
100,
Color.argb(60, 255, 255, 255)
)
val leftLayerDrawable = LayerDrawable(arrayOf(leftBlurDrawable))
val rightBlurDrawable = createBlurDrawable(
keyguardBottomAreaView,
40,
100,
Color.argb(60, 255, 255, 255)
)
val rightLayerDrawable = LayerDrawable(arrayOf(rightBlurDrawable))
leftLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
rightLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
mLeftAffordanceView.background = leftLayerDrawable
mRightAffordanceView.background = rightLayerDrawable
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package star.sky.voyager.hook.hooks.systemui

import android.graphics.Color
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.Log
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.XSPUtils
import star.sky.voyager.utils.key.hasEnable

object MonetTheme : HookRegister() {
override fun init() = hasEnable("monet_theme") {
loadClassOrNull("com.android.systemui.theme.ThemeOverlayController")?.methodFinder()
?.first {
name == "getOverlay" && parameterCount == 3 && parameterTypes[0] == Int::class.java && parameterTypes[1] == Int::class.java
}?.createHook {
before { param ->
param.args[0] =
Color.parseColor(XSPUtils.getString("your_theme_accent_color", "#0d84ff"))
param.args[1] =
Color.parseColor(XSPUtils.getString("your_theme_neutral_color", "#0d84ff"))
Log.i("Your monet theme color1:" + param.args[0])
Log.i("Your monet theme color2:" + param.args[1])
Log.i("Your monet theme style:" + param.args[2])
}
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,14 @@
<string name="home_folder_anim_2">打开快慢(越大越慢)</string>
<string name="home_folder_anim_3">文件夹关闭回弹(越小越明显)</string>
<string name="home_folder_anim_4">关闭快慢(越大越慢)</string>

<string name="mono_chrome_icon">图标背景色</string>
<string name="monet_color">默认颜色 -> 莫奈取色</string>
<string name="use_edit_color">修改成你喜欢的颜色</string>
<string name="your_color">你喜欢的颜色</string>
<string name="monet_theme">自定义系统主题色</string>
<string name="your_theme_accent_color">你喜欢的系统强调色</string>
<string name="your_theme_neutral_color">你喜欢的系统中性色</string>

<string name="system_ui_show_status_bar_battery">状态栏显示关于电池</string>
<string name="system_ui_show_status_bar_battery_summary">仅充电显示,刷新率由系统决定</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@
<string name="monet_color">Default color -> monet color</string>
<string name="use_edit_color">Edit it into your favorite color</string>
<string name="your_color">Your favorite color</string>
<string name="monet_theme">Edit system monet theme color into your favorite color</string>
<string name="your_theme_accent_color">Your favorite accent color</string>
<string name="your_theme_neutral_color">Your favorite neutral color</string>

<string name="system_ui_show_status_bar_battery">StatusBar Show about Battery</string>
<string name="system_ui_show_status_bar_battery_summary">Charging display only, refresh rate is determined by the system</string>
Expand Down

0 comments on commit 5e812da

Please sign in to comment.