Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Add Support MiBlurUtilities
Browse files Browse the repository at this point in the history
* Also add WIP Dock Blur
  • Loading branch information
YuKongA committed Nov 6, 2023
1 parent 1fa47a2 commit de919af
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ dependencies {
compileOnly(de.robv.android.xposed.api)
implementation(com.github.kyuubiran.ezXHelper)
implementation(org.luckypray.dexkit)
implementation(org.lsposed.hiddenapibypass.hiddenapibypass)
implementation(projects.blockmiui)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class MiuiHomePage : BasePage() {
TextSummaryV(textId = R.string.miuihome_blur_when_open_folder, tipsId = R.string.miuihome_blur_when_open_folder_summary),
SwitchV("miuihome_blur_when_open_folder", false)
)
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.miuihome_add_dock_blur, tipsId = R.string.miuihome_add_dock_blur_summary),
SwitchV("miuihome_add_dock_blur", false)
)
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.miuihome_hide_allapps_category_all, tipsId = R.string.miuihome_hide_allapps_category_all_summary),
SwitchV("miuihome_hide_allapps_category_all", false)
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/kotlin/com/yuk/hyperOS_XXL/blur/BlurView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.yuk.hyperOS_XXL.blur

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import cn.fkj233.ui.activity.dp2px
import com.yuk.hyperOS_XXL.blur.MiBlurUtilities.mSupportedMiBlur
import com.yuk.hyperOS_XXL.utils.AppUtils.isDarkMode

@SuppressLint("ViewConstructor")
class BlurView(context: Context, private val radius: Int) : View(context) {

private fun setBlur() {
//MiBlurUtilities.resetBlurColor(this.parent as View)
MiBlurUtilities.setPassWindowBlurEnable(this.parent as View, true)
MiBlurUtilities.setViewBlur(this.parent as View, 1)
MiBlurUtilities.setBlurRoundRect(this.parent as View, dp2px(context, radius.toFloat()))
//MiBlurUtilities.setBlurColor(this.parent as View, if (isDarkMode(this.context)) 0x14ffffff else 0x14000000, 3)
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (mSupportedMiBlur) {
setBlur()
}
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
MiBlurUtilities.clearAllBlur(this.parent as View)
}
}
105 changes: 105 additions & 0 deletions app/src/main/kotlin/com/yuk/hyperOS_XXL/blur/MiBlurUtilities.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.yuk.hyperOS_XXL.blur

import android.graphics.Outline
import android.util.Log
import android.view.View
import android.view.ViewOutlineProvider
import com.yuk.hyperOS_XXL.utils.AppUtils.isDarkMode
import org.lsposed.hiddenapibypass.HiddenApiBypass

object MiBlurUtilities {
var mSupportedMiBlur: Boolean = true

fun setViewBackgroundBlur(view: View?, i: Int) {
HiddenApiBypass.invoke(View::class.java, view, "setMiBackgroundBlurMode", i)
}

fun setViewBlur(view: View, i: Int) {
HiddenApiBypass.invoke(View::class.java, view, "setMiViewBlurMode", i)
}

fun setBlurRadius(view: View, i: Int) {
if (i < 0 || i > 200) {
Log.e("MiBlurUtilities", "setMiBackgroundBlurRadius error radius is " + i + " " + view.javaClass.getName() + " hashcode " + view.hashCode())
return
}
HiddenApiBypass.invoke(View::class.java, view, "setMiBackgroundBlurRadius", i)
}

fun setPassWindowBlurEnable(view: View, z: Boolean) {
Log.d("Launcher.BlurUtilities", "setViewBlur: view $view")
HiddenApiBypass.invoke(View::class.java, view, "setPassWindowBlurEnabled", z)
}

fun disableMiBackgroundContainBelow(view: View, z: Boolean) {
HiddenApiBypass.invoke(View::class.java, view, "disableMiBackgroundContainBelow", z)
}

fun setBlurColor(view: View, i: Int, i2: Int) {
HiddenApiBypass.invoke(View::class.java, view, "addMiBackgroundBlendColor", i, i2)
}

fun resetBlurColor(view: View) {
HiddenApiBypass.invoke(View::class.java, view, "clearMiBackgroundBlendColor")
}

fun setBlurRoundRect(view: View, i: Int, i2: Int, i3: Int, i4: Int, i5: Int) {
view.setClipToOutline(false)
val outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(
i2, i3, i4, i5, i.toFloat()
)
}
}
view.outlineProvider = outlineProvider
}

fun setBlurRoundRect(view: View, i: Int) {
view.setClipToOutline(true)
val outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(
0, 0, view.width, view.height, i.toFloat()
)
}
}
view.outlineProvider = outlineProvider
}


fun clearAllBlur(view: View) {
resetBlurColor(view)
setViewBackgroundBlur(view, 0)
setViewBlur(view, 0)
setBlurRadius(view, 0)
setPassWindowBlurEnable(view, false)
}

fun setElementBlur(view: View, i: Int, i2: Int, i3: Int, i4: Int, i5: Int, i6: Int, i7: Int, i8: Int, i9: Int, i10: Int) {
resetBlurColor(view)
setViewBlur(view, i)
setBlurRoundRect(view, i2)
if (isDarkMode(view.context)) {
setBlurColor(view, i3, i4)
setBlurColor(view, i7, i8)
return
}
setBlurColor(view, i5, i6)
setBlurColor(view, i9, i10)
}

fun setContainerBlur(view: View, i: Int, z: Boolean, i2: Int, i3: Int, i4: Int, i5: Int, i6: Int) {
resetBlurColor(view)
setViewBackgroundBlur(view, i)
if (z) {
setPassWindowBlurEnable(view, true)
}
setBlurRadius(view, i2)
if (isDarkMode(view.context)) {
setBlurColor(view, i3, i4)
} else {
setBlurColor(view, i5, i6)
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/kotlin/com/yuk/hyperOS_XXL/hooks/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.yuk.hyperOS_XXL.hooks.modules.miuihome.AlwaysShowStatusBarClock
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.AnimDurationRatio
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.BlurWhenOpenFolder
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.CategoryFeatures
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.DockBlur
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.DoubleTapToSleep
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.MinusOneOverlapMode
import com.yuk.hyperOS_XXL.hooks.modules.miuihome.RecentViewRemoveCardAnim
Expand Down Expand Up @@ -127,6 +128,7 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
UseCompleteBlur,
MinusOneOverlapMode,
ShowRealMemory,
DockBlur
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.yuk.hyperOS_XXL.hooks.modules.miuihome

import android.animation.ValueAnimator
import android.app.Application
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import cn.fkj233.ui.activity.dp2px
import com.github.kyuubiran.ezxhelper.EzXHelper
import com.github.kyuubiran.ezxhelper.EzXHelper.appContext
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.yuk.hyperOS_XXL.blur.BlurView
import com.yuk.hyperOS_XXL.hooks.modules.BaseHook
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.callMethod
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.findClass
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.hookAfterMethod
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.hookBeforeMethod
import com.yuk.hyperOS_XXL.utils.XSharedPreferences.getBoolean
import de.robv.android.xposed.XposedHelpers

object DockBlur : BaseHook() {
override fun init() {

if (!getBoolean("miuihome_add_dock_blur", false)) return

var isShowEditPanel = false
val launcherClass = "com.miui.home.launcher.Launcher".findClass()
val folderInfo = "com.miui.home.launcher.FolderInfo".findClass()

Application::class.java.hookBeforeMethod("attach", Context::class.java) { hookParam ->
EzXHelper.initAppContext(hookParam.args[0] as Context)

val mDockHeight = dp2px(appContext, 93f)
val mDockMargin = dp2px(appContext, 10f)
val mDockBottomMargin = dp2px(appContext, 13f)

// DockBlur WIP
"com.miui.home.launcher.Launcher".findClass().declaredConstructors.createHooks {
after {
var mDockBlurParent = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlurParent")
var mDockBlur = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlur")
if (mDockBlurParent != null && mDockBlur != null) return@after
mDockBlurParent = FrameLayout(appContext)
mDockBlur = BlurView(appContext, 30)
XposedHelpers.setAdditionalInstanceField(it.thisObject, "mDockBlur", mDockBlur)
XposedHelpers.setAdditionalInstanceField(it.thisObject, "mDockBlurParent", mDockBlurParent)
}
launcherClass.hookAfterMethod("onCreate", Bundle::class.java) {
val mSearchBarContainer = it.thisObject.callMethod("getSearchBarContainer") as FrameLayout
val mSearchEdgeLayout = mSearchBarContainer.parent as FrameLayout
val mDockBlurParent = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlurParent") as FrameLayout
val mDockBlur = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlur") as BlurView
val lp = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mDockHeight)
lp.gravity = Gravity.BOTTOM
lp.setMargins(mDockMargin, 0, mDockMargin, mDockBottomMargin)
mDockBlurParent.layoutParams = lp
mDockBlur.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
mSearchEdgeLayout.addView(mDockBlurParent, 0)
mDockBlurParent.addView(mDockBlur, 0)
launcherClass.hookAfterMethod("showEditPanel", Boolean::class.java) { hookParam ->
isShowEditPanel = hookParam.args[0] as Boolean
if (isShowEditPanel) {
val valueAnimator = ValueAnimator.ofFloat(mDockBlurParent.alpha, 0f)
valueAnimator.addUpdateListener { animator ->
val value = animator.animatedValue as Float
mDockBlurParent.alpha = value
}
valueAnimator.duration = 150
valueAnimator.start()
} else {
val valueAnimator = ValueAnimator.ofFloat(mDockBlurParent.alpha, 1f)
valueAnimator.addUpdateListener { animator ->
val value = animator.animatedValue as Float
mDockBlurParent.alpha = value
}
valueAnimator.duration = 150
valueAnimator.start()
}
}
launcherClass.hookAfterMethod("openFolder", folderInfo, View::class.java) {
if (!isShowEditPanel) {
val valueAnimator = ValueAnimator.ofFloat(mDockBlurParent.alpha, 0f)
valueAnimator.addUpdateListener { animator ->
val value = animator.animatedValue as Float
mDockBlurParent.alpha = value
}
valueAnimator.duration = 150
valueAnimator.start()
}
}
launcherClass.hookAfterMethod("closeFolder", Boolean::class.java) {
if (!isShowEditPanel) {
val valueAnimator = ValueAnimator.ofFloat(mDockBlurParent.alpha, 1f)
valueAnimator.addUpdateListener { animator ->
val value = animator.animatedValue as Float
mDockBlurParent.alpha = value
}
valueAnimator.duration = 150
valueAnimator.start()
}
}
}
}
}

}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
<string name="miuihome_minus_one_overlap_mode_summary">配合「背景模糊」使用,该功能作用域为系统桌面</string>
<string name="miuihome_show_real_memory">显示真实内存使用情况</string>
<string name="miuihome_show_real_memory_summary">在最近任务中显示真实内存使用情况,需在桌面设置中开启“显示内存信息”</string>
<string name="miuihome_add_dock_blur">添加 Dock 模糊</string>
<string name="miuihome_add_dock_blur_summary">未完成,建议关闭负一屏使用</string>

<string name="thememanager">主题壁纸</string>
<string name="thememanager_remove_ads">去广告</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
<string name="miuihome_minus_one_overlap_mode_summary">Used in conjunction with minus one screen blur, and the system launcher need to be checked</string>
<string name="miuihome_show_real_memory">Show Real Memory Info</string>
<string name="miuihome_show_real_memory_summary">Hacking fake MIUI memory display, need to turn on "Show memory status" in Home screen Settings</string>
<string name="miuihome_add_dock_blur">Add Dock Blur</string>
<string name="miuihome_add_dock_blur_summary">WIP</string>

<string name="thememanager">Theme Manager</string>
<string name="thememanager_remove_ads">Remove Ads</string>
Expand Down
5 changes: 4 additions & 1 deletion gradle/sweet-dependency/sweet-dependency-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ libraries:
version: 2.0.8
org.luckypray:
dexkit:
version: 2.0.0-rc7
version: 2.0.0-rc7
org.lsposed.hiddenapibypass:
hiddenapibypass:
version: 4.3

0 comments on commit de919af

Please sign in to comment.