Skip to content

Commit

Permalink
OP QS Header: Add support for custom QS tiles and text colors
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <[email protected]>
  • Loading branch information
Mahmud0808 committed Sep 7, 2024
1 parent cab4a6c commit b064cd7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ import com.drdisagree.iconify.common.Preferences.OP_QS_HEADER_EXPANSION_Y
import com.drdisagree.iconify.common.Preferences.OP_QS_HEADER_SWITCH
import com.drdisagree.iconify.common.Preferences.OP_QS_HEADER_TOP_MARGIN
import com.drdisagree.iconify.common.Preferences.OP_QS_HEADER_VIBRATE
import com.drdisagree.iconify.common.Preferences.QS_TEXT_ALWAYS_WHITE
import com.drdisagree.iconify.common.Preferences.QS_TEXT_FOLLOW_ACCENT
import com.drdisagree.iconify.utils.color.monet.quantize.QuantizerCelebi
import com.drdisagree.iconify.utils.color.monet.score.Score
import com.drdisagree.iconify.xposed.ModPack
import com.drdisagree.iconify.xposed.modules.utils.ActivityLauncherUtils
import com.drdisagree.iconify.xposed.modules.utils.Helpers.findClassInArray
import com.drdisagree.iconify.xposed.modules.utils.Helpers.isMethodAvailable
import com.drdisagree.iconify.xposed.modules.utils.Helpers.isQsTileOverlayEnabled
import com.drdisagree.iconify.xposed.modules.utils.SettingsLibUtils.Companion.getColorAttr
import com.drdisagree.iconify.xposed.modules.utils.TouchAnimator
import com.drdisagree.iconify.xposed.modules.utils.VibrationUtils
Expand Down Expand Up @@ -104,6 +107,8 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {
private var mediaBlurLevel = 10f
private var topMarginValue = 0
private var expansionAmount = 0
private var qsTextAlwaysWhite = false
private var qsTextFollowAccent = false

private lateinit var mActivityLauncherUtils: ActivityLauncherUtils

Expand Down Expand Up @@ -170,6 +175,8 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {
mediaBlurLevel = getSliderInt(OP_QS_HEADER_BLUR_LEVEL, 10).toFloat()
topMarginValue = getSliderInt(OP_QS_HEADER_TOP_MARGIN, 0)
expansionAmount = getSliderInt(OP_QS_HEADER_EXPANSION_Y, 0)
qsTextAlwaysWhite = getBoolean(QS_TEXT_ALWAYS_WHITE, false)
qsTextFollowAccent = getBoolean(QS_TEXT_FOLLOW_ACCENT, false)
}

if (key.isNotEmpty() &&
Expand Down Expand Up @@ -198,6 +205,10 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {
"$SYSTEMUI_PACKAGE.qs.tileimpl.QSTileViewImpl",
loadPackageParam.classLoader
)
val tileLayoutClass = findClass(
"$SYSTEMUI_PACKAGE.qs.TileLayout",
loadPackageParam.classLoader
)
val qsPanelControllerBaseClass = findClassIfExists(
"$SYSTEMUI_PACKAGE.qs.QSPanelControllerBase",
loadPackageParam.classLoader
Expand Down Expand Up @@ -299,6 +310,17 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {
}
})

hookAllConstructors(tileLayoutClass, object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
if (!showOpQsHeaderView) return

initResources()
updateInternetTileColors()
updateBluetoothTileColors()
updateMediaPlayer(force = true)
}
})

// Update colors when device theme changes
hookAllMethods(shadeHeaderControllerClass, "onInit", object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
Expand All @@ -311,13 +333,12 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {

val updateColors = object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
if (qsTileViewImplInstance != null) {
initResources()
if (!showOpQsHeaderView || qsTileViewImplInstance == null) return

updateInternetTileColors()
updateBluetoothTileColors()
updateMediaPlayer(force = true)
}
initResources()
updateInternetTileColors()
updateBluetoothTileColors()
updateMediaPlayer(force = true)
}
}

Expand Down Expand Up @@ -1253,12 +1274,22 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {

val mMediaPlayerBackground = mQsOpHeaderView!!.mediaPlayerBackground
val defaultBackground = opMediaBackgroundDrawable.constantState?.newDrawable()?.mutate()
?.apply {
if (isQsTileOverlayEnabled) {
setTint(Color.TRANSPARENT)
} else {
colorInactive?.let { setTint(it) }
}
}

mMediaPlayerBackground.apply {
if (drawable == opMediaDefaultBackground) {
setImageDrawable(defaultBackground)
scaleType = ImageView.ScaleType.CENTER_CROP
clipToOutline = true

mQsOpHeaderView!!.resetMediaAppIconColor(backgroundColor = colorAccent)
colorLabelInactive?.let { mQsOpHeaderView!!.setMediaPlayerItemsColor(it) }
}
}

Expand Down Expand Up @@ -1673,25 +1704,6 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {
} catch (ignored: PackageManager.NameNotFoundException) {
}

qsTileViewImplInstance?.let { thisObject ->
colorActive = getObjectField(
thisObject,
"colorActive"
) as Int
colorInactive = getObjectField(
thisObject,
"colorInactive"
) as Int
colorLabelActive = getObjectField(
thisObject,
"colorLabelActive"
) as Int
colorLabelInactive = getObjectField(
thisObject,
"colorLabelInactive"
) as Int
}

mContext.apply {
colorAccent = getColorAttr(
this,
Expand Down Expand Up @@ -1733,11 +1745,36 @@ class OpQsHeader(context: Context?) : ModPack(context!!) {
)
}

qsTileViewImplInstance?.let { thisObject ->
val qsTileOverlayEnabled = isQsTileOverlayEnabled

colorActive = if (qsTileOverlayEnabled) Color.WHITE
else getObjectField(
thisObject,
"colorActive"
) as Int
colorInactive = if (qsTileOverlayEnabled) Color.TRANSPARENT
else getObjectField(
thisObject,
"colorInactive"
) as Int
colorLabelActive = if (qsTextAlwaysWhite) Color.WHITE
else if (qsTextFollowAccent) colorAccent
else getObjectField(
thisObject,
"colorLabelActive"
) as Int
colorLabelInactive = getObjectField(
thisObject,
"colorLabelInactive"
) as Int
}

opMediaBackgroundDrawable = if (colorInactive != null && colorInactive != 0) {
GradientDrawable().apply {
setColor(colorInactive!!)
shape = GradientDrawable.RECTANGLE
cornerRadius = qsTileCornerRadius
colors = intArrayOf(colorInactive!!, colorInactive!!)
}
} else {
ContextCompat.getDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ object Helpers {
}
}

val isQsTileOverlayEnabled: Boolean
get() = Shell.cmd("[[ $(cmd overlay list | grep -oE '\\[x\\] IconifyComponentQSS[N|P][0-9]+.overlay') ]] && echo 1 || echo 0")
.exec().out[0] == "1"

val isPixelVariant: Boolean
get() = Shell.cmd("[[ $(cmd overlay list | grep -oE '\\[x\\] IconifyComponentQSSP[0-9]+.overlay') ]] && echo 1 || echo 0")
.exec().out[0] == "1"
Expand Down

0 comments on commit b064cd7

Please sign in to comment.