From a103a946e4662aa31c3bb8914835e903e4161996 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Fri, 13 Mar 2020 12:10:35 -0400 Subject: [PATCH] Controls UI - Fix colors Colors and state were not properly being applied. Set the bg color directly, instead of using the unneccsary ColorStateList. Bug: 151421548 Test: restart device, check colors Change-Id: Ic32b6865bcaf499a2ae3540fd1c296c7aad461aa --- .../SystemUI/res/color/control_background.xml | 7 ------- .../SystemUI/res/color/light_background.xml | 7 ------- .../res/color/thermo_cool_background.xml | 7 ------- .../res/color/thermo_heat_background.xml | 7 ------- packages/SystemUI/res/values/colors.xml | 4 ++++ .../systemui/controls/ui/ControlViewHolder.kt | 17 ++++++++++++----- .../android/systemui/controls/ui/RenderInfo.kt | 18 ++++++++++++------ 7 files changed, 28 insertions(+), 39 deletions(-) delete mode 100644 packages/SystemUI/res/color/control_background.xml delete mode 100644 packages/SystemUI/res/color/light_background.xml delete mode 100644 packages/SystemUI/res/color/thermo_cool_background.xml delete mode 100644 packages/SystemUI/res/color/thermo_heat_background.xml diff --git a/packages/SystemUI/res/color/control_background.xml b/packages/SystemUI/res/color/control_background.xml deleted file mode 100644 index 977310cfae01a..0000000000000 --- a/packages/SystemUI/res/color/control_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/packages/SystemUI/res/color/light_background.xml b/packages/SystemUI/res/color/light_background.xml deleted file mode 100644 index 12994646a346d..0000000000000 --- a/packages/SystemUI/res/color/light_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/packages/SystemUI/res/color/thermo_cool_background.xml b/packages/SystemUI/res/color/thermo_cool_background.xml deleted file mode 100644 index 977310cfae01a..0000000000000 --- a/packages/SystemUI/res/color/thermo_cool_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/packages/SystemUI/res/color/thermo_heat_background.xml b/packages/SystemUI/res/color/thermo_heat_background.xml deleted file mode 100644 index 2709ebe4dcfd8..0000000000000 --- a/packages/SystemUI/res/color/thermo_heat_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 80c1ac8e3496b..56e2b061ebc2a 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -225,4 +225,8 @@ @color/GM2_grey_900 @*android:color/background_floating_material_dark @*android:color/foreground_material_dark + @color/GM2_yellow_200 + @color/GM2_red_200 + @color/GM2_blue_200 + @color/GM2_blue_200 diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt index 23dc4c65d2b10..b4392067d9532 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt @@ -17,8 +17,8 @@ package com.android.systemui.controls.ui import android.content.Context -import android.graphics.BlendMode import android.graphics.drawable.ClipDrawable +import android.graphics.drawable.GradientDrawable import android.graphics.drawable.LayerDrawable import android.service.controls.Control import android.service.controls.actions.ControlAction @@ -39,6 +39,8 @@ import com.android.systemui.R import kotlin.reflect.KClass private const val UPDATE_DELAY_IN_MILLIS = 3000L +private const val ALPHA_ENABLED = (255.0 * 0.2).toInt() +private const val ALPHA_DISABLED = 255 class ControlViewHolder( val layout: ViewGroup, @@ -144,16 +146,21 @@ class ControlViewHolder( val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset) val fg = context.getResources().getColorStateList(ri.foreground, context.getTheme()) - val bg = context.getResources().getColorStateList(ri.background, context.getTheme()) + val (bg, alpha) = if (enabled) { + Pair(ri.enabledBackground, ALPHA_ENABLED) + } else { + Pair(R.color.control_default_background, ALPHA_DISABLED) + } + status.setTextColor(fg) statusExtra.setTextColor(fg) icon.setImageDrawable(ri.icon) icon.setImageTintList(fg) - clipLayer.getDrawable().apply { - setTintBlendMode(BlendMode.HUE) - setTintList(bg) + (clipLayer.getDrawable() as GradientDrawable).apply { + setColor(context.getResources().getColor(bg, context.getTheme())) + setAlpha(alpha) } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt index 56267beb1b71f..27e46497b20aa 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt @@ -16,6 +16,7 @@ package com.android.systemui.controls.ui +import android.annotation.ColorRes import android.annotation.MainThread import android.content.ComponentName import android.content.Context @@ -37,8 +38,11 @@ data class IconState(val disabledResourceId: Int, val enabledResourceId: Int) { } } -data class RenderInfo(val icon: Drawable, val foreground: Int, val background: Int) { - +data class RenderInfo( + val icon: Drawable, + val foreground: Int, + @ColorRes val enabledBackground: Int +) { companion object { const val APP_ICON_ID = -1 private val iconMap = SparseArray() @@ -72,6 +76,7 @@ data class RenderInfo(val icon: Drawable, val foreground: Int, val background: I icon = iconMap.get(resourceId) if (icon == null) { icon = context.resources.getDrawable(resourceId, null) + icon.mutate() iconMap.put(resourceId, icon) } } @@ -94,12 +99,13 @@ private const val THERMOSTAT_RANGE = DeviceTypes.TYPE_THERMOSTAT * BUCKET_SIZE private val deviceColorMap = mapOf>( (THERMOSTAT_RANGE + TemperatureControlTemplate.MODE_HEAT) to - Pair(R.color.thermo_heat_foreground, R.color.thermo_heat_background), + Pair(R.color.thermo_heat_foreground, R.color.control_enabled_thermo_heat_background), (THERMOSTAT_RANGE + TemperatureControlTemplate.MODE_COOL) to - Pair(R.color.thermo_cool_foreground, R.color.thermo_cool_background), - DeviceTypes.TYPE_LIGHT to Pair(R.color.light_foreground, R.color.light_background) + Pair(R.color.thermo_cool_foreground, R.color.control_enabled_thermo_cool_background), + DeviceTypes.TYPE_LIGHT + to Pair(R.color.light_foreground, R.color.control_enabled_light_background) ).withDefault { - Pair(R.color.control_foreground, R.color.control_background) + Pair(R.color.control_foreground, R.color.control_enabled_default_background) } private val deviceIconMap = mapOf(