1 /* <lambda>null2 * 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 19 import android.graphics.drawable.Drawable 20 import android.graphics.drawable.LayerDrawable 21 import android.service.controls.Control 22 import android.service.controls.templates.ControlTemplate 23 import android.service.controls.templates.TemperatureControlTemplate 24 25 import com.android.systemui.res.R 26 import com.android.systemui.controls.ui.ControlViewHolder.Companion.MIN_LEVEL 27 import com.android.systemui.controls.ui.ControlViewHolder.Companion.MAX_LEVEL 28 29 class TemperatureControlBehavior : Behavior { 30 lateinit var clipLayer: Drawable 31 lateinit var control: Control 32 lateinit var cvh: ControlViewHolder 33 var subBehavior: Behavior? = null 34 35 override fun initialize(cvh: ControlViewHolder) { 36 this.cvh = cvh 37 } 38 39 override fun bind(cws: ControlWithState, colorOffset: Int) { 40 this.control = cws.control!! 41 42 cvh.setStatusText(control.getStatusText()) 43 44 val ld = cvh.layout.getBackground() as LayerDrawable 45 clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) 46 47 val template = control.getControlTemplate() as TemperatureControlTemplate 48 val activeMode = template.getCurrentActiveMode() 49 val subTemplate = template.getTemplate() 50 if (subTemplate == ControlTemplate.getNoTemplateObject() || 51 subTemplate == ControlTemplate.getErrorTemplate()) { 52 // No sub template is specified, apply a default look with basic touch interaction. 53 // Treat an error as no template. 54 val enabled = activeMode != 0 && activeMode != TemperatureControlTemplate.MODE_OFF 55 clipLayer.setLevel(if (enabled) MAX_LEVEL else MIN_LEVEL) 56 cvh.applyRenderInfo(enabled, activeMode) 57 58 cvh.layout.setOnClickListener { _ -> 59 cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control) 60 } 61 } else { 62 // A sub template has been specified, use this as the default behavior for user 63 // interactions (touch, range) 64 subBehavior = cvh.bindBehavior( 65 subBehavior, 66 cvh.findBehaviorClass( 67 control.status, 68 subTemplate, 69 control.deviceType 70 ), 71 activeMode 72 ) 73 } 74 } 75 } 76