Skip to content

Commit

Permalink
SystemUI: HomeHandle: add Mi Blur Effect
Browse files Browse the repository at this point in the history
Signed-off-by: Art_Chen <[email protected]>
  • Loading branch information
Art-Chen committed Nov 1, 2023
1 parent 53514ee commit 0fa05e2
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -130,23 +142,41 @@ 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()
}
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) {
Expand All @@ -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)
}
Expand All @@ -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,
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 8 additions & 7 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<string name="vibrator_map_summary">重映射普通震动为特效震动(线性马达震动)</string>
<string name="wallpaper_scale_title">壁纸缩放设置</string>
<string name="wallpaper_scale_summary">自定义壁纸缩放比例</string>
<string name="force_miui_refresh_custom">启用MIUI自定义高刷新率特性</string>
<string name="force_current_refresh_rate_title">禁用MIUI刷新率策略</string>
<string name="force_current_refresh_rate_off">刷新率将由MIUI动态控制</string>
<string name="force_miui_refresh_custom">启用自定义高刷新率特性</string>
<string name="force_current_refresh_rate_title">禁用刷新率策略</string>
<string name="force_current_refresh_rate_off">刷新率将由系统动态控制</string>
<string name="force_current_refresh_rate_on">刷新率将保持为您的设置</string>

<string name="m90Hz_game_apps">90Hz 游戏应用</string>
Expand All @@ -38,8 +38,8 @@
<string name="reboot">重启</string>
<string name="color_fade_anim_smoothly_title">更舒服的亮灭屏动画</string>
<string name="color_fade_anim_smoothly_summary">让Color Fade动画比MIUI原来的设置更慢一些 (俺的动画!!!!)</string>
<string name="music_notification_optimize_title">优化MIUI音乐通知</string>
<string name="music_notification_optimize_summary">修复MIUI异常的歌曲切换动画和App不规范导致的专辑图不同步问题</string>
<string name="music_notification_optimize_title">优化音乐通知</string>
<string name="music_notification_optimize_summary">修复异常的歌曲切换动画和App不规范导致的专辑图不同步问题</string>
<string name="music_notification_optimize_foreground_color_title">优化音乐通知的文字和按钮的颜色</string>
<string name="music_notification_optimize_foreground_color_summary">使用Monet颜色而不是从专辑图取的糟糕的动态颜色来提高可读性</string>
<string name="enable_vibrator_effect_remap_title">启用特效震动重映射</string>
Expand Down Expand Up @@ -86,9 +86,9 @@
<string name="chen_home_handle_auto_transparent_title">小白条自动透明</string>
<string name="chen_home_handle_auto_transparent_summary">将默认半透明小白条,并在触摸小白条时恢复正常</string>
<string name="do_not_override_pending_transition_title">阻止应用设置自己的Pending过渡动画</string>
<string name="do_not_override_pending_transition_summary">将使用MIUI动画替换掉某些App设置的不优雅的过场动画(可能破坏应用本身的设计,慎用)</string>
<string name="do_not_override_pending_transition_summary">将使用系统动画替换掉某些App设置的不优雅的过场动画(可能破坏应用本身的设计,慎用)</string>
<string name="disable_wallpaper_auto_darken_title">禁用壁纸自动压暗</string>
<string name="chen_home_handle_full_transparent_at_miuihome_title">回到MIUI桌面时隐藏小白条</string>
<string name="chen_home_handle_full_transparent_at_miuihome_title">回到桌面时隐藏小白条</string>
<string name="home_handle_header">小白条与手势栏</string>
<string name="music_notification_header">音乐通知</string>
<string name="use_chen_volume_animation_title">动起来吧!音量调节栏!</string>
Expand All @@ -105,4 +105,5 @@
<string name="force_disable_mi_blur_effect_summary"><![CDATA[(BUG!) 这是一个workaround。因为大部分版本不支持模糊混色下的Scale效果.\n这将会导致横切控制中心和通知中心时模糊背景和图标出现异常!正确方式是关闭高级材质开关(但是会丢失通知模糊效果)。]]></string>
<string name="blur_scale_val_title">模糊缩放程度</string>
<string name="chen_home_handle_scale_on_full_transparent_title">小白条隐藏或出现时应用缩放效果</string>
<string name="chen_home_handle_blur_effect_title">在小白条上应用模糊材质(需要开启高级材质)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@
<string name="force_disable_mi_blur_effect_summary"><![CDATA[(BUG!) This is a workaround because some version may not supported blur scale when using mi blur effect.\nIt will let blur background dismiss when switch the NC -> CC by swipe]]></string>
<string name="blur_scale_val_title">Blur Scale degree</string>
<string name="chen_home_handle_scale_on_full_transparent_title">Scale home handle when dismiss or appeared</string>
<string name="chen_home_handle_blur_effect_title">Apply Mi Blur Effect on Home Handle</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/chen_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,18 @@

<rikka.material.preference.MaterialSwitchPreference
app:key="chen_home_handle_full_transparent_at_miuihome"
app:dependency="chen_home_handle_anim"
app:title="@string/chen_home_handle_full_transparent_at_miuihome_title" />

<rikka.material.preference.MaterialSwitchPreference
app:key="home_handle_scale_on_full_transparent"
app:dependency="chen_home_handle_anim"
app:title="@string/chen_home_handle_scale_on_full_transparent_title" />

<rikka.material.preference.MaterialSwitchPreference
app:key="chen_home_handle_blur_effect"
app:dependency="chen_home_handle_anim"
app:title="@string/chen_home_handle_blur_effect_title" />
</PreferenceCategory>

<PreferenceCategory app:title="@string/music_notification_header">
Expand Down

0 comments on commit 0fa05e2

Please sign in to comment.