blob: b4d0e63496052073aeef30e44a3fc5c1406f3004 [file] [log] [blame]
Matt Pietala635bd12020-02-03 13:36:18 -05001/*
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
17package com.android.systemui.controls.ui
18
Matt Pietala635bd12020-02-03 13:36:18 -050019import android.graphics.drawable.Drawable
20import android.graphics.drawable.LayerDrawable
21import android.service.controls.Control
22import android.service.controls.templates.TemperatureControlTemplate
Matt Pietala635bd12020-02-03 13:36:18 -050023
24import com.android.systemui.R
Matt Pietal677981d2020-04-24 14:38:32 -040025import com.android.systemui.controls.ui.ControlViewHolder.Companion.MIN_LEVEL
26import com.android.systemui.controls.ui.ControlViewHolder.Companion.MAX_LEVEL
Matt Pietala635bd12020-02-03 13:36:18 -050027
28class TemperatureControlBehavior : Behavior {
29 lateinit var clipLayer: Drawable
30 lateinit var control: Control
31 lateinit var cvh: ControlViewHolder
32 lateinit var template: TemperatureControlTemplate
Matt Pietala635bd12020-02-03 13:36:18 -050033
Matt Pietalb582b692020-02-14 19:37:57 -050034 override fun initialize(cvh: ControlViewHolder) {
Matt Pietala635bd12020-02-03 13:36:18 -050035 this.cvh = cvh
Matt Pietaldc78c842020-03-30 08:09:18 -040036
37 cvh.layout.setOnClickListener { _ ->
Matt Pietal677981d2020-04-24 14:38:32 -040038 cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control)
Matt Pietaldc78c842020-03-30 08:09:18 -040039 }
Matt Pietalb582b692020-02-14 19:37:57 -050040 }
Matt Pietala635bd12020-02-03 13:36:18 -050041
Matt Pietalb582b692020-02-14 19:37:57 -050042 override fun bind(cws: ControlWithState) {
43 this.control = cws.control!!
44
45 cvh.status.setText(control.getStatusText())
Matt Pietala635bd12020-02-03 13:36:18 -050046
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 Pietala635bd12020-02-03 13:36:18 -050054 clipLayer.setLevel(if (enabled) MAX_LEVEL else MIN_LEVEL)
Matt Pietal53a8bbd2020-03-05 16:10:34 -050055 cvh.applyRenderInfo(enabled, activeMode)
Matt Pietala635bd12020-02-03 13:36:18 -050056 }
57}