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.content.Context 20 import android.graphics.Color 21 import android.graphics.drawable.ColorDrawable 22 import android.view.LayoutInflater 23 import android.view.View 24 import android.widget.ImageView 25 import com.android.settingslib.graph.ThemedBatteryDrawable 26 import com.android.systemui.R 27 import com.android.systemui.privacy.OngoingPrivacyChip 28 import com.android.systemui.privacy.PrivacyItem 29 30 interface StatusEvent { 31 val priority: Int 32 // Whether or not to force the status bar open and show a dot 33 val forceVisible: Boolean 34 // Whether or not to show an animation for this event 35 val showAnimation: Boolean 36 val viewCreator: (context: Context) -> View 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 BatteryEvent : StatusEvent { 51 override val priority = 50 52 override val forceVisible = false 53 override val showAnimation = true 54 override var contentDescription: String? = "" 55 contextnull56 override val viewCreator: (context: Context) -> View = { context -> 57 val iv = ImageView(context) 58 iv.setImageDrawable(ThemedBatteryDrawable(context, Color.WHITE)) 59 iv.setBackgroundDrawable(ColorDrawable(Color.GREEN)) 60 iv 61 } 62 toStringnull63 override fun toString(): String { 64 return javaClass.simpleName 65 } 66 } 67 68 class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { 69 override var contentDescription: String? = null 70 override val priority = 100 71 override val forceVisible = true 72 var privacyItems: List<PrivacyItem> = listOf() 73 private var privacyChip: OngoingPrivacyChip? = null 74 contextnull75 override val viewCreator: (context: Context) -> View = { context -> 76 val v = LayoutInflater.from(context) 77 .inflate(R.layout.ongoing_privacy_chip, null) as OngoingPrivacyChip 78 v.privacyList = privacyItems 79 v.contentDescription = contentDescription 80 privacyChip = v 81 v 82 } 83 toStringnull84 override fun toString(): String { 85 return javaClass.simpleName 86 } 87 shouldUpdateFromEventnull88 override fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { 89 return other is PrivacyEvent && 90 (other.privacyItems != privacyItems || 91 other.contentDescription != contentDescription) 92 } 93 updateFromEventnull94 override fun updateFromEvent(other: StatusEvent?) { 95 if (other !is PrivacyEvent) { 96 return 97 } 98 99 privacyItems = other.privacyItems 100 contentDescription = other.contentDescription 101 102 privacyChip?.contentDescription = other.contentDescription 103 privacyChip?.privacyList = other.privacyItems 104 } 105 } 106