Skip to content

Commit

Permalink
HomeHandleAnim: Major improvement
Browse files Browse the repository at this point in the history
* Allow User to control we apply the wa for immersive mode now
* Allow user to hidden the home handle on the home screen as before
  (even enabled blur option)
* Drop event if scaleX or Y is less or equals 0, home handle is not
  visible.

Signed-off-by: Art_Chen <[email protected]>
  • Loading branch information
Art-Chen committed May 20, 2024
1 parent bac3f51 commit 6fea1d8
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "moe.chenxy.miuiextra"
minSdk 31
targetSdk 34
versionCode 16
versionName "2.6.9.2-U-Pre_Hyper"
versionCode 18
versionName "2.6.9.4-U-HyperOS"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 16,
"versionName": "2.6.9.2-U-Pre_Hyper",
"versionCode": 18,
"versionName": "2.6.9.4-U-HyperOS",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Binder
import android.os.Parcel
import android.os.VibrationEffect
import android.util.Log
import android.view.Display
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.hook.factory.method
import com.highcapable.yukihookapi.hook.type.android.IBinderClass
Expand All @@ -33,7 +34,7 @@ object SystemHooker : YukiBaseHooker() {
override fun onHook() {
// Vibrator Mapper
loadHooker(VibratorMapHooker)
loadHooker(StartingWindowOptimize)
// loadHooker(StartingWindowOptimize)

// Hook for Wallpaper Scale Settings
"com.android.server.wm.WallpaperController".toClass().method {
Expand Down Expand Up @@ -82,33 +83,33 @@ object SystemHooker : YukiBaseHooker() {

// ColorFade Animation Customize
if (mainPrefs.getBoolean("color_fade_anim_smoothly", false)) {
"com.android.server.display.DisplayPowerController".toClass().method {
name = "initialize"
param(IntType)
}.hook {
after {
mainPrefs.reload()
val mContext =
XposedHelpers.getObjectField(this.instance, "mContext") as Context
val mColorFadeOffAnimator = XposedHelpers.getObjectField(
this.instance,
"mColorFadeOffAnimator"
) as ObjectAnimator
mColorFadeOffAnimator.duration =
mainPrefs.getInt("screen_off_color_fade_anim_val", 450).toLong()

val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
mainPrefs.reload()
mColorFadeOffAnimator.duration =
mainPrefs.getInt("screen_off_color_fade_anim_val", 450).toLong()
"com.android.server.display.DisplayPowerController".toClass().apply {
method {
name = "initialize"
param(IntType)
}.hook {
after {
mainPrefs.reload()
val mContext =
XposedHelpers.getObjectField(this.instance, "mContext") as Context
val mColorFadeOffAnimator = XposedHelpers.getObjectField(
this.instance,
"mColorFadeOffAnimator"
) as ObjectAnimator
mColorFadeOffAnimator.duration =
mainPrefs.getInt("screen_off_color_fade_anim_val", 450).toLong()
val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
mainPrefs.reload()
mColorFadeOffAnimator.duration =
mainPrefs.getInt("screen_off_color_fade_anim_val", 450).toLong()
}
}

mContext.registerReceiver(
broadcastReceiver,
IntentFilter("chen.miui.extra.update.colorfade")
)
}
mContext.registerReceiver(
broadcastReceiver,
IntentFilter("chen.miui.extra.update.colorfade")
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
var isHidden = false
var lastIsHidden = false
var disableHomeHandleMovement = mainPrefs.getBoolean("home_handle_disable_move_event", false)
var forceAlphaAtHome = mainPrefs.getBoolean("home_handle_force_alpha_at_home", false)

fun getSetting(type: EventType): HomeHandleSettings {
return HomeHandleSettings(
Expand All @@ -113,6 +114,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {

disableHomeHandleMovement = mainPrefs.getBoolean("home_handle_disable_move_event", false)
useMiBlur = mainPrefs.getBoolean("chen_home_handle_blur_effect", false)
forceAlphaAtHome = mainPrefs.getBoolean("home_handle_force_alpha_at_home", false)
}
}

Expand Down Expand Up @@ -147,21 +149,6 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
zoomYAnimator.start()
}

// fun animateHomeHandleZoom(zoomType: ZoomType) {
// val duration =
// when (zoomType) {
// ZoomType.ZOOM_IN -> 600
// ZoomType.NORMAL_FOR_OPACITY, ZoomType.ZOOM_OUT -> 800
// else -> 400
// }
// zoomValueAnimator!!.setFloatValues(mHomeHandle.scaleX, if (zoomType == ZoomType.ZOOM_IN) 1.05f else if (zoomType == ZoomType.ZOOM_OUT) 0.9f else 1.0f)
//
//
// zoomValueAnimator!!.start()
// animateZoomTo()
// }


fun animateHomeHandleX(duration: Long, offset: Float) {
if (!this::xAnimator.isInitialized) {
xAnimator = ValueAnimator()
Expand Down Expand Up @@ -209,6 +196,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
}

var currBlurRadius = 0
var lastBlurRadius = 0
val opacityHomeHandleRunnable = Runnable {
if (alphaAnimator.isRunning) {
alphaAnimator.cancel()
Expand All @@ -223,25 +211,31 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
} else {
// Adjust Blur Radius
currBlurRadius = (it.animatedValue as Float).toInt()
mHomeHandle.setMiBackgroundBlurRadius(currBlurRadius)
// setRadius is expensive
if (currBlurRadius != lastBlurRadius)
mHomeHandle.setMiBackgroundBlurRadius(currBlurRadius)
lastBlurRadius = currBlurRadius
}
}

fun opacityTo(to: Float, duration: Long, forceAlpha: Boolean = false) {
fun opacityTo(to: Float, duration: Long) {
if (!this::alphaAnimator.isInitialized) {
alphaAnimator = ValueAnimator()
}
if (alphaAnimator.isRunning) alphaAnimator.end()

alphaAnimator.duration = duration
alphaAnimator.setFloatValues(mHomeHandle.alpha, to)

if (forceAlpha)
alphaAnimator.addUpdateListener {
mHomeHandle.alpha = it.animatedValue as Float
}
else
alphaAnimator.addUpdateListener(doOnOpacityUpdate)

if (currBlurRadius != 0) {
currBlurRadius = 0
mHomeHandle.setMiBackgroundBlurRadius(currBlurRadius)
mHomeHandle.setPassWindowBlurEnabledCompat(false)
}
alphaAnimator.removeAllListeners()
alphaAnimator.addUpdateListener {
mHomeHandle.alpha = it.animatedValue as Float
}
alphaAnimator.start()
}

Expand All @@ -256,8 +250,15 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
alphaAnimator = ValueAnimator()
}

if (forceAlphaAtHome && useMiBlur && type == EventType.HOME) {
// Force Alpha At Home
opacityTo(1 - (onHomeSettings.transDegree.toFloat() / 100), onHomeSettings.alphaAnimDuration)
animateZoomTo(onHomeSettings.scaleX, onHomeSettings.scaleY, onHomeSettings.scaleAnimDuration)
return
}

if (alphaAnimator.isRunning) {
if (mIsInHome) {
if (type == EventType.HOME) {
alphaAnimator.cancel()
} else {
alphaAnimator.doOnEnd {
Expand Down Expand Up @@ -389,7 +390,8 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
if (mHandler != null) {
mHandler!!.post {
if (motionEvent.actionMasked == MotionEvent.ACTION_DOWN
&& (mHomeHandle.alpha == 0f || (mHomeHandle.windowVisibility != View.VISIBLE || isHidden))) {
&& (mHomeHandle.alpha == 0f || mHomeHandle.scaleX <= 0f || mHomeHandle.scaleY <= 0f
|| (mHomeHandle.windowVisibility != View.VISIBLE || isHidden))) {
// drop if home handle is transparent.
return@post
}
Expand Down Expand Up @@ -693,7 +695,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
}
}

if (mainPrefs.getBoolean("chen_home_handle_no_space", false)) {
if (mainPrefs.getBoolean("home_handle_wa_no_space_not_hide", false)) {
// Workaround immersive mode can not hide the handle
"com.android.systemui.navigationbar.NavigationBar".toClass().method {
name("setWindowState")
Expand All @@ -707,8 +709,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() {
if (lastIsHidden == isHidden) return@after

if (isHidden) {
// opacityTo(0f, 300, forceAlpha = true)
mHomeHandle.alpha = 0f
opacityTo(0f, 300)
} else {
opacityHomeHandle(EventType.NORMAL)
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@
<string name="home_handle_anim_duration_scale">Scale Anim Duration</string>
<string name="home_handle_anim_duration_xy">Zoom Anim Duration</string>
<string name="home_handle_disable_move_event_title">Disable Home Handle Movement</string>
<string name="home_handle_force_alpha_at_home_title">Force to use alpha anim at home</string>
<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>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@
<string name="home_handle_anim_duration_scale">缩放动画时长</string>
<string name="home_handle_anim_duration_xy">位移动画时长</string>
<string name="home_handle_disable_move_event_title">禁用小白条跟手位移</string>
<string name="home_handle_force_alpha_at_home_title">在桌面时强制使用透明度调整</string>
<string name="home_handle_force_alpha_at_home_summary">透明动画将调整透明度而不是模糊级别,并将去除模糊材质</string>
<string name="home_handle_wa_no_space_not_hide_title">手势栏隐藏时隐藏小白条</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@
<string name="home_handle_anim_duration_scale">Scale Anim Duration</string>
<string name="home_handle_anim_duration_xy">Zoom Anim Duration</string>
<string name="home_handle_disable_move_event_title">Disable Home Handle Movement</string>
<string name="home_handle_force_alpha_at_home_title">Force to use alpha anim at home</string>
<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>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/chen_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
app:title="@string/chen_home_handle_no_space_title"
app:summary="@string/chen_home_handle_no_space_summary"/>

<rikka.material.preference.MaterialSwitchPreference
app:key="home_handle_wa_no_space_not_hide"
app:dependency="chen_home_handle_no_space"
app:title="@string/home_handle_wa_no_space_not_hide_title" />

<Preference
app:key="home_handle_anim_custom"
app:dependency="chen_home_handle_anim"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/home_handle_anim_pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,9 @@
app:min="0"
app:updatesContinuously="true"
app:title="@string/home_handle_anim_duration_xy" />
<rikka.material.preference.MaterialSwitchPreference
app:key="home_handle_force_alpha_at_home"
app:title="@string/home_handle_force_alpha_at_home_title"
app:summary="@string/home_handle_force_alpha_at_home_summary" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 6fea1d8

Please sign in to comment.