Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -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 | |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 19 | import android.graphics.drawable.Drawable |
| 20 | import android.graphics.drawable.LayerDrawable |
| 21 | import android.service.controls.Control |
| 22 | import android.service.controls.templates.TemperatureControlTemplate |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 23 | |
| 24 | import com.android.systemui.R |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 25 | import com.android.systemui.controls.ui.ControlViewHolder.Companion.MIN_LEVEL |
| 26 | import com.android.systemui.controls.ui.ControlViewHolder.Companion.MAX_LEVEL |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 27 | |
| 28 | class TemperatureControlBehavior : Behavior { |
| 29 | lateinit var clipLayer: Drawable |
| 30 | lateinit var control: Control |
| 31 | lateinit var cvh: ControlViewHolder |
| 32 | lateinit var template: TemperatureControlTemplate |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 33 | |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 34 | override fun initialize(cvh: ControlViewHolder) { |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 35 | this.cvh = cvh |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 36 | |
| 37 | cvh.layout.setOnClickListener { _ -> |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 38 | cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control) |
Matt Pietal | dc78c84 | 2020-03-30 08:09:18 -0400 | [diff] [blame] | 39 | } |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 40 | } |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 41 | |
Matt Pietal | b582b69 | 2020-02-14 19:37:57 -0500 | [diff] [blame] | 42 | override fun bind(cws: ControlWithState) { |
| 43 | this.control = cws.control!! |
| 44 | |
| 45 | cvh.status.setText(control.getStatusText()) |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 46 | |
| 47 | val ld = cvh.layout.getBackground() as LayerDrawable |
| 48 | clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) |
| 49 | |
| 50 | template = control.getControlTemplate() as TemperatureControlTemplate |
| 51 | |
| 52 | val activeMode = template.getCurrentActiveMode() |
| 53 | val enabled = activeMode != 0 && activeMode != TemperatureControlTemplate.MODE_OFF |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 54 | clipLayer.setLevel(if (enabled) MAX_LEVEL else MIN_LEVEL) |
Matt Pietal | 53a8bbd | 2020-03-05 16:10:34 -0500 | [diff] [blame] | 55 | cvh.applyRenderInfo(enabled, activeMode) |
Matt Pietal | a635bd1 | 2020-02-03 13:36:18 -0500 | [diff] [blame] | 56 | } |
| 57 | } |