From f5e07514ebdcf11d861f3668b09d1f6e822dc74a Mon Sep 17 00:00:00 2001 From: Art_Chen Date: Fri, 3 Nov 2023 23:26:07 +0800 Subject: [PATCH] SystemUI: VolumePanelAnimator: add scale and stretch effect * Also fixed the unnecessary animation when already on the top Signed-off-by: Art_Chen --- .../systemui/ChenVolumePanelAnimator.kt | 50 ++++++++++++++++++- .../systemui/HomeHandleAnimatorHooker.kt | 4 +- .../view/activity/SettingsActivity.kt | 31 ++---------- app/src/main/res/values-zh-rCN/strings.xml | 6 +++ app/src/main/res/values/arrays.xml | 10 ++++ app/src/main/res/values/strings.xml | 6 +++ app/src/main/res/xml/chen_preferences.xml | 12 ++++- 7 files changed, 85 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/ChenVolumePanelAnimator.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/ChenVolumePanelAnimator.kt index a03c9e5..30f4735 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/ChenVolumePanelAnimator.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/ChenVolumePanelAnimator.kt @@ -6,32 +6,65 @@ import android.widget.LinearLayout import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker import com.highcapable.yukihookapi.hook.factory.method import com.highcapable.yukihookapi.hook.type.java.IntType +import de.robv.android.xposed.XSharedPreferences import de.robv.android.xposed.XposedHelpers +import moe.chenxy.miuiextra.BuildConfig +import kotlin.math.absoluteValue + object ChenVolumePanelAnimator : YukiBaseHooker() { + private const val SHIFT_ONLY = 0 + private const val STRETCH = 1 + private const val SCALE = 2 + + private var MAX_SHIFT_VAL = 25f + override fun onHook() { + val mainPrefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "chen_main_settings") + mainPrefs.reload() + var effectMode = mainPrefs.getString("chen_volume_animation_effect", "0")?.toInt() var mDialogView: LinearLayout? = null val mDialogAnimator = ValueAnimator() mDialogAnimator.addUpdateListener { - mDialogView?.translationY = it.animatedValue as Float + val currentVal = it.animatedValue as Float + when (effectMode) { + STRETCH -> { + mDialogView?.scaleX = 1 - (currentVal.absoluteValue / (MAX_SHIFT_VAL * 8)) + mDialogView?.scaleY = 1 + (currentVal.absoluteValue / (MAX_SHIFT_VAL * 20)) + } + SCALE -> { + mDialogView?.scaleX = 1 - (currentVal / (MAX_SHIFT_VAL * 15)) + mDialogView?.scaleY = 1 - (currentVal / (MAX_SHIFT_VAL * 15)) + } + } + mDialogView?.translationY = currentVal } + mDialogAnimator.duration = 800 mDialogAnimator.interpolator = PathInterpolator(0.39f, 1.48f, 0.44f, 1.07f) fun animateVolumeView(isTop: Boolean) { if (mDialogAnimator.isRunning) mDialogAnimator.cancel() + MAX_SHIFT_VAL = when (effectMode) { + STRETCH -> 50f + else -> 25f + } + mDialogAnimator.setFloatValues( mDialogView!!.translationY, - if (isTop) -25f else 25f, + if (isTop) -MAX_SHIFT_VAL else MAX_SHIFT_VAL, 0f ) + mainPrefs.reload() + effectMode = mainPrefs.getString("chen_volume_animation_effect", "0")?.toInt() mDialogAnimator.start() } var lastIsTopHaptic = false var lastIsBottomHaptic = false var lastIsContinueHaptic = false + var isDismissed = true "com.android.systemui.miui.volume.MiuiVolumeDialogImpl$1".toClass().method { name = "onPerformHapticFeedback" param(IntType) @@ -44,6 +77,10 @@ object ChenVolumePanelAnimator : YukiBaseHooker() { val isContinueHaptic: Boolean = i and 1 > 0 val isTopHaptic: Boolean = i and 2 > 0 val isBottomHaptic: Boolean = i and 4 > 0 + if (isDismissed) { + isDismissed = false + return@before + } // Log.i("Art_Chen", "onPerformHapticFeedback isContinueHaptic:$isContinueHaptic, isTopHaptic: $isTopHaptic, isBottomHaptic: $isBottomHaptic") if ((isTopHaptic || isBottomHaptic) && (lastIsBottomHaptic != isBottomHaptic || lastIsTopHaptic != isTopHaptic || lastIsContinueHaptic != isContinueHaptic)) { animateVolumeView(isTopHaptic && !isBottomHaptic) @@ -55,5 +92,14 @@ object ChenVolumePanelAnimator : YukiBaseHooker() { lastIsBottomHaptic = isBottomHaptic } } + + "com.android.systemui.miui.volume.MiuiVolumeDialogImpl$6".toClass().method { + name = "onDismiss" + }.hook { + after { + isDismissed = true + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/HomeHandleAnimatorHooker.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/HomeHandleAnimatorHooker.kt index e9eeddc..6baccd9 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/HomeHandleAnimatorHooker.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/HomeHandleAnimatorHooker.kt @@ -80,7 +80,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { var mLightColor = -1 var mDarkColor = -1 var mNavigationHandle : Any? = null - var currentIntensity = -1; + var currentIntensity = 0f fun animateHomeHandleZoom(zoomType: ZoomType) { if (zoomValueAnimator == null) { zoomValueAnimator = ValueAnimator() @@ -569,7 +569,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { XposedHelpers.setIntField(this.instance, "mDarkColor", mDarkColor) XposedHelpers.setIntField(this.instance, "mLightColor", mLightColor) } - currentIntensity = this.args[0] as Int + currentIntensity = this.args[0] as Float } } } diff --git a/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt b/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt index dca6c67..df04f7c 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt @@ -106,8 +106,9 @@ class SettingsActivity : AppCompatActivity() { override fun onPreferenceTreeClick(preference: Preference): Boolean { if (preference is TwoStatePreference) { val category = preference.parent as PreferenceCategory - if (category.key == "status_bar_and_cc_category") { - showRebootSnackBar(R.string.may_need_reboot, SHELL_RESTART_SYSTEMUI) + when (category.key) { + "wallpaper_settings" -> showRebootSnackBar(R.string.may_need_reboot, SHELL_RESTART_MI_WALLPAPER) + "status_bar_and_cc_category", "home_handle" -> showRebootSnackBar(R.string.may_need_reboot, SHELL_RESTART_SYSTEMUI) } this.context?.let { ChenUtils.performVibrateHeavyClick(it) } } @@ -148,29 +149,8 @@ class SettingsActivity : AppCompatActivity() { return@setOnPreferenceChangeListener true } - findPreference("use_chen_screen_on_anim")?.setOnPreferenceChangeListener { _, _ -> - showRebootSnackBar(null, SHELL_RESTART_MI_WALLPAPER) - return@setOnPreferenceChangeListener true - } - - val animTurboMode = findPreference("chen_home_handle_anim_turbo_mode") - val immersionMode = findPreference("chen_home_handle_no_space") - findPreference("chen_home_handle_anim")?.setOnPreferenceChangeListener { _, _ -> - showRebootSnackBar(null, SHELL_RESTART_SYSTEMUI) - return@setOnPreferenceChangeListener true - } bindAnimationSeekBarNoEditText(findPreference("home_handle_y_val"), 1) - animTurboMode?.setOnPreferenceChangeListener { _, _ -> - showRebootSnackBar(null, SHELL_RESTART_SYSTEMUI) - return@setOnPreferenceChangeListener true - } - - immersionMode?.setOnPreferenceChangeListener { _, _ -> - showRebootSnackBar(null, SHELL_RESTART_SYSTEMUI) - return@setOnPreferenceChangeListener true - } - val colorFadeOnCustom = findPreference("screen_on_color_fade_anim_val") val colorFadeOffCustom = findPreference("screen_off_color_fade_anim_val") val colorFadeCustom = findPreference("color_fade_anim_smoothly") @@ -223,11 +203,6 @@ class SettingsActivity : AppCompatActivity() { return@setOnPreferenceChangeListener true } - findPreference("disable_wallpaper_auto_darken")?.setOnPreferenceChangeListener { _, newValue -> - showRebootSnackBar(null, SHELL_RESTART_MI_WALLPAPER) - return@setOnPreferenceChangeListener true - } - findPreference("use_chen_volume_animation")?.setOnPreferenceChangeListener { _, newValue -> showRebootSnackBar(null, SHELL_RESTART_SYSTEMUI) return@setOnPreferenceChangeListener true diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 3c61889..3945db3 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -106,4 +106,10 @@ 模糊缩放程度 小白条隐藏或出现时应用缩放效果 在小白条上应用模糊材质(需要开启高级材质) + 音量条动画效果 + 位移 + 拉伸 + 位移 + 拉伸 + 缩放 + 位移 + 缩放 \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 1fead45..89c62ac 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -7,4 +7,14 @@ com.android.systemui com.miui.miwallpaper + + @string/shift + @string/stretch + @string/scale + + + 0 + 1 + 2 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4e1598..81184be 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -108,4 +108,10 @@ Blur Scale degree Scale home handle when dismiss or appeared Apply Mi Blur Effect on Home Handle + Volume Animation Effect + Shift + Stretch + Shift and Stretch + Scale + Shift and Scale \ No newline at end of file diff --git a/app/src/main/res/xml/chen_preferences.xml b/app/src/main/res/xml/chen_preferences.xml index 7b95f91..26dd7c2 100644 --- a/app/src/main/res/xml/chen_preferences.xml +++ b/app/src/main/res/xml/chen_preferences.xml @@ -74,9 +74,17 @@ app:key="use_chen_volume_animation" app:title="@string/use_chen_volume_animation_title" app:summary="@string/use_chen_volume_animation_summary"/> + + - + @@ -105,7 +113,7 @@ app:title="@string/miui_unlock_wallpaper_anim_fade_anim_val_title" /> - +