1 /* <lambda>null2 * Copyright (C) 2021 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.statusbar.events 18 19 import android.annotation.IntRange 20 import android.annotation.SuppressLint 21 import android.content.Context 22 import android.view.View 23 import android.widget.ImageView 24 import com.android.systemui.privacy.OngoingPrivacyChip 25 import com.android.systemui.privacy.PrivacyItem 26 import com.android.systemui.statusbar.BatteryStatusChip 27 28 typealias ViewCreator = (context: Context) -> BackgroundAnimatableView 29 30 interface StatusEvent { 31 val priority: Int 32 // Whether or not to force the status bar open and show a dot 33 var forceVisible: Boolean 34 // Whether or not to show an animation for this event 35 val showAnimation: Boolean 36 val viewCreator: ViewCreator 37 var contentDescription: String? 38 39 // Update this event with values from another event. 40 fun updateFromEvent(other: StatusEvent?) { 41 // no op by default 42 } 43 44 // Whether or not this event should update its value from the provided. False by default 45 fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { 46 return false 47 } 48 } 49 50 class BGView( 51 context: Context 52 ) : View(context), BackgroundAnimatableView { 53 override val view: View 54 get() = this 55 setBoundsForAnimationnull56 override fun setBoundsForAnimation(l: Int, t: Int, r: Int, b: Int) { 57 setLeftTopRightBottom(l, t, r, b) 58 } 59 } 60 61 @SuppressLint("AppCompatCustomView") 62 class BGImageView( 63 context: Context 64 ) : ImageView(context), BackgroundAnimatableView { 65 override val view: View 66 get() = this 67 setBoundsForAnimationnull68 override fun setBoundsForAnimation(l: Int, t: Int, r: Int, b: Int) { 69 setLeftTopRightBottom(l, t, r, b) 70 } 71 } 72 73 class BatteryEvent(@IntRange(from = 0, to = 100) val batteryLevel: Int) : StatusEvent { 74 override val priority = 50 75 override var forceVisible = false 76 override val showAnimation = true 77 override var contentDescription: String? = "" 78 contextnull79 override val viewCreator: ViewCreator = { context -> 80 BatteryStatusChip(context).apply { 81 setBatteryLevel(batteryLevel) 82 } 83 } 84 toStringnull85 override fun toString(): String { 86 return javaClass.simpleName 87 } 88 } 89 90 class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { 91 override var contentDescription: String? = null 92 override val priority = 100 93 override var forceVisible = true 94 var privacyItems: List<PrivacyItem> = listOf() 95 private var privacyChip: OngoingPrivacyChip? = null 96 contextnull97 override val viewCreator: ViewCreator = { context -> 98 val v = OngoingPrivacyChip(context) 99 v.privacyList = privacyItems 100 v.contentDescription = contentDescription 101 privacyChip = v 102 v 103 } 104 toStringnull105 override fun toString(): String { 106 return "${javaClass.simpleName}(forceVisible=$forceVisible, privacyItems=$privacyItems)" 107 } 108 shouldUpdateFromEventnull109 override fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { 110 return other is PrivacyEvent 111 } 112 updateFromEventnull113 override fun updateFromEvent(other: StatusEvent?) { 114 if (other !is PrivacyEvent) { 115 return 116 } 117 118 privacyItems = other.privacyItems 119 contentDescription = other.contentDescription 120 121 privacyChip?.contentDescription = other.contentDescription 122 privacyChip?.privacyList = other.privacyItems 123 } 124 } 125