Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.controls.ui |
| 18 | |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 19 | import android.animation.Animator |
| 20 | import android.animation.AnimatorListenerAdapter |
| 21 | import android.animation.ValueAnimator |
Matt Pietal | 94316e9 | 2020-04-22 10:58:32 -0400 | [diff] [blame] | 22 | import android.app.Dialog |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 23 | import android.content.Context |
| 24 | import android.graphics.drawable.ClipDrawable |
Matt Pietal | a103a94 | 2020-03-13 12:10:35 -0400 | [diff] [blame] | 25 | import android.graphics.drawable.GradientDrawable |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 26 | import android.graphics.drawable.LayerDrawable |
| 27 | import android.service.controls.Control |
Matt Pietal | f8cc0fa | 2020-03-26 08:48:50 -0400 | [diff] [blame] | 28 | import android.service.controls.DeviceTypes |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 29 | import android.service.controls.actions.ControlAction |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 30 | import android.service.controls.templates.ControlTemplate |
Matt Pietal | 53a8bbd | 2020-03-05 16:10:34 -0500 | [diff] [blame] | 31 | import android.service.controls.templates.StatelessTemplate |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 32 | import android.service.controls.templates.TemperatureControlTemplate |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 33 | import android.service.controls.templates.ToggleRangeTemplate |
| 34 | import android.service.controls.templates.ToggleTemplate |
Lucas Dupin | d60b332 | 2020-04-15 18:06:47 -0700 | [diff] [blame] | 35 | import android.util.MathUtils |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 36 | import android.view.View |
| 37 | import android.view.ViewGroup |
| 38 | import android.widget.ImageView |
| 39 | import android.widget.TextView |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 40 | import com.android.internal.graphics.ColorUtils |
| 41 | import com.android.systemui.Interpolators |
| 42 | import com.android.systemui.R |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 43 | import com.android.systemui.controls.controller.ControlsController |
Matt Pietal | 1aac43b | 2020-02-04 15:43:31 -0500 | [diff] [blame] | 44 | import com.android.systemui.util.concurrency.DelayableExecutor |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 45 | import kotlin.reflect.KClass |
| 46 | |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 47 | /** |
| 48 | * Wraps the widgets that make up the UI representation of a {@link Control}. Updates to the view |
| 49 | * are signaled via calls to {@link #bindData}. Similar to the ViewHolder concept used in |
| 50 | * RecyclerViews. |
| 51 | */ |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 52 | class ControlViewHolder( |
| 53 | val layout: ViewGroup, |
Matt Pietal | 1aac43b | 2020-02-04 15:43:31 -0500 | [diff] [blame] | 54 | val controlsController: ControlsController, |
Matt Pietal | 5bdfba4 | 2020-02-14 09:14:43 -0500 | [diff] [blame] | 55 | val uiExecutor: DelayableExecutor, |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 56 | val bgExecutor: DelayableExecutor, |
| 57 | val controlActionCoordinator: ControlActionCoordinator |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 58 | ) { |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 59 | |
| 60 | companion object { |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 61 | const val STATE_ANIMATION_DURATION = 700L |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 62 | private const val UPDATE_DELAY_IN_MILLIS = 3000L |
Matt Pietal | d8ca2c0 | 2020-04-24 19:20:48 -0400 | [diff] [blame] | 63 | private const val ALPHA_ENABLED = 255 |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 64 | private const val ALPHA_DISABLED = 0 |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 65 | private val FORCE_PANEL_DEVICES = setOf( |
| 66 | DeviceTypes.TYPE_THERMOSTAT, |
| 67 | DeviceTypes.TYPE_CAMERA |
| 68 | ) |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 69 | |
| 70 | const val MIN_LEVEL = 0 |
| 71 | const val MAX_LEVEL = 10000 |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 74 | private val toggleBackgroundIntensity: Float = layout.context.resources |
| 75 | .getFraction(R.fraction.controls_toggle_bg_intensity, 1, 1) |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 76 | private var stateAnimator: ValueAnimator? = null |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 77 | private val baseLayer: GradientDrawable |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 78 | val icon: ImageView = layout.requireViewById(R.id.icon) |
| 79 | val status: TextView = layout.requireViewById(R.id.status) |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 80 | val title: TextView = layout.requireViewById(R.id.title) |
| 81 | val subtitle: TextView = layout.requireViewById(R.id.subtitle) |
| 82 | val context: Context = layout.getContext() |
| 83 | val clipLayer: ClipDrawable |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 84 | lateinit var cws: ControlWithState |
Matt Pietal | 1aac43b | 2020-02-04 15:43:31 -0500 | [diff] [blame] | 85 | var cancelUpdate: Runnable? = null |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 86 | var behavior: Behavior? = null |
Matt Pietal | b7da66c | 2020-03-06 10:49:31 -0500 | [diff] [blame] | 87 | var lastAction: ControlAction? = null |
Matt Pietal | 94316e9 | 2020-04-22 10:58:32 -0400 | [diff] [blame] | 88 | private var lastChallengeDialog: Dialog? = null |
| 89 | |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 90 | val deviceType: Int |
| 91 | get() = cws.control?.let { it.getDeviceType() } ?: cws.ci.deviceType |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 92 | |
| 93 | init { |
| 94 | val ld = layout.getBackground() as LayerDrawable |
| 95 | ld.mutate() |
| 96 | clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) as ClipDrawable |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 97 | clipLayer.alpha = ALPHA_DISABLED |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 98 | baseLayer = ld.findDrawableByLayerId(R.id.background) as GradientDrawable |
Matt Pietal | 5f478c7 | 2020-04-01 15:53:54 -0400 | [diff] [blame] | 99 | // needed for marquee to start |
| 100 | status.setSelected(true) |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | fun bindData(cws: ControlWithState) { |
| 104 | this.cws = cws |
| 105 | |
Matt Pietal | 1aac43b | 2020-02-04 15:43:31 -0500 | [diff] [blame] | 106 | cancelUpdate?.run() |
| 107 | |
Matt Pietal | 31ec9f2 | 2020-03-12 09:02:17 -0400 | [diff] [blame] | 108 | val (controlStatus, template) = cws.control?.let { |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 109 | title.setText(it.getTitle()) |
| 110 | subtitle.setText(it.getSubtitle()) |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 111 | Pair(it.status, it.controlTemplate) |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 112 | } ?: run { |
| 113 | title.setText(cws.ci.controlTitle) |
Matt Pietal | 8587826 | 2020-03-18 15:34:46 -0400 | [diff] [blame] | 114 | subtitle.setText(cws.ci.controlSubtitle) |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 115 | Pair(Control.STATUS_UNKNOWN, ControlTemplate.NO_TEMPLATE) |
| 116 | } |
| 117 | |
Matt Pietal | 307b1ef | 2020-02-10 07:27:01 -0500 | [diff] [blame] | 118 | cws.control?.let { |
Matt Pietal | 31ec9f2 | 2020-03-12 09:02:17 -0400 | [diff] [blame] | 119 | layout.setClickable(true) |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 120 | layout.setOnLongClickListener(View.OnLongClickListener() { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 121 | controlActionCoordinator.longPress(this@ControlViewHolder) |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 122 | true |
| 123 | }) |
| 124 | } |
| 125 | |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 126 | val clazz = findBehavior(controlStatus, template, deviceType) |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 127 | if (behavior == null || behavior!!::class != clazz) { |
| 128 | // Behavior changes can signal a change in template from the app or |
| 129 | // first time setup |
| 130 | behavior = clazz.java.newInstance() |
| 131 | behavior?.initialize(this) |
Matt Pietal | 31ec9f2 | 2020-03-12 09:02:17 -0400 | [diff] [blame] | 132 | |
| 133 | // let behaviors define their own, if necessary, and clear any existing ones |
| 134 | layout.setAccessibilityDelegate(null) |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 135 | } |
Matt Pietal | 31ec9f2 | 2020-03-12 09:02:17 -0400 | [diff] [blame] | 136 | |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 137 | behavior?.bind(cws) |
Matt Pietal | 31ec9f2 | 2020-03-12 09:02:17 -0400 | [diff] [blame] | 138 | |
Matt Pietal | 5f478c7 | 2020-04-01 15:53:54 -0400 | [diff] [blame] | 139 | layout.setContentDescription("${title.text} ${subtitle.text} ${status.text}") |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Matt Pietal | 1aac43b | 2020-02-04 15:43:31 -0500 | [diff] [blame] | 142 | fun actionResponse(@ControlAction.ResponseResult response: Int) { |
Matt Pietal | 94316e9 | 2020-04-22 10:58:32 -0400 | [diff] [blame] | 143 | // OK responses signal normal behavior, and the app will provide control updates |
| 144 | val failedAttempt = lastChallengeDialog != null |
| 145 | when (response) { |
| 146 | ControlAction.RESPONSE_OK -> |
| 147 | lastChallengeDialog = null |
| 148 | ControlAction.RESPONSE_UNKNOWN -> { |
| 149 | lastChallengeDialog = null |
| 150 | setTransientStatus(context.resources.getString(R.string.controls_error_failed)) |
| 151 | } |
| 152 | ControlAction.RESPONSE_FAIL -> { |
| 153 | lastChallengeDialog = null |
| 154 | setTransientStatus(context.resources.getString(R.string.controls_error_failed)) |
| 155 | } |
| 156 | ControlAction.RESPONSE_CHALLENGE_PIN -> { |
| 157 | lastChallengeDialog = ChallengeDialogs.createPinDialog(this, false, failedAttempt) |
| 158 | lastChallengeDialog?.show() |
| 159 | } |
| 160 | ControlAction.RESPONSE_CHALLENGE_PASSPHRASE -> { |
| 161 | lastChallengeDialog = ChallengeDialogs.createPinDialog(this, true, failedAttempt) |
| 162 | lastChallengeDialog?.show() |
| 163 | } |
| 164 | ControlAction.RESPONSE_CHALLENGE_ACK -> { |
| 165 | lastChallengeDialog = ChallengeDialogs.createConfirmationDialog(this) |
| 166 | lastChallengeDialog?.show() |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | fun dismiss() { |
| 172 | lastChallengeDialog?.dismiss() |
| 173 | lastChallengeDialog = null |
Matt Pietal | 1aac43b | 2020-02-04 15:43:31 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Matt Pietal | 307b1ef | 2020-02-10 07:27:01 -0500 | [diff] [blame] | 176 | fun setTransientStatus(tempStatus: String) { |
| 177 | val previousText = status.getText() |
Matt Pietal | 307b1ef | 2020-02-10 07:27:01 -0500 | [diff] [blame] | 178 | |
| 179 | cancelUpdate = uiExecutor.executeDelayed({ |
| 180 | status.setText(previousText) |
Matt Pietal | 307b1ef | 2020-02-10 07:27:01 -0500 | [diff] [blame] | 181 | }, UPDATE_DELAY_IN_MILLIS) |
| 182 | |
| 183 | status.setText(tempStatus) |
Matt Pietal | 307b1ef | 2020-02-10 07:27:01 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 186 | fun action(action: ControlAction) { |
Matt Pietal | b7da66c | 2020-03-06 10:49:31 -0500 | [diff] [blame] | 187 | lastAction = action |
Matt Pietal | 313f37d | 2020-02-24 11:27:22 -0500 | [diff] [blame] | 188 | controlsController.action(cws.componentName, cws.ci, action) |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Matt Pietal | 6b4b65c | 2020-04-22 14:16:53 -0400 | [diff] [blame] | 191 | fun usePanel(): Boolean = deviceType in ControlViewHolder.FORCE_PANEL_DEVICES |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 192 | |
| 193 | private fun findBehavior( |
| 194 | status: Int, |
| 195 | template: ControlTemplate, |
| 196 | deviceType: Int |
| 197 | ): KClass<out Behavior> { |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 198 | return when { |
Matt Pietal | 94316e9 | 2020-04-22 10:58:32 -0400 | [diff] [blame] | 199 | status == Control.STATUS_UNKNOWN -> StatusBehavior::class |
| 200 | status == Control.STATUS_ERROR -> StatusBehavior::class |
| 201 | status == Control.STATUS_NOT_FOUND -> StatusBehavior::class |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 202 | deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 203 | template is ToggleTemplate -> ToggleBehavior::class |
Matt Pietal | 53a8bbd | 2020-03-05 16:10:34 -0500 | [diff] [blame] | 204 | template is StatelessTemplate -> TouchBehavior::class |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 205 | template is ToggleRangeTemplate -> ToggleRangeBehavior::class |
| 206 | template is TemperatureControlTemplate -> TemperatureControlBehavior::class |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 207 | else -> DefaultBehavior::class |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 211 | internal fun applyRenderInfo(enabled: Boolean, offset: Int = 0, animated: Boolean = true) { |
Matt Pietal | 53a8bbd | 2020-03-05 16:10:34 -0500 | [diff] [blame] | 212 | setEnabled(enabled) |
| 213 | |
Matt Pietal | 53a8bbd | 2020-03-05 16:10:34 -0500 | [diff] [blame] | 214 | val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset) |
| 215 | |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 216 | val fg = context.resources.getColorStateList(ri.foreground, context.theme) |
| 217 | val bg = context.resources.getColor(R.color.control_default_background, context.theme) |
Matt Pietal | 4f5cd67 | 2020-04-22 13:51:11 -0400 | [diff] [blame] | 218 | var (newClipColor, newAlpha) = if (enabled) { |
| 219 | // allow color overrides for the enabled state only |
| 220 | val color = cws.control?.getCustomColor()?.let { |
| 221 | val state = intArrayOf(android.R.attr.state_enabled) |
| 222 | it.getColorForState(state, it.getDefaultColor()) |
| 223 | } ?: context.resources.getColor(ri.enabledBackground, context.theme) |
| 224 | listOf(color, ALPHA_ENABLED) |
Matt Pietal | a103a94 | 2020-03-13 12:10:35 -0400 | [diff] [blame] | 225 | } else { |
Matt Pietal | 4f5cd67 | 2020-04-22 13:51:11 -0400 | [diff] [blame] | 226 | listOf( |
| 227 | context.resources.getColor(R.color.control_default_background, context.theme), |
| 228 | ALPHA_DISABLED |
| 229 | ) |
Matt Pietal | a103a94 | 2020-03-13 12:10:35 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 232 | status.setTextColor(fg) |
Matt Pietal | f8cc0fa | 2020-03-26 08:48:50 -0400 | [diff] [blame] | 233 | |
Matt Pietal | 4f5cd67 | 2020-04-22 13:51:11 -0400 | [diff] [blame] | 234 | cws.control?.getCustomIcon()?.let { |
| 235 | // do not tint custom icons, assume the intended icon color is correct |
| 236 | icon.imageTintList = null |
| 237 | icon.setImageIcon(it) |
| 238 | } ?: run { |
| 239 | icon.setImageDrawable(ri.icon) |
| 240 | |
| 241 | // do not color app icons |
| 242 | if (deviceType != DeviceTypes.TYPE_ROUTINE) { |
| 243 | icon.imageTintList = fg |
| 244 | } |
Matt Pietal | f8cc0fa | 2020-03-26 08:48:50 -0400 | [diff] [blame] | 245 | } |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 246 | |
Matt Pietal | a103a94 | 2020-03-13 12:10:35 -0400 | [diff] [blame] | 247 | (clipLayer.getDrawable() as GradientDrawable).apply { |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 248 | val newBaseColor = if (behavior is ToggleRangeBehavior) { |
| 249 | ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity) |
| 250 | } else { |
| 251 | bg |
| 252 | } |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 253 | stateAnimator?.cancel() |
| 254 | if (animated) { |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 255 | val oldColor = color?.defaultColor ?: newClipColor |
| 256 | val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor |
Lucas Dupin | d60b332 | 2020-04-15 18:06:47 -0700 | [diff] [blame] | 257 | val oldAlpha = layout.alpha |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 258 | stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply { |
| 259 | addUpdateListener { |
| 260 | alpha = it.animatedValue as Int |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 261 | setColor(ColorUtils.blendARGB(oldColor, newClipColor, it.animatedFraction)) |
| 262 | baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor, |
| 263 | newBaseColor, it.animatedFraction)) |
Matt Pietal | e27ca7c | 2020-05-01 08:29:10 -0400 | [diff] [blame] | 264 | layout.alpha = MathUtils.lerp(oldAlpha, 1f, it.animatedFraction) |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 265 | } |
| 266 | addListener(object : AnimatorListenerAdapter() { |
| 267 | override fun onAnimationEnd(animation: Animator?) { |
| 268 | stateAnimator = null |
| 269 | } |
| 270 | }) |
| 271 | duration = STATE_ANIMATION_DURATION |
| 272 | interpolator = Interpolators.CONTROL_STATE |
| 273 | start() |
| 274 | } |
| 275 | } else { |
| 276 | alpha = newAlpha |
Lucas Dupin | 92f6cca | 2020-04-14 22:30:54 -0700 | [diff] [blame] | 277 | setColor(newClipColor) |
| 278 | baseLayer.setColor(newBaseColor) |
Matt Pietal | e27ca7c | 2020-05-01 08:29:10 -0400 | [diff] [blame] | 279 | layout.alpha = 1f |
Lucas Dupin | 2ee4ec9 | 2020-04-13 19:51:14 -0700 | [diff] [blame] | 280 | } |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 281 | } |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 282 | } |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 283 | |
Matt Pietal | 53a8bbd | 2020-03-05 16:10:34 -0500 | [diff] [blame] | 284 | private fun setEnabled(enabled: Boolean) { |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 285 | status.setEnabled(enabled) |
| 286 | icon.setEnabled(enabled) |
| 287 | } |
| 288 | } |