Skip to content

Commit

Permalink
fix: CCGrid for HyperOS cannot be updated when the screen is switched…
Browse files Browse the repository at this point in the history
… between landscape and portrait orientation
  • Loading branch information
Sevtinge committed Dec 5, 2024
1 parent 3c1f681 commit b5314c3
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,47 @@ object CCGridForHyperOS {

@JvmStatic
fun initCCGridForHyperOS(classLoader: ClassLoader?) {
XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader, "setCornerRadius", Float::class.javaPrimitiveType, object : MethodHook() {
override fun before(param: MethodHookParam) {
param.args[0] = radius
}
}
)

var warningD: Drawable? = null
var enabledD: Drawable? = null
var restrictedD: Drawable? = null
var disabledD: Drawable? = null
var unavailableD: Drawable? = null
var updateTemp1 = false
var updateTemp2 = false

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader, "updateIcon", "com.android.systemui.plugins.qs.QSTile\$State", Boolean::class.javaPrimitiveType, Boolean::class.javaPrimitiveType, object : MethodHook() {
override fun before(param: MethodHookParam) {
val pluginContext: Context =
XposedHelpers.getObjectField(param?.thisObject, "pluginContext") as Context;
if (warningD == null) {
val param1 = param.args[1] as Boolean
val param2 = param.args[2] as Boolean
val update = (param1 && param2 && (!updateTemp1 || !updateTemp2))
if (update) {
updateTemp1 = param1
updateTemp2 = param2
}

val pluginContext: Context = XposedHelpers.getObjectField(param.thisObject, "pluginContext") as Context

if (warningD == null || update) {
val warning: Int = pluginContext.resources.getIdentifier("qs_background_warning", "drawable", "miui.systemui.plugin")
warningD = pluginContext.theme.getDrawable(warning);
}
if (enabledD == null) {
if (enabledD == null || update) {
val enabled: Int = pluginContext.resources.getIdentifier("qs_background_enabled", "drawable", "miui.systemui.plugin")
enabledD = pluginContext.theme.getDrawable(enabled);
}
if (restrictedD == null) {
if (restrictedD == null || update) {
val restricted: Int = pluginContext.resources.getIdentifier("qs_background_restricted", "drawable", "miui.systemui.plugin")
restrictedD = pluginContext.theme.getDrawable(restricted);
}
if (disabledD == null) {
if (disabledD == null || update) {
val disabled: Int = pluginContext.resources.getIdentifier("qs_background_disabled", "drawable", "miui.systemui.plugin")
disabledD = pluginContext.theme.getDrawable(disabled);
}
if (unavailableD == null) {
if (unavailableD == null || update) {
val unavailable: Int = pluginContext.resources.getIdentifier("qs_background_unavailable", "drawable", "miui.systemui.plugin")
unavailableD = pluginContext.theme.getDrawable(unavailable);
}

if (warningD is GradientDrawable) {
(warningD as GradientDrawable).cornerRadius = radius
}
Expand Down

0 comments on commit b5314c3

Please sign in to comment.