Skip to content

Commit

Permalink
WallpaperZoomOptimizer: Support OS1 New Arch Home
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Art-Chen committed Jul 28, 2024
1 parent d6b8e7e commit 7a55cf1
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainSwitchPreference>("enable_wallpaper_zoom_optimize")
val category = findPreference<PreferenceCategory>("wallpaper_zoom_anim_custom_category")

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,6 @@
<string name="want_to_map_id">新しいマップを追加</string>
<string name="weibo_title">Weibo</string>
<string name="xposed_desc">HyperOS の世界へ出かけよう! @ Art_Chen</string>
<string name="wallpaper_zoomIn_damping_ratio_summary">Zoom In Animation Damping Ratio</string>
<string name="wallpaper_zoomOut_damping_ratio_summary">Zoom Out Animation Damping Ratio</string>
</resources>
6 changes: 4 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
<string name="wallpaper_zoom_anim_custom_header">自定义壁纸缩放动画</string>
<string name="wallpaper_zoom_anim_common_header">通用</string>
<string name="wallpaper_zoomOut_start_velocity_summary">缩小动画开始速度</string>
<string name="wallpaper_zoomOut_stiffness_summary">缩小动画 Stiffness</string>
<string name="wallpaper_zoomIn_stiffness_summary">放大动画 Stiffness</string>
<string name="wallpaper_zoomOut_stiffness_summary">缩小动画阻力</string>
<string name="wallpaper_zoomIn_stiffness_summary">放大动画阻力</string>
<string name="wallpaper_zoomIn_start_velocity_summary">放大动画开始速度</string>
<string name="wallpaper_zoomOut_summary">缩小动画程度</string>
<string name="wallpaper_auto_zoom_on_lockscreen_title">锁屏时自动缩放壁纸</string>
Expand Down Expand Up @@ -128,4 +128,6 @@
<string name="home_handle_force_alpha_at_home_summary">透明动画将调整透明度而不是模糊级别,并将去除模糊材质</string>
<string name="home_handle_wa_no_space_not_hide_title">手势栏隐藏时隐藏小白条</string>
<string name="wallpaper_accuracy_title">动画精度等级</string>
<string name="wallpaper_zoomIn_damping_ratio_summary">放大动画回弹系数</string>
<string name="wallpaper_zoomOut_damping_ratio_summary">缩小动画回弹系数</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,6 @@
<string name="home_handle_force_alpha_at_home_summary">Transparent Anim will adjust alpha and drop blur effect</string>
<string name="home_handle_wa_no_space_not_hide_title">Workaround Home Handle Not Hidden</string>
<string name="wallpaper_accuracy_title">Animation Accuracy Level</string>
<string name="wallpaper_zoomIn_damping_ratio_summary">Zoom In Animation Damping Ratio</string>
<string name="wallpaper_zoomOut_damping_ratio_summary">Zoom Out Animation Damping Ratio</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/xml/wallpaper_zoom_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
app:min="-3000"
app:updatesContinuously="true"
app:title="@string/wallpaper_zoomIn_start_velocity_summary" />
<SeekBarPreference
android:max="300"
app:key="wallpaper_zoomIn_damping_ratio_val"
app:defaultValue="100"
app:min="100"
app:updatesContinuously="true"
app:title="@string/wallpaper_zoomIn_damping_ratio_summary" />
<SeekBarPreference
android:max="30000"
app:key="wallpaper_zoomOut_stiffness_val"
Expand All @@ -33,6 +40,13 @@
app:min="-3000"
app:updatesContinuously="true"
app:title="@string/wallpaper_zoomOut_start_velocity_summary" />
<SeekBarPreference
android:max="300"
app:key="wallpaper_zoomOut_damping_ratio_val"
app:defaultValue="100"
app:min="100"
app:updatesContinuously="true"
app:title="@string/wallpaper_zoomOut_damping_ratio_summary" />
<SeekBarPreference
android:max="10"
app:key="wallpaper_zoomOut_val"
Expand Down

0 comments on commit 7a55cf1

Please sign in to comment.