Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20c3d155 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Controls UI - Support custom colors/icons" into rvc-dev am: 3d850958

Change-Id: I2d0d385420d12cc2222f380ef8ae248e93f22c79
parents 205ec366 3d850958
Loading
Loading
Loading
Loading
+22 −8
Original line number Original line Diff line number Diff line
@@ -186,22 +186,36 @@ class ControlViewHolder(
        val fg = context.resources.getColorStateList(ri.foreground, context.theme)
        val fg = context.resources.getColorStateList(ri.foreground, context.theme)
        val bg = context.resources.getColor(R.color.control_default_background, context.theme)
        val bg = context.resources.getColor(R.color.control_default_background, context.theme)
        val dimAlpha = if (dimmed) dimmedAlpha else 1f
        val dimAlpha = if (dimmed) dimmedAlpha else 1f
        var (clip, newAlpha) = if (enabled) {
        var (newClipColor, newAlpha) = if (enabled) {
            listOf(ri.enabledBackground, ALPHA_ENABLED)
            // allow color overrides for the enabled state only
            val color = cws.control?.getCustomColor()?.let {
                val state = intArrayOf(android.R.attr.state_enabled)
                it.getColorForState(state, it.getDefaultColor())
            } ?: context.resources.getColor(ri.enabledBackground, context.theme)
            listOf(color, ALPHA_ENABLED)
        } else {
        } else {
            listOf(R.color.control_default_background, ALPHA_DISABLED)
            listOf(
                context.resources.getColor(R.color.control_default_background, context.theme),
                ALPHA_DISABLED
            )
        }
        }


        status.setTextColor(fg)
        status.setTextColor(fg)

        cws.control?.getCustomIcon()?.let {
            // do not tint custom icons, assume the intended icon color is correct
            icon.imageTintList = null
            icon.setImageIcon(it)
        } ?: run {
            icon.setImageDrawable(ri.icon)
            icon.setImageDrawable(ri.icon)


            // do not color app icons
            // do not color app icons
            if (deviceType != DeviceTypes.TYPE_ROUTINE) {
            if (deviceType != DeviceTypes.TYPE_ROUTINE) {
                icon.imageTintList = fg
                icon.imageTintList = fg
            }
            }
        }


        (clipLayer.getDrawable() as GradientDrawable).apply {
        (clipLayer.getDrawable() as GradientDrawable).apply {
            val newClipColor = context.resources.getColor(clip, context.theme)
            val newBaseColor = if (behavior is ToggleRangeBehavior) {
            val newBaseColor = if (behavior is ToggleRangeBehavior) {
                ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity)
                ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity)
            } else {
            } else {