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