1 /*
2  * Copyright (C) 2022 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.temporarydisplay.chipbar
18 
19 import android.os.VibrationEffect
20 import android.view.View
21 import androidx.annotation.AttrRes
22 import com.android.internal.logging.InstanceId
23 import com.android.systemui.common.shared.model.Text
24 import com.android.systemui.common.shared.model.TintedIcon
25 import com.android.systemui.res.R
26 import com.android.systemui.temporarydisplay.TemporaryViewInfo
27 import com.android.systemui.temporarydisplay.ViewPriority
28 
29 /**
30  * A container for all the state needed to display a chipbar via [ChipbarCoordinator].
31  *
32  * @property startIcon the icon to display at the start of the chipbar (on the left in LTR locales;
33  *   on the right in RTL locales).
34  * @property text the text to display.
35  * @property endItem an optional end item to display at the end of the chipbar (on the right in LTR
36  *   locales; on the left in RTL locales).
37  * @property vibrationEffect an optional vibration effect when the chipbar is displayed
38  * @property allowSwipeToDismiss true if users are allowed to swipe up to dismiss this chipbar.
39  */
40 data class ChipbarInfo(
41     val startIcon: TintedIcon,
42     val text: Text,
43     val endItem: ChipbarEndItem?,
44     val vibrationEffect: VibrationEffect? = null,
45     val allowSwipeToDismiss: Boolean = false,
46     override val windowTitle: String,
47     override val wakeReason: String,
48     override val timeoutMs: Int,
49     override val id: String,
50     override val priority: ViewPriority,
51     override val instanceId: InstanceId?,
52 ) : TemporaryViewInfo() {
53     companion object {
54         // LINT.IfChange
55         @AttrRes val DEFAULT_ICON_TINT = com.android.internal.R.attr.materialColorOnSecondaryFixed
56         // LINT.ThenChange(systemui/res/layout/chipbar.xml)
57     }
58 }
59 
60 /** The possible items to display at the end of the chipbar. */
61 sealed class ChipbarEndItem {
62     /** A loading icon should be displayed. */
63     object Loading : ChipbarEndItem()
64 
65     /** An error icon should be displayed. */
66     object Error : ChipbarEndItem()
67 
68     /**
69      * A button with the provided [text] and [onClickListener] functionality should be displayed.
70      */
71     data class Button(val text: Text, val onClickListener: View.OnClickListener) : ChipbarEndItem()
72 
73     // TODO(b/245610654): Add support for a generic icon.
74 }
75