blob: 8ce2e617669ced506e887e689d182c2b603d38cf [file] [log] [blame]
Matt Pietal53a8bbd2020-03-05 16:10:34 -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
19import android.graphics.drawable.Drawable
20import android.graphics.drawable.LayerDrawable
21import android.view.View
22import android.service.controls.Control
Matt Pietaldc78c842020-03-30 08:09:18 -040023import android.service.controls.templates.ControlTemplate
Matt Pietal53a8bbd2020-03-05 16:10:34 -050024
25import com.android.systemui.R
Matt Pietal677981d2020-04-24 14:38:32 -040026import com.android.systemui.controls.ui.ControlViewHolder.Companion.MIN_LEVEL
Matt Pietal53a8bbd2020-03-05 16:10:34 -050027
28/**
29 * Supports touch events, but has no notion of state as the {@link ToggleBehavior} does. Must be
30 * used with {@link StatelessTemplate}.
31 */
32class TouchBehavior : Behavior {
33 lateinit var clipLayer: Drawable
Matt Pietaldc78c842020-03-30 08:09:18 -040034 lateinit var template: ControlTemplate
Matt Pietal53a8bbd2020-03-05 16:10:34 -050035 lateinit var control: Control
36 lateinit var cvh: ControlViewHolder
37
38 override fun initialize(cvh: ControlViewHolder) {
39 this.cvh = cvh
Lucas Dupin2ee4ec92020-04-13 19:51:14 -070040 cvh.applyRenderInfo(false /* enabled */, 0 /* offset */, false /* animated */)
Matt Pietal53a8bbd2020-03-05 16:10:34 -050041
42 cvh.layout.setOnClickListener(View.OnClickListener() {
Matt Pietal677981d2020-04-24 14:38:32 -040043 cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control)
Matt Pietal53a8bbd2020-03-05 16:10:34 -050044 })
45 }
46
Matt Pietalcf516132020-05-07 16:50:04 -040047 override fun bind(cws: ControlWithState, colorOffset: Int) {
Matt Pietal53a8bbd2020-03-05 16:10:34 -050048 this.control = cws.control!!
49 cvh.status.setText(control.getStatusText())
Matt Pietaldc78c842020-03-30 08:09:18 -040050 template = control.getControlTemplate()
Matt Pietal53a8bbd2020-03-05 16:10:34 -050051
52 val ld = cvh.layout.getBackground() as LayerDrawable
53 clipLayer = ld.findDrawableByLayerId(R.id.clip_layer)
54 clipLayer.setLevel(MIN_LEVEL)
55
Matt Pietalcf516132020-05-07 16:50:04 -040056 cvh.applyRenderInfo(false, colorOffset)
Matt Pietal53a8bbd2020-03-05 16:10:34 -050057 }
58}