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 
19 import android.content.Context
20 import android.service.controls.Control
21 
22 /**
23  * All control interactions should be routed through this coordinator. It handles dispatching of
24  * actions, haptic support, and all detail panels
25  */
26 interface ControlActionCoordinator {
27 
28     // If launched from an Activity, continue within this stack
29     var activityContext: Context
30 
31     /**
32      * Close any dialogs which may have been open
33      */
34     fun closeDialogs()
35 
36     /**
37      * Create a [BooleanAction], and inform the service of a request to change the device state
38      *
39      * @param cvh [ControlViewHolder] for the control
40      * @param templateId id of the control's template, as given by the service
41      * @param isChecked new requested state of the control
42      */
43     fun toggle(cvh: ControlViewHolder, templateId: String, isChecked: Boolean)
44 
45     /**
46      * For non-toggle controls, touching may create a dialog or invoke a [CommandAction].
47      *
48      * @param cvh [ControlViewHolder] for the control
49      * @param templateId id of the control's template, as given by the service
50      * @param control the control as sent by the service
51      */
52     fun touch(cvh: ControlViewHolder, templateId: String, control: Control)
53 
54     /**
55      * When a ToggleRange control is interacting with, a drag event is sent.
56      *
57      * @param isEdge did the drag event reach a control edge
58      */
59     fun drag(isEdge: Boolean)
60 
61     /**
62      * Send a request to update the value of a device using the [FloatAction].
63      *
64      * @param cvh [ControlViewHolder] for the control
65      * @param templateId id of the control's template, as given by the service
66      * @param newValue value to set for the device
67      */
68     fun setValue(cvh: ControlViewHolder, templateId: String, newValue: Float)
69 
70     /**
71      * Actions may have been put on hold while the device is unlocked. Invoke this action if
72      * present.
73      */
74     fun runPendingAction(controlId: String)
75 
76     /**
77      * User interaction with a control may be blocked for a period of time while actions are being
78      * executed by the application.  When the response returns, run this method to enable further
79      * user interaction.
80      */
81     fun enableActionOnTouch(controlId: String)
82 
83     /**
84      * All long presses will be shown in a 3/4 height bottomsheet panel, in order for the user to
85      * retain context with their favorited controls in the power menu.
86      */
87     fun longPress(cvh: ControlViewHolder)
88 }
89