Skip to content

Commit

Permalink
SystemUI: VolumePanelAnimator: add scale and stretch effect
Browse files Browse the repository at this point in the history
* Also fixed the unnecessary animation when already on the top

Signed-off-by: Art_Chen <[email protected]>
  • Loading branch information
Art-Chen committed Nov 3, 2023
1 parent 0fa05e2 commit f5e0751
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -55,5 +92,14 @@ object ChenVolumePanelAnimator : YukiBaseHooker() {
lastIsBottomHaptic = isBottomHaptic
}
}

"com.android.systemui.miui.volume.MiuiVolumeDialogImpl$6".toClass().method {
name = "onDismiss"
}.hook {
after {
isDismissed = true
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down Expand Up @@ -148,29 +149,8 @@ class SettingsActivity : AppCompatActivity() {
return@setOnPreferenceChangeListener true
}

findPreference<SwitchPreferenceCompat>("use_chen_screen_on_anim")?.setOnPreferenceChangeListener { _, _ ->
showRebootSnackBar(null, SHELL_RESTART_MI_WALLPAPER)
return@setOnPreferenceChangeListener true
}

val animTurboMode = findPreference<SwitchPreferenceCompat>("chen_home_handle_anim_turbo_mode")
val immersionMode = findPreference<SwitchPreferenceCompat>("chen_home_handle_no_space")
findPreference<SwitchPreferenceCompat>("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<SeekBarPreference>("screen_on_color_fade_anim_val")
val colorFadeOffCustom = findPreference<SeekBarPreference>("screen_off_color_fade_anim_val")
val colorFadeCustom = findPreference<SwitchPreferenceCompat>("color_fade_anim_smoothly")
Expand Down Expand Up @@ -223,11 +203,6 @@ class SettingsActivity : AppCompatActivity() {
return@setOnPreferenceChangeListener true
}

findPreference<SwitchPreferenceCompat>("disable_wallpaper_auto_darken")?.setOnPreferenceChangeListener { _, newValue ->
showRebootSnackBar(null, SHELL_RESTART_MI_WALLPAPER)
return@setOnPreferenceChangeListener true
}

findPreference<SwitchPreferenceCompat>("use_chen_volume_animation")?.setOnPreferenceChangeListener { _, newValue ->
showRebootSnackBar(null, SHELL_RESTART_SYSTEMUI)
return@setOnPreferenceChangeListener true
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@
<string name="blur_scale_val_title">模糊缩放程度</string>
<string name="chen_home_handle_scale_on_full_transparent_title">小白条隐藏或出现时应用缩放效果</string>
<string name="chen_home_handle_blur_effect_title">在小白条上应用模糊材质(需要开启高级材质)</string>
<string name="chen_volume_animation_effect_title">音量条动画效果</string>
<string name="shift">位移</string>
<string name="stretch">拉伸</string>
<string name="shift_and_stretch">位移 + 拉伸</string>
<string name="scale">缩放</string>
<string name="shift_and_scale">位移 + 缩放</string>
</resources>
10 changes: 10 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
<item>com.android.systemui</item>
<item>com.miui.miwallpaper</item>
</string-array>
<string-array name="volume_animation_effect_entries">
<item>@string/shift</item>
<item>@string/stretch</item>
<item>@string/scale</item>
</string-array>
<string-array name="volume_animation_effect_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@
<string name="blur_scale_val_title">Blur Scale degree</string>
<string name="chen_home_handle_scale_on_full_transparent_title">Scale home handle when dismiss or appeared</string>
<string name="chen_home_handle_blur_effect_title">Apply Mi Blur Effect on Home Handle</string>
<string name="chen_volume_animation_effect_title">Volume Animation Effect</string>
<string name="shift">Shift</string>
<string name="stretch">Stretch</string>
<string name="shift_and_stretch">Shift and Stretch</string>
<string name="scale">Scale</string>
<string name="shift_and_scale">Shift and Scale</string>
</resources>
12 changes: 10 additions & 2 deletions app/src/main/res/xml/chen_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

<rikka.preference.SimpleMenuPreference
app:key="chen_volume_animation_effect"
app:dependency="use_chen_volume_animation"
app:title="@string/chen_volume_animation_effect_title"
app:entries="@array/volume_animation_effect_entries"
app:summary="%s"
app:entryValues="@array/volume_animation_effect_values" />
</PreferenceCategory>

<PreferenceCategory app:title="@string/wallpaper_header">
<PreferenceCategory app:title="@string/wallpaper_header" app:key="wallpaper_settings">
<Preference
app:key="wallpaper_zoom"
app:title="@string/wallpaper_scale_title" />
Expand Down Expand Up @@ -105,7 +113,7 @@
app:title="@string/miui_unlock_wallpaper_anim_fade_anim_val_title" />
</PreferenceCategory>

<PreferenceCategory app:title="@string/home_handle_header">
<PreferenceCategory app:title="@string/home_handle_header" app:key="home_handle">
<rikka.material.preference.MaterialSwitchPreference
app:key="chen_home_handle_anim"
app:title="@string/chen_home_handle_anim_title"
Expand Down

0 comments on commit f5e0751

Please sign in to comment.