From 7a55cf1a15644cf8c50e5137e47d3280342f1ef8 Mon Sep 17 00:00:00 2001 From: Art_Chen Date: Mon, 29 Jul 2024 00:04:55 +0800 Subject: [PATCH] WallpaperZoomOptimizer: Support OS1 New Arch Home also add adjust for Animation Damping Ratio. NOTE: The Legacy Home previous hard coded dampting ratio to 1.5f, but HyperOS default is 1.0f. Signed-off-by: Art_Chen --- .../miuiextra/hooker/entity/MiuiHomeHook.kt | 13 ++- ...oker.kt => WallpaperZoomOptimizeLegacy.kt} | 11 +- .../home/WallpaperZoomOptimizeOS1NewArch.kt | 102 ++++++++++++++++++ .../view/activity/WallpaperZoomActivity.kt | 7 ++ app/src/main/res/values-ja/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 6 +- app/src/main/res/values/strings.xml | 2 + .../res/xml/wallpaper_zoom_preferences.xml | 14 +++ 8 files changed, 150 insertions(+), 7 deletions(-) rename app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/{WallpaperZoomOptimizeHooker.kt => WallpaperZoomOptimizeLegacy.kt} (96%) create mode 100644 app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeOS1NewArch.kt diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/MiuiHomeHook.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/MiuiHomeHook.kt index 410dccb..621b43d 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/MiuiHomeHook.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/MiuiHomeHook.kt @@ -1,5 +1,6 @@ package moe.chenxy.miuiextra.hooker.entity +import android.util.Log import android.view.View import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker import com.highcapable.yukihookapi.hook.factory.method @@ -12,7 +13,8 @@ import moe.chenxy.miuiextra.BuildConfig import moe.chenxy.miuiextra.hooker.entity.home.AnimationEnhanceHooker import moe.chenxy.miuiextra.hooker.entity.home.IconLaunchAnimHooker import moe.chenxy.miuiextra.hooker.entity.home.ViewBlurHooker -import moe.chenxy.miuiextra.hooker.entity.home.WallpaperZoomOptimizeHooker +import moe.chenxy.miuiextra.hooker.entity.home.WallpaperZoomOptimizeLegacy +import moe.chenxy.miuiextra.hooker.entity.home.WallpaperZoomOptimizeOS1NewArch import moe.chenxy.miuiextra.utils.ChenUtils @@ -39,7 +41,14 @@ object MiuiHomeHook : YukiBaseHooker() { if (zoomPrefs.getBoolean("enable_wallpaper_zoom_optimize", false)) { - loadHooker(WallpaperZoomOptimizeHooker) + val wallpaperElem = "com.miui.home.recents.anim.WallpaperElement".toClassOrNull() + if (wallpaperElem != null) { + Log.i("Art_Chen", "WallpaperZoomOptimizer: OS1 New Arch Home detected!") + loadHooker(WallpaperZoomOptimizeOS1NewArch) + } else { + Log.i("Art_Chen", "WallpaperZoomOptimizer: Legacy Arch Home detected!") + loadHooker(WallpaperZoomOptimizeLegacy) + } } loadHooker(ViewBlurHooker) diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeHooker.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeLegacy.kt similarity index 96% rename from app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeHooker.kt rename to app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeLegacy.kt index d312ed0..e645ff4 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeHooker.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeLegacy.kt @@ -23,7 +23,7 @@ import moe.chenxy.miuiextra.utils.ChenUtils import java.util.concurrent.AbstractExecutorService -object WallpaperZoomOptimizeHooker : YukiBaseHooker() { +object WallpaperZoomOptimizeLegacy : YukiBaseHooker() { private var mSpringAnimation: Any? = null private var zoomInStiffness = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_stiffness_val", 3263).toFloat() / 100 @@ -35,6 +35,9 @@ object WallpaperZoomOptimizeHooker : YukiBaseHooker() { MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_start_velocity_val", 0).toFloat() / 1000 private var zoomOut = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_val", 4).toFloat() / 10 + private var zoomInDampingRatio = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_damping_ratio_val", 100).toFloat() / 100 + private var zoomOutDampingRatio = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_damping_ratio_val", 100).toFloat() / 100 + private var wallpaperZoomThiz: Any? = null private var mZoomedIn = false private var mZoomedOut = 1.0f @@ -80,6 +83,8 @@ object WallpaperZoomOptimizeHooker : YukiBaseHooker() { MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_start_velocity_val", 0) .toFloat() / 1000 accuracyLevel = MiuiHomeHook.zoomPrefs.getInt("wallpaper_accuracy_val", 2) + zoomInDampingRatio = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_damping_ratio_val", 100).toFloat() / 100 + zoomOutDampingRatio = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_damping_ratio_val", 100).toFloat() / 100 } } @@ -131,7 +136,7 @@ object WallpaperZoomOptimizeHooker : YukiBaseHooker() { "setStiffness", zoomInStiffness ) - XposedHelpers.callMethod(mZoomInSpringForce, "setDampingRatio", 1.5f) + XposedHelpers.callMethod(mZoomInSpringForce, "setDampingRatio", zoomInDampingRatio) XposedHelpers.callMethod(mZoomInSpringForce, "setFinalPosition", f) XposedHelpers.callMethod( @@ -154,7 +159,7 @@ object WallpaperZoomOptimizeHooker : YukiBaseHooker() { "setStiffness", zoomOutStiffness ) - XposedHelpers.callMethod(mZoomOutSpringForce, "setDampingRatio", 1.5f) + XposedHelpers.callMethod(mZoomOutSpringForce, "setDampingRatio", zoomOutDampingRatio) XposedHelpers.callMethod(mZoomOutSpringForce, "setFinalPosition", f) XposedHelpers.callMethod( diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeOS1NewArch.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeOS1NewArch.kt new file mode 100644 index 0000000..f11662b --- /dev/null +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/WallpaperZoomOptimizeOS1NewArch.kt @@ -0,0 +1,102 @@ +package moe.chenxy.miuiextra.hooker.entity.home + +import android.annotation.SuppressLint +import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.highcapable.yukihookapi.hook.factory.method +import de.robv.android.xposed.XposedHelpers +import moe.chenxy.miuiextra.hooker.entity.MiuiHomeHook + + +object WallpaperZoomOptimizeOS1NewArch : YukiBaseHooker() { + private lateinit var mZoomInSpringForce: Any + private lateinit var mZoomOutSpringForce: Any + private lateinit var mSpringAnimation: Any + + private var mZoomOut = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_val", 1).toFloat() / 10 + private var zoomOutStartVelocity = + MiuiHomeHook.zoomPrefs.getInt( + "wallpaper_zoomOut_start_velocity_val", + 662 + ).toFloat() / 1000 + private var zoomInStartVelocity = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_start_velocity_val", 0).toFloat() / 1000 + private var accuracyLevel = MiuiHomeHook.zoomPrefs.getInt("wallpaper_accuracy_val", 3) + private val minChange: Float + get() { + return when (accuracyLevel) { + 1 -> 0.1f + 2 -> 0.05f + 3 -> 0.01f + 4 -> 0.005f + 5 -> 0.001f + 6 -> 0.0005f + 7 -> 0.0001f + 8 -> 0.00005f + 9 -> 0.00001f + else -> 0.1f + } + } + + private fun updateSettings(thiz: Any, isZoomOut: Boolean) { + var firstInit = false + if (!this::mZoomInSpringForce.isInitialized) { + mZoomInSpringForce = XposedHelpers.getObjectField(thiz, "mZoomInSpringForce") + mZoomOutSpringForce = XposedHelpers.getObjectField(thiz, "mZoomOutSpringForce") + mSpringAnimation = XposedHelpers.getObjectField(thiz, "mSpringAnimation") + firstInit = true + } + + if (MiuiHomeHook.zoomPrefs.hasFileChanged() || firstInit) { + MiuiHomeHook.zoomPrefs.reload() + val zoomInStiffness = + MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_stiffness_val", 3263) + .toFloat() / 100 + val zoomOutStiffness = + MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_stiffness_val", 3263) + .toFloat() / 100 + + mZoomOut = + MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_val", 1).toFloat() / 10 + zoomInStartVelocity = + MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_start_velocity_val", 0).toFloat() / 1000 + accuracyLevel = MiuiHomeHook.zoomPrefs.getInt("wallpaper_accuracy_val", 2) + + val zoomInDampingRatio = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomIn_damping_ratio_val", 100).toFloat() / 100 + val zoomOutDampingRatio = MiuiHomeHook.zoomPrefs.getInt("wallpaper_zoomOut_damping_ratio_val", 100).toFloat() / 100 + + XposedHelpers.callMethod(mZoomInSpringForce, "setStiffness", zoomInStiffness) + XposedHelpers.callMethod(mZoomInSpringForce, "setDampingRatio", zoomInDampingRatio) + XposedHelpers.callMethod(mZoomOutSpringForce, "setStiffness", zoomOutStiffness) + XposedHelpers.callMethod(mZoomOutSpringForce, "setDampingRatio", zoomOutDampingRatio) +// XposedHelpers.callMethod(mZoomOutSpringForce, "setFinalPosition", mZoomOut) + + XposedHelpers.callMethod(mSpringAnimation, "setMinimumVisibleChange", minChange) + } + + if (isZoomOut) + XposedHelpers.callMethod(mSpringAnimation, "setStartVelocity", zoomOutStartVelocity) + else + XposedHelpers.callMethod(mSpringAnimation, "setStartVelocity", zoomInStartVelocity) + } + + @SuppressLint("UnspecifiedRegisterReceiverFlag") + override fun onHook() { + "com.miui.home.recents.anim.WallpaperElement".toClass().method { + name = "animTo" + paramCount = 1 + }.hook { + before { + val param = this.args[0] ?: return@before + + updateSettings(this.instance, XposedHelpers.callMethod(param, "getZoomOut") as Float == 1.0f) + } + } + + "com.miui.home.recents.anim.WallpaperParam".toClass().method { + name = "getZoomOut" + }.hook { + after { + if (this.result == 0.6f) this.result = mZoomOut + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/moe/chenxy/miuiextra/view/activity/WallpaperZoomActivity.kt b/app/src/main/java/moe/chenxy/miuiextra/view/activity/WallpaperZoomActivity.kt index 00013c9..dcac275 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/view/activity/WallpaperZoomActivity.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/view/activity/WallpaperZoomActivity.kt @@ -114,6 +114,13 @@ class WallpaperZoomActivity : AppCompatActivity() { R.string.wallpaper_accuracy_title ) + bindAnimationSeekBar(findPreference("wallpaper_zoomIn_damping_ratio_val"), 100, + R.string.wallpaper_zoomIn_damping_ratio_summary + ) + bindAnimationSeekBar(findPreference("wallpaper_zoomOut_damping_ratio_val"), 100, + R.string.wallpaper_zoomOut_damping_ratio_summary + ) + val mainSwitch = findPreference("enable_wallpaper_zoom_optimize") val category = findPreference("wallpaper_zoom_anim_custom_category") diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ee1c0f6..f3b4a6b 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -240,4 +240,6 @@ 新しいマップを追加 Weibo HyperOS の世界へ出かけよう! @ Art_Chen + Zoom In Animation Damping Ratio + Zoom Out Animation Damping Ratio diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 61ed55d..d54840a 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -58,8 +58,8 @@ 自定义壁纸缩放动画 通用 缩小动画开始速度 - 缩小动画 Stiffness - 放大动画 Stiffness + 缩小动画阻力 + 放大动画阻力 放大动画开始速度 缩小动画程度 锁屏时自动缩放壁纸 @@ -128,4 +128,6 @@ 透明动画将调整透明度而不是模糊级别,并将去除模糊材质 手势栏隐藏时隐藏小白条 动画精度等级 + 放大动画回弹系数 + 缩小动画回弹系数 \ 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 fe645a4..ba595c6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -130,4 +130,6 @@ Transparent Anim will adjust alpha and drop blur effect Workaround Home Handle Not Hidden Animation Accuracy Level + Zoom In Animation Damping Ratio + Zoom Out Animation Damping Ratio \ No newline at end of file diff --git a/app/src/main/res/xml/wallpaper_zoom_preferences.xml b/app/src/main/res/xml/wallpaper_zoom_preferences.xml index 2c41e37..76f9110 100644 --- a/app/src/main/res/xml/wallpaper_zoom_preferences.xml +++ b/app/src/main/res/xml/wallpaper_zoom_preferences.xml @@ -19,6 +19,13 @@ app:min="-3000" app:updatesContinuously="true" app:title="@string/wallpaper_zoomIn_start_velocity_summary" /> + +