优化自定义媒体音量步数功能

This commit is contained in:
LittleTurtle2333
2022-04-13 23:23:24 +08:00
parent 320a393a7c
commit f2f133c5b9
2 changed files with 27 additions and 5 deletions

View File

@@ -976,14 +976,33 @@ class SettingsActivity : MIUIActivity() {
)
Line()
TitleText(resId = R.string.sound)
Text(
resId = R.string.media_volume_steps,
val mediaVolumeStepsSwitchBinding = GetDataBinding(
object : DefValue {
override fun getValue(): Any {
return getSP().getBoolean("media_volume_steps_switch", false)
}
}
) { view, flags, data ->
when (flags) {
1 -> (view as Switch).isEnabled = data as Boolean
2 -> view.visibility = if (data as Boolean) View.VISIBLE else View.GONE
}
}
TextSummaryWithSwitch(
TextSummaryV(
textId = R.string.media_volume_steps_switch,
tips = "${getString(R.string.take_effect_after_reboot)}\n${getString(R.string.media_volume_steps_summary)}"
),
SwitchV(
"media_volume_steps_switch",
dataBindingSend = mediaVolumeStepsSwitchBinding.bindingSend
)
)
SeekBarWithText(
"media_volume_steps",
15,
29,
15
15, dataBindingRecv = mediaVolumeStepsSwitchBinding.binding.getRecv(2)
)
}
register("scope_other", getString(R.string.scope_other), false) {

View File

@@ -5,8 +5,10 @@ import com.lt2333.simplicitytools.util.hookBeforeMethod
import com.lt2333.simplicitytools.util.xposed.base.HookRegister
object SystemPropertiesHook : HookRegister() {
override fun init() {
val mediaStepsSwitch = XSPUtils.getBoolean("media_volume_steps_switch", false)
val mediaSteps = XSPUtils.getInt("media_volume_steps", 15)
"android.os.SystemProperties".hookBeforeMethod(
getDefaultClassLoader(),
"getInt",
@@ -14,8 +16,9 @@ object SystemPropertiesHook : HookRegister() {
Int::class.java
) {
when (it.args[0] as String) {
"ro.config.media_vol_steps" -> it.result = XSPUtils.getInt("media_volume_steps",15)
"ro.config.media_vol_steps" -> if (mediaStepsSwitch) it.result = mediaSteps
}
}
}
}