Skip to content

Commit

Permalink
HomeHandleAnim: Workaround MiuiHome Mi Blur freeze issue
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Art-Chen committed Jun 22, 2024
1 parent d425be8 commit 614dda8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -41,6 +42,8 @@ object MiuiHomeHook : YukiBaseHooker() {
loadHooker(WallpaperZoomOptimizeHooker)
}

loadHooker(ViewBlurHooker)


"com.miui.home.launcher.compat.UserPresentAnimationCompatV12Phone".toClass().apply {
method {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

Expand Down

0 comments on commit 614dda8

Please sign in to comment.