From 0fa05e21a891bffbacce5c2c5b0bc3e920bee866 Mon Sep 17 00:00:00 2001 From: Art_Chen Date: Thu, 2 Nov 2023 02:12:59 +0800 Subject: [PATCH] SystemUI: HomeHandle: add Mi Blur Effect Signed-off-by: Art_Chen --- .../systemui/HomeHandleAnimatorHooker.kt | 97 +++++++++++++++++-- .../entity/systemui/MiBlurCompatUtils.kt | 29 ++++++ app/src/main/res/values-zh-rCN/strings.xml | 15 +-- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/chen_preferences.xml | 6 ++ 5 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/MiBlurCompatUtils.kt 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 60e9a0e..e9eeddc 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 @@ -5,6 +5,7 @@ import android.annotation.SuppressLint import android.content.ComponentName import android.content.Context import android.content.Intent +import android.graphics.Color import android.graphics.Insets import android.graphics.Point import android.os.Handler @@ -27,11 +28,17 @@ import com.highcapable.yukihookapi.hook.type.android.AttributeSetClass import com.highcapable.yukihookapi.hook.type.android.ContextClass import com.highcapable.yukihookapi.hook.type.android.LayoutInflaterClass import com.highcapable.yukihookapi.hook.type.android.ViewGroupClass +import com.highcapable.yukihookapi.hook.type.java.FloatType import com.highcapable.yukihookapi.hook.type.java.IntType import com.highcapable.yukihookapi.hook.type.java.StringClass import de.robv.android.xposed.XSharedPreferences import de.robv.android.xposed.XposedHelpers import moe.chenxy.miuiextra.BuildConfig +import moe.chenxy.miuiextra.hooker.entity.systemui.MiBlurCompatUtils.isSupportMiBlur +import moe.chenxy.miuiextra.hooker.entity.systemui.MiBlurCompatUtils.setMiBackgroundBlurModeCompat +import moe.chenxy.miuiextra.hooker.entity.systemui.MiBlurCompatUtils.setMiBackgroundBlurRadius +import moe.chenxy.miuiextra.hooker.entity.systemui.MiBlurCompatUtils.setMiViewBlurMode +import moe.chenxy.miuiextra.hooker.entity.systemui.MiBlurCompatUtils.setPassWindowBlurEnabledCompat import moe.chenxy.miuiextra.utils.ChenUtils import java.lang.reflect.Proxy import kotlin.math.abs @@ -67,8 +74,13 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { var barHeight = 0 var origBarHeight = 0 val yOffset = mainPrefs.getInt("home_handle_y_val", 7) - val mEnabledHomeAutoTransparent = + var mEnabledHomeAutoTransparent = mainPrefs.getBoolean("chen_home_handle_full_transparent_at_miuihome", false) + var useMiBlur = mainPrefs.getBoolean("chen_home_handle_blur_effect", false) + var mLightColor = -1 + var mDarkColor = -1 + var mNavigationHandle : Any? = null + var currentIntensity = -1; fun animateHomeHandleZoom(zoomType: ZoomType) { if (zoomValueAnimator == null) { zoomValueAnimator = ValueAnimator() @@ -130,7 +142,15 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { animateHomeHandleY(600, yOffset.toFloat()) } + fun setDarkIntensity(int: Int) { + if (mNavigationHandle != null) { + XposedHelpers.callMethod(mNavigationHandle, "setDarkIntensity", int) + } + } + var mPendingOpacityStatus: Boolean + var isTransparent = false + val maxBlurRadius = 20 val opacityHomeHandleRunnable = Runnable { if (homeHandleAlphaAnimator.isRunning) { homeHandleAlphaAnimator.cancel() @@ -138,15 +158,25 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { homeHandleAlphaAnimator.start() } homeHandleAlphaAnimator.addUpdateListener { - mHomeHandle.alpha = it.animatedValue as Float + if (!useMiBlur || !mHomeHandle.isSupportMiBlur() || mainPrefs.getBoolean("chen_home_handle_auto_transparent", false)) { + mHomeHandle.alpha = it.animatedValue as Float + } else { + if (isTransparent) { + mHomeHandle.alpha = it.animatedValue as Float + } else if (mHomeHandle.alpha == 0f) { + mHomeHandle.alpha = 1f + } + mHomeHandle.setMiBackgroundBlurRadius(((it.animatedValue as Float) * maxBlurRadius).toInt()) + } } fun opacityHomeHandle(needOpacity: Boolean, needToTransparent: Boolean) { mainPrefs.reload() val autoTransparent = mainPrefs.getBoolean("chen_home_handle_auto_transparent", false) val useScaleEffect = mainPrefs.getBoolean("home_handle_scale_on_full_transparent", false) + useMiBlur = mainPrefs.getBoolean("chen_home_handle_blur_effect", false) val isHome = mIsInHome - if (!autoTransparent && needOpacity && !needToTransparent) { + if (!autoTransparent && needOpacity && !needToTransparent && !useMiBlur) { return } if (homeHandleAlphaAnimator.isRunning) { @@ -157,7 +187,16 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { homeHandleAlphaAnimator.doOnEnd { it.removeAllListeners() homeHandleAlphaAnimator.addUpdateListener { it1 -> - mHomeHandle.alpha = it1.animatedValue as Float + if (!useMiBlur || !mHomeHandle.isSupportMiBlur()) { + mHomeHandle.alpha = it1.animatedValue as Float + } else { + if (isTransparent) { + mHomeHandle.alpha = it1.animatedValue as Float + } else if (mHomeHandle.alpha == 0f) { + mHomeHandle.alpha = 1f + } + mHomeHandle.setMiBackgroundBlurRadius(((it1.animatedValue as Float) * maxBlurRadius).toInt()) + } } opacityHomeHandle(mPendingOpacityStatus, needToTransparent) } @@ -176,6 +215,29 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { else 400 + if (needOpacity && !needToTransparent && useMiBlur) { + if (mHomeHandle.isSupportMiBlur()) { + mHomeHandle.alpha = 1f + mDarkColor = 0x55191919.toInt() + mLightColor = 0x77ffffff.toInt() + mHomeHandle.setMiBackgroundBlurModeCompat(1) + mHomeHandle.setPassWindowBlurEnabledCompat(true) + mHomeHandle.setMiViewBlurMode(2) + mHomeHandle.setMiBackgroundBlurRadius(maxBlurRadius) +// setDarkIntensity(currentIntensity) + } + } else { + if (mHomeHandle.isSupportMiBlur()) { + mDarkColor = 0xcc191919.toInt() + mLightColor = 0xb3ffffff.toInt() + mHomeHandle.setMiBackgroundBlurModeCompat(0) + mHomeHandle.setPassWindowBlurEnabledCompat(false) +// mHomeHandle.setMiViewBlurMode(1) + mHomeHandle.setMiBackgroundBlurRadius(0) + } + } + + isTransparent = needToTransparent // homeHandleAlphaAnimator.interpolator = PathInterpolator(0.39f, 0f, 0.11f, 1.02f) homeHandleAlphaAnimator.setFloatValues( mHomeHandle.alpha, @@ -350,7 +412,13 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { } mHomeHandle = mHorizontal.findViewById(mHomeHandleId) mHomeHandle.translationY = yOffset.toFloat() - mHomeHandle.alpha = if (mIsInHome) 0f else if (autoTransparent) 0.7f else 1f + if (!useMiBlur || !mHomeHandle.isSupportMiBlur()) { + mHomeHandle.alpha = if (mIsInHome) 0f else if (autoTransparent) 0.7f else 1f + } else { + mHomeHandle.alpha = if (mIsInHome) 0f else 1f + // init mi blur + opacityHomeHandle(true, false) + } animateHomeHandleToNormal() } } @@ -466,7 +534,7 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { val intent = Intent("chen.action.top_activity.switched") val mUtilsContext = XposedHelpers.getObjectField(this.instance, "mContext") as Context - + mEnabledHomeAutoTransparent = mainPrefs.getBoolean("chen_home_handle_full_transparent_at_miuihome", false) if (currentTopActivity.packageName == "com.miui.home") { // Log.i("Art_Chen", "Current Top Activity is MiuiHome, do sth") @@ -487,6 +555,23 @@ object HomeHandleAnimatorHooker : YukiBaseHooker() { mUtilsContext.sendBroadcast(intent) } } + + "com.android.systemui.navigationbar.gestural.NavigationHandle".toClass().method { + name = "setDarkIntensity" + param(FloatType) + }.hook { + before { + if (mDarkColor == -1) { + mDarkColor = XposedHelpers.getIntField(this.instance, "mDarkColor") + mLightColor = XposedHelpers.getIntField(this.instance, "mLightColor") + mNavigationHandle = this.instance + } else { + XposedHelpers.setIntField(this.instance, "mDarkColor", mDarkColor) + XposedHelpers.setIntField(this.instance, "mLightColor", mLightColor) + } + currentIntensity = this.args[0] as Int + } + } } private fun getScreenHeight(context: Context): Int { diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/MiBlurCompatUtils.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/MiBlurCompatUtils.kt new file mode 100644 index 0000000..a559249 --- /dev/null +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/systemui/MiBlurCompatUtils.kt @@ -0,0 +1,29 @@ +package moe.chenxy.miuiextra.hooker.entity.systemui + +import android.view.View +import de.robv.android.xposed.XposedHelpers +import moe.chenxy.miuiextra.hooker.entity.systemui.StatusBarBlurUtilsHooker.toClass + +object MiBlurCompatUtils { + private val blurCompatCls = "com.miui.systemui.util.MiBlurCompat".toClass() + + @JvmStatic + fun View.setPassWindowBlurEnabledCompat(enable: Boolean) = XposedHelpers.callStaticMethod( + blurCompatCls, "setPassWindowBlurEnabledCompat", this, enable) + + @JvmStatic + fun View.setMiBackgroundBlurModeCompat(mode: Int) = XposedHelpers.callMethod( + this, "setMiBackgroundBlurMode", mode) + + @JvmStatic + fun View.setMiBackgroundBlurRadius(radius: Int) = + XposedHelpers.callMethod(this, "setMiBackgroundBlurRadius", radius) + + @JvmStatic + fun View.setMiViewBlurMode(mode: Int) = + XposedHelpers.callMethod(this, "setMiViewBlurMode", mode) + + @JvmStatic + fun View.isSupportMiBlur() = + XposedHelpers.callStaticMethod(blurCompatCls, "getBackgroundBlurOpened", this.context) as Boolean +} \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 8912273..3c61889 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -9,9 +9,9 @@ 重映射普通震动为特效震动(线性马达震动) 壁纸缩放设置 自定义壁纸缩放比例 - 启用MIUI自定义高刷新率特性 - 禁用MIUI刷新率策略 - 刷新率将由MIUI动态控制 + 启用自定义高刷新率特性 + 禁用刷新率策略 + 刷新率将由系统动态控制 刷新率将保持为您的设置 90Hz 游戏应用 @@ -38,8 +38,8 @@ 重启 更舒服的亮灭屏动画 让Color Fade动画比MIUI原来的设置更慢一些 (俺的动画!!!!) - 优化MIUI音乐通知 - 修复MIUI异常的歌曲切换动画和App不规范导致的专辑图不同步问题 + 优化音乐通知 + 修复异常的歌曲切换动画和App不规范导致的专辑图不同步问题 优化音乐通知的文字和按钮的颜色 使用Monet颜色而不是从专辑图取的糟糕的动态颜色来提高可读性 启用特效震动重映射 @@ -86,9 +86,9 @@ 小白条自动透明 将默认半透明小白条,并在触摸小白条时恢复正常 阻止应用设置自己的Pending过渡动画 - 将使用MIUI动画替换掉某些App设置的不优雅的过场动画(可能破坏应用本身的设计,慎用) + 将使用系统动画替换掉某些App设置的不优雅的过场动画(可能破坏应用本身的设计,慎用) 禁用壁纸自动压暗 - 回到MIUI桌面时隐藏小白条 + 回到桌面时隐藏小白条 小白条与手势栏 音乐通知 动起来吧!音量调节栏! @@ -105,4 +105,5 @@ 模糊缩放程度 小白条隐藏或出现时应用缩放效果 + 在小白条上应用模糊材质(需要开启高级材质) \ 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 160859f..f4e1598 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,4 +107,5 @@ CC by swipe]]> Blur Scale degree Scale home handle when dismiss or appeared + Apply Mi Blur Effect on Home Handle \ No newline at end of file diff --git a/app/src/main/res/xml/chen_preferences.xml b/app/src/main/res/xml/chen_preferences.xml index 625ca90..7b95f91 100644 --- a/app/src/main/res/xml/chen_preferences.xml +++ b/app/src/main/res/xml/chen_preferences.xml @@ -141,12 +141,18 @@ + +