Skip to content

Commit

Permalink
MiuiHome: calculate shadow color by text color
Browse files Browse the repository at this point in the history
Signed-off-by: Art_Chen <[email protected]>
  • Loading branch information
Art-Chen committed Jul 29, 2024
1 parent 8a7a295 commit 225b135
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package moe.chenxy.miuiextra.hooker.entity

import android.graphics.Color
import android.util.Log
import android.view.View
import android.widget.TextView
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.hook.factory.method
import com.highcapable.yukihookapi.hook.type.android.ContextClass
import com.highcapable.yukihookapi.hook.type.android.ViewClass
import com.highcapable.yukihookapi.hook.type.java.FloatType
import com.highcapable.yukihookapi.hook.type.java.IntType
Expand All @@ -15,14 +12,15 @@ 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.TitleShadowHooker
import moe.chenxy.miuiextra.hooker.entity.home.ViewBlurHooker
import moe.chenxy.miuiextra.hooker.entity.home.WallpaperZoomOptimizeLegacy
import moe.chenxy.miuiextra.hooker.entity.home.WallpaperZoomOptimizeOS1NewArch
import moe.chenxy.miuiextra.utils.ChenUtils


object MiuiHomeHook : YukiBaseHooker() {
private val mainPrefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "chen_main_settings")
val mainPrefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "chen_main_settings")
val zoomPrefs = XSharedPreferences(BuildConfig.APPLICATION_ID, "chen_wallpaper_zoom_settings")

enum class AnimType {
Expand Down Expand Up @@ -55,6 +53,7 @@ object MiuiHomeHook : YukiBaseHooker() {
}

loadHooker(ViewBlurHooker)
loadHooker(TitleShadowHooker)


"com.miui.home.launcher.compat.UserPresentAnimationCompatV12Phone".toClass().apply {
Expand Down Expand Up @@ -95,29 +94,5 @@ object MiuiHomeHook : YukiBaseHooker() {
}
}
}

"com.miui.home.launcher.DeviceConfig".toClass().apply {
method {
name = "checkDarkenWallpaperSupport"
param(ContextClass)
}.hook {
replaceTo(!mainPrefs.getBoolean("disable_wallpaper_auto_darken", false))
}
}

"com.miui.home.launcher.common.Utilities".toClass().apply {
method {
name = "setTitleShadow"
paramCount = 3
}.hook {
after {
val textView = this.args[1] as TextView
// val color = this.args[2] as Int
textView.setShadowLayer(30.0f, 0f, 0f, Color.rgb(10,10,10))
}
}
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package moe.chenxy.miuiextra.hooker.entity.home

import android.graphics.Color
import android.widget.TextView
import androidx.core.graphics.blue
import androidx.core.graphics.green
import androidx.core.graphics.red
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
import com.highcapable.yukihookapi.hook.factory.method
import com.highcapable.yukihookapi.hook.type.android.ContextClass
import moe.chenxy.miuiextra.hooker.entity.MiuiHomeHook.mainPrefs
import kotlin.math.abs

object TitleShadowHooker : YukiBaseHooker() {
override fun onHook() {
val enableShadow = mainPrefs.getBoolean("disable_wallpaper_auto_darken", false)
"com.miui.home.launcher.DeviceConfig".toClass().apply {
method {
name = "checkDarkenWallpaperSupport"
param(ContextClass)
}.hook {
replaceTo(!enableShadow)
}
}

"com.miui.home.launcher.common.Utilities".toClass().apply {
method {
name = "setTitleShadow"
paramCount = 3
}.hook {
replaceUnit {
if (!enableShadow) return@replaceUnit

val textView = this.args[1] as TextView
// val color = this.args[2] as Int
val textColor = textView.currentTextColor
val reversedColor = Color.rgb(abs(245 - textColor.red),abs(245 - textColor.green),abs(245 - textColor.blue))
textView.setShadowLayer(30.0f, 0f, 0f, reversedColor)
}
}
}

}
}

0 comments on commit 225b135

Please sign in to comment.