• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.systemui.statusbar.phone
17 
18 import android.annotation.IntDef
19 import com.android.internal.statusbar.StatusBarIcon
20 import com.android.systemui.statusbar.pipeline.icons.shared.model.ModernStatusBarViewCreator
21 
22 /** Wraps [com.android.internal.statusbar.StatusBarIcon] so we can still have a uniform list */
23 open class StatusBarIconHolder private constructor() {
24     @IntDef(TYPE_ICON, TYPE_MOBILE_NEW, TYPE_WIFI_NEW, TYPE_BINDABLE)
25     @Retention(AnnotationRetention.SOURCE)
26     internal annotation class IconType
27 
28     var icon: StatusBarIcon? = null
29 
30     @IconType
31     open var type = TYPE_ICON
32         internal set
33 
34     var tag = 0
35         private set
36 
37     open var isVisible: Boolean
38         get() =
39             when (type) {
40                 TYPE_ICON -> icon!!.visible
41 
42                 // The new pipeline controls visibilities via the view model and
43                 // view binder, so
44                 // this is effectively an unused return value.
45                 TYPE_BINDABLE,
46                 TYPE_MOBILE_NEW,
47                 TYPE_WIFI_NEW -> true
48                 else -> true
49             }
50         set(visible) {
51             if (isVisible == visible) {
52                 return
53             }
54             when (type) {
55                 TYPE_ICON -> icon!!.visible = visible
56                 TYPE_BINDABLE,
57                 TYPE_MOBILE_NEW,
58                 TYPE_WIFI_NEW -> {}
59             }
60         }
61 
toStringnull62     override fun toString(): String {
63         return ("StatusBarIconHolder(type=${getTypeString(type)}" +
64             " tag=$tag" +
65             " visible=$isVisible)")
66     }
67 
68     companion object {
69         const val TYPE_ICON = 0
70 
71         /**
72          * TODO (b/249790733): address this once the new pipeline is in place This type exists so
73          * that the new pipeline (see [MobileIconViewModel]) can be used to inform the old view
74          * system about changes to the data set (the list of mobile icons). The design of the new
75          * pipeline should allow for removal of this icon holder type, and obsolete the need for
76          * this entire class.
77          */
78         @Deprecated(
79             """This field only exists so the new status bar pipeline can interface with the
80       view holder system."""
81         )
82         const val TYPE_MOBILE_NEW = 3
83 
84         /**
85          * TODO (b/238425913): address this once the new pipeline is in place This type exists so
86          * that the new wifi pipeline can be used to inform the old view system about the existence
87          * of the wifi icon. The design of the new pipeline should allow for removal of this icon
88          * holder type, and obsolete the need for this entire class.
89          */
90         @Deprecated(
91             """This field only exists so the new status bar pipeline can interface with the
92       view holder system."""
93         )
94         const val TYPE_WIFI_NEW = 4
95 
96         /** Only applicable to [BindableIconHolder] */
97         const val TYPE_BINDABLE = 5
98 
99         /** Returns a human-readable string representing the given type. */
getTypeStringnull100         fun getTypeString(@IconType type: Int): String {
101             return when (type) {
102                 TYPE_ICON -> "ICON"
103                 TYPE_MOBILE_NEW -> "MOBILE_NEW"
104                 TYPE_WIFI_NEW -> "WIFI_NEW"
105                 else -> "UNKNOWN"
106             }
107         }
108 
109         @JvmStatic
fromIconnull110         fun fromIcon(icon: StatusBarIcon?): StatusBarIconHolder {
111             val wrapper = StatusBarIconHolder()
112             wrapper.icon = icon
113             return wrapper
114         }
115 
116         /** Creates a new holder with for the new wifi icon. */
117         @JvmStatic
forNewWifiIconnull118         fun forNewWifiIcon(): StatusBarIconHolder {
119             val holder = StatusBarIconHolder()
120             holder.type = TYPE_WIFI_NEW
121             return holder
122         }
123 
124         /**
125          * ONLY for use with the new connectivity pipeline, where we only need a subscriptionID to
126          * determine icon ordering and building the correct view model
127          */
128         @JvmStatic
fromSubIdForModernMobileIconnull129         fun fromSubIdForModernMobileIcon(subId: Int): StatusBarIconHolder {
130             val holder = StatusBarIconHolder()
131             holder.type = TYPE_MOBILE_NEW
132             holder.tag = subId
133             return holder
134         }
135     }
136 
137     /**
138      * Subclass of StatusBarIconHolder that is responsible only for the registration of an icon into
139      * the [StatusBarIconList]. A bindable icon takes care of its own display, including hiding
140      * itself under the correct conditions.
141      *
142      * StatusBarIconController will register all available bindable icons on init (see
143      * [BindableIconsRepository]), and will ignore any call to setIcon for these.
144      *
145      * @property initializer a view creator that can bind the relevant view models to the created
146      *   view.
147      * @property slot the name of the slot that this holder is used for.
148      */
149     class BindableIconHolder(val initializer: ModernStatusBarViewCreator, val slot: String) :
150         StatusBarIconHolder() {
151         override var type: Int = TYPE_BINDABLE
152 
153         /** This is unused, as bindable icons use their own view binders to control visibility */
154         override var isVisible: Boolean = true
155 
toStringnull156         override fun toString(): String {
157             return ("StatusBarIconHolder(type=BINDABLE, slot=$slot)")
158         }
159     }
160 }
161