• 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 
17 package com.android.systemui.statusbar.phone;
18 
19 import android.annotation.Nullable;
20 import android.content.Context;
21 import android.graphics.drawable.Icon;
22 import android.os.UserHandle;
23 
24 import com.android.internal.statusbar.StatusBarIcon;
25 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.CallIndicatorIconState;
26 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState;
27 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState;
28 
29 /**
30  * Wraps {@link com.android.internal.statusbar.StatusBarIcon} so we can still have a uniform list
31  */
32 public class StatusBarIconHolder {
33     public static final int TYPE_ICON = 0;
34     public static final int TYPE_WIFI = 1;
35     public static final int TYPE_MOBILE = 2;
36 
37     private StatusBarIcon mIcon;
38     private WifiIconState mWifiState;
39     private MobileIconState mMobileState;
40     private int mType = TYPE_ICON;
41     private int mTag = 0;
42 
StatusBarIconHolder()43     private StatusBarIconHolder() {
44 
45     }
46 
fromIcon(StatusBarIcon icon)47     public static StatusBarIconHolder fromIcon(StatusBarIcon icon) {
48         StatusBarIconHolder wrapper = new StatusBarIconHolder();
49         wrapper.mIcon = icon;
50 
51         return wrapper;
52     }
53 
54     /** */
fromResId( Context context, int resId, CharSequence contentDescription)55     public static StatusBarIconHolder fromResId(
56             Context context,
57             int resId,
58             CharSequence contentDescription) {
59         StatusBarIconHolder holder = new StatusBarIconHolder();
60         holder.mIcon = new StatusBarIcon(UserHandle.SYSTEM, context.getPackageName(),
61                 Icon.createWithResource( context, resId), 0, 0, contentDescription);
62         return holder;
63     }
64 
65     /** */
fromWifiIconState(WifiIconState state)66     public static StatusBarIconHolder fromWifiIconState(WifiIconState state) {
67         StatusBarIconHolder holder = new StatusBarIconHolder();
68         holder.mWifiState = state;
69         holder.mType = TYPE_WIFI;
70         return holder;
71     }
72 
73     /** */
fromMobileIconState(MobileIconState state)74     public static StatusBarIconHolder fromMobileIconState(MobileIconState state) {
75         StatusBarIconHolder holder = new StatusBarIconHolder();
76         holder.mMobileState = state;
77         holder.mType = TYPE_MOBILE;
78         holder.mTag = state.subId;
79         return holder;
80     }
81 
82     /**
83      * Creates a new StatusBarIconHolder from a CallIndicatorIconState.
84      */
fromCallIndicatorState( Context context, CallIndicatorIconState state)85     public static StatusBarIconHolder fromCallIndicatorState(
86             Context context,
87             CallIndicatorIconState state) {
88         StatusBarIconHolder holder = new StatusBarIconHolder();
89         int resId = state.isNoCalling ? state.noCallingResId : state.callStrengthResId;
90         String contentDescription = state.isNoCalling
91                 ? state.noCallingDescription : state.callStrengthDescription;
92         holder.mIcon = new StatusBarIcon(UserHandle.SYSTEM, context.getPackageName(),
93                 Icon.createWithResource(context, resId), 0, 0, contentDescription);
94         holder.mTag = state.subId;
95         return holder;
96     }
97 
getType()98     public int getType() {
99         return mType;
100     }
101 
102     @Nullable
getIcon()103     public StatusBarIcon getIcon() {
104         return mIcon;
105     }
106 
setIcon(StatusBarIcon icon)107     public void setIcon(StatusBarIcon icon) {
108         mIcon = icon;
109     }
110 
111     @Nullable
getWifiState()112     public WifiIconState getWifiState() {
113         return mWifiState;
114     }
115 
setWifiState(WifiIconState state)116     public void setWifiState(WifiIconState state) {
117         mWifiState = state;
118     }
119 
120     @Nullable
getMobileState()121     public MobileIconState getMobileState() {
122         return mMobileState;
123     }
124 
setMobileState(MobileIconState state)125     public void setMobileState(MobileIconState state) {
126         mMobileState = state;
127     }
128 
isVisible()129     public boolean isVisible() {
130         switch (mType) {
131             case TYPE_ICON:
132                 return mIcon.visible;
133             case TYPE_WIFI:
134                 return mWifiState.visible;
135             case TYPE_MOBILE:
136                 return mMobileState.visible;
137 
138             default: return true;
139         }
140     }
141 
setVisible(boolean visible)142     public void setVisible(boolean visible) {
143         if (isVisible() == visible) {
144             return;
145         }
146 
147         switch (mType) {
148             case TYPE_ICON:
149                 mIcon.visible = visible;
150                 break;
151 
152             case TYPE_WIFI:
153                 mWifiState.visible = visible;
154                 break;
155 
156             case TYPE_MOBILE:
157                 mMobileState.visible = visible;
158                 break;
159         }
160     }
161 
getTag()162     public int getTag() {
163         return mTag;
164     }
165 }
166