From 614dda8f060b9fe1f7cb170f0914b270ed1c072f Mon Sep 17 00:00:00 2001 From: Art_Chen Date: Sat, 22 Jun 2024 23:33:02 +0800 Subject: [PATCH] HomeHandleAnim: Workaround MiuiHome Mi Blur freeze issue HyperCeiler attached MiBlur View for replaced Original Window Blur, but Mi Blur will draw only top layer. Unfortunately, NavBar has higher z-index than MiuiHome Blur view if we active the blur for home handle caused home blur view freezed. Deactive blur if home view rect blur active and reactive it when home blur view radius return to zero. Signed-off-by: Art_Chen --- .../miuiextra/hooker/entity/MiuiHomeHook.kt | 3 ++ .../entity/home/IconLaunchAnimHooker.kt | 1 + .../hooker/entity/home/ViewBlurHooker.kt | 45 +++++++++++++++++++ .../systemui/HomeHandleAnimatorHooker.kt | 26 ++++++++++- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/ViewBlurHooker.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 03ff91c..410dccb 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 @@ -11,6 +11,7 @@ import de.robv.android.xposed.XposedHelpers 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.utils.ChenUtils @@ -41,6 +42,8 @@ object MiuiHomeHook : YukiBaseHooker() { loadHooker(WallpaperZoomOptimizeHooker) } + loadHooker(ViewBlurHooker) + "com.miui.home.launcher.compat.UserPresentAnimationCompatV12Phone".toClass().apply { method { diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/IconLaunchAnimHooker.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/IconLaunchAnimHooker.kt index 8c4c034..95d9002 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/IconLaunchAnimHooker.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/IconLaunchAnimHooker.kt @@ -6,6 +6,7 @@ import com.highcapable.yukihookapi.hook.core.YukiMemberHookCreator import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker import com.highcapable.yukihookapi.hook.factory.method import com.highcapable.yukihookapi.hook.type.android.MotionEventClass +import com.highcapable.yukihookapi.hook.type.android.ViewClass import de.robv.android.xposed.XposedHelpers import moe.chenxy.miuiextra.hooker.entity.MiuiHomeHook diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/ViewBlurHooker.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/ViewBlurHooker.kt new file mode 100644 index 0000000..7b7aef2 --- /dev/null +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/home/ViewBlurHooker.kt @@ -0,0 +1,45 @@ +package moe.chenxy.miuiextra.hooker.entity.home + +import android.content.Context +import android.content.Intent +import android.util.Log +import android.view.View +import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.highcapable.yukihookapi.hook.factory.method +import com.highcapable.yukihookapi.hook.type.android.ViewClass +import com.highcapable.yukihookapi.hook.type.java.IntType +import de.robv.android.xposed.XposedHelpers + +object ViewBlurHooker : YukiBaseHooker() { + override fun onHook() { + var launcherBlurActivated = false + + fun View.getMiViewBlurModeCompat() = XposedHelpers.callMethod( + this, "getMiViewBlurMode") as Int + // Workaround NavBar zindex higher than launcher caused mi blur not draw the blur view + ViewClass.apply { + method { + name = "setMiBackgroundBlurRadius" + param(IntType) + }.hook { + before { + if ((this.instance as View).getMiViewBlurModeCompat() != 1) { + return@before + } + Log.i("Art_Chen", "setMiBackgroundBlurRadius ${this.args[0]}") + val isActive = this.args[0] as Int > 0 +// if (isActive == launcherBlurActivated) return@before +// +// launcherBlurActivated = isActive + + val mContext = XposedHelpers.getObjectField(this.instance, "mContext") as Context + val intent = Intent("chen.action.home.blur.state.switched") + intent.`package`= "com.android.systemui" + intent.putExtra("active", isActive) + mContext.sendBroadcast(intent) + } + } + } + } + +} \ 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 67c671d..11aec0d 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 @@ -2,9 +2,11 @@ package moe.chenxy.miuiextra.hooker.entity.systemui import android.animation.ValueAnimator import android.annotation.SuppressLint +import android.content.BroadcastReceiver import android.content.ComponentName import android.content.Context import android.content.Intent +import android.content.IntentFilter import android.graphics.Insets import android.graphics.Point import android.os.Handler @@ -230,7 +232,8 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { if (currBlurRadius != 0) { currBlurRadius = 0 mHomeHandle.setMiBackgroundBlurRadius(currBlurRadius) - mHomeHandle.setPassWindowBlurEnabledCompat(false) +// mHomeHandle.setPassWindowBlurEnabledCompat(false) + mHomeHandle.setMiBackgroundBlurModeCompat(0) } alphaAnimator.removeAllListeners() alphaAnimator.addUpdateListener { @@ -303,7 +306,8 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { alphaAnimator.doOnEnd { if (currBlurRadius == 0) { // Clear Blur if radius == 0 - mHomeHandle.setPassWindowBlurEnabledCompat(false) +// mHomeHandle.setPassWindowBlurEnabledCompat(false) + mHomeHandle.setMiBackgroundBlurModeCompat(0) } } } @@ -370,6 +374,12 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { if (!motionTriggered) opacityHomeHandle(EventType.HOME) } + fun onHomeBlurChanged(active: Boolean) { +// Log.i("Art_Chen", "Home Blur State changed: $active") + if (!useMiBlur) return + + mHomeHandle.setMiBackgroundBlurModeCompat(if (active) 0 else 1) + } var baseX = -1f var baseY = -1f @@ -515,6 +525,18 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { }) Log.i("Art_Chen", "ChenInputEventDispatcher registered!") } + + // Register Home Blur State Changed Event Listener + val blurEventListener = object : BroadcastReceiver() { + override fun onReceive(p0: Context?, p1: Intent?) { + val isActive = p1?.getBooleanExtra("active", false) + isActive?.let { + onHomeBlurChanged(it) + } + } + } + + mContext!!.registerReceiver(blurEventListener, IntentFilter("chen.action.home.blur.state.switched")) } }