This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
81 deletions.
There are no files selected for viewing
135 changes: 54 additions & 81 deletions
135
app/src/main/kotlin/com/yuk/hyperOS_XXL/hooks/modules/miuihome/DockBlur.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,82 @@ | ||
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.view.animation.Animation | ||
import android.widget.FrameLayout | ||
import cn.fkj233.ui.activity.dp2px | ||
import com.github.kyuubiran.ezxhelper.EzXHelper | ||
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass | ||
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.getObjectField | ||
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.hookAfterMethod | ||
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.hookBeforeMethod | ||
import com.yuk.hyperOS_XXL.utils.KotlinXposedHelper.new | ||
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, 94f) | ||
val mDockMargin = dp2px(appContext, 10f) | ||
val mDockBottomMargin = dp2px(appContext, 14f) | ||
val workspaseClass = "com.miui.home.launcher.Workspace".findClass() | ||
val applicationClass = "com.miui.home.launcher.Application".findClass() | ||
|
||
// 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() | ||
} | ||
} | ||
// DockBlur WIP, ONLY FOR XIAOMI14 WITH HYPER OS | ||
"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) | ||
//loadClass("com.miui.home.launcher.hotseats.HotSeats").new(appContext, null).apply { | ||
// TODO | ||
//"onMeasure" | ||
mDockBlur = BlurView(appContext, 30) | ||
XposedHelpers.setAdditionalInstanceField(it.thisObject, "mDockBlur", mDockBlur) | ||
XposedHelpers.setAdditionalInstanceField(it.thisObject, "mDockBlurParent", mDockBlurParent) | ||
} | ||
} | ||
launcherClass.hookAfterMethod("setupViews") { | ||
val mScreenContent = it.thisObject.getObjectField("mScreenContent") as FrameLayout | ||
val mDockBlurParent = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlurParent") as FrameLayout | ||
val mDockBlur = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlur") as BlurView | ||
val mDockHeight = dp2px(mDockBlurParent.context, 94f) | ||
val mDockMargin = dp2px(mDockBlurParent.context, 10f) | ||
val mDockBottomMargin = dp2px(mDockBlurParent.context, 14f) | ||
mDockBlurParent.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mDockHeight).also { layoutParams -> | ||
layoutParams.gravity = Gravity.BOTTOM | ||
layoutParams.setMargins(mDockMargin, 0, mDockMargin, mDockBottomMargin) | ||
} | ||
mDockBlurParent.attributeSourceResourceMap | ||
mDockBlur.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT) | ||
mScreenContent.addView(mDockBlurParent, 0) | ||
mDockBlurParent.addView(mDockBlur, 0) | ||
} | ||
launcherClass.hookAfterMethod("showBottomAreaEditPanelIfNeed", View::class.java, Boolean::class.java) { | ||
val mDockBlurParent = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlurParent") as FrameLayout | ||
val mHotseatEditingEnter = it.thisObject.getObjectField("mHotseatEditingEnter") as Animation | ||
val mHotseatEditingExit = it.thisObject.getObjectField("mHotseatEditingExit") as Animation | ||
val z = it.args[1] as Boolean | ||
if (mDockBlurParent.visibility == 0 == z) { | ||
mDockBlurParent.startAnimation(if (z) mHotseatEditingExit else mHotseatEditingEnter) | ||
mDockBlurParent.visibility = if (z) View.INVISIBLE else View.VISIBLE | ||
if (z) { | ||
return@hookAfterMethod | ||
} | ||
mDockBlurParent.setAlpha(1.0f) | ||
} | ||
} | ||
|
||
launcherClass.hookAfterMethod("setScreenContentAlpha", Float::class.java) { | ||
val mDockBlurParent = XposedHelpers.getAdditionalInstanceField(it.thisObject, "mDockBlurParent") as FrameLayout | ||
mDockBlurParent.alpha = it.args[0] as Float | ||
} | ||
} | ||
|
||
} |