blob: c4ff85fb798448c84d0dfbd1918d9036b55d56c4 [file] [log] [blame]
Evan Lairde1d13c92018-03-20 16:58:01 -04001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.annotation.Nullable;
20import android.content.Context;
21import android.graphics.drawable.Icon;
22import android.os.UserHandle;
23import com.android.internal.statusbar.StatusBarIcon;
24import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState;
25import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState;
26
27/**
28 * Wraps {@link com.android.internal.statusbar.StatusBarIcon} so we can still have a uniform list
29 */
30public class StatusBarIconHolder {
31 public static final int TYPE_ICON = 0;
32 public static final int TYPE_WIFI = 1;
33 public static final int TYPE_MOBILE = 2;
34
35 private StatusBarIcon mIcon;
36 private WifiIconState mWifiState;
37 private MobileIconState mMobileState;
38 private int mType = TYPE_ICON;
39 private int mTag = 0;
40 private boolean mVisible = true;
41
42 public static StatusBarIconHolder fromIcon(StatusBarIcon icon) {
43 StatusBarIconHolder wrapper = new StatusBarIconHolder();
44 wrapper.mIcon = icon;
45
46 return wrapper;
47 }
48
49 public static StatusBarIconHolder fromResId(Context context, int resId,
50 CharSequence contentDescription) {
51 StatusBarIconHolder holder = new StatusBarIconHolder();
52 holder.mIcon = new StatusBarIcon(UserHandle.SYSTEM, context.getPackageName(),
53 Icon.createWithResource( context, resId), 0, 0, contentDescription);
54 return holder;
55 }
56
57 public static StatusBarIconHolder fromWifiIconState(WifiIconState state) {
58 StatusBarIconHolder holder = new StatusBarIconHolder();
59 holder.mWifiState = state;
60 holder.mType = TYPE_WIFI;
61 return holder;
62 }
63
64 public static StatusBarIconHolder fromMobileIconState(MobileIconState state) {
65 StatusBarIconHolder holder = new StatusBarIconHolder();
66 holder.mMobileState = state;
67 holder.mType = TYPE_MOBILE;
68 holder.mTag = state.subId;
69 return holder;
70 }
71
72 public int getType() {
73 return mType;
74 }
75
76 @Nullable
77 public StatusBarIcon getIcon() {
78 return mIcon;
79 }
80
81 @Nullable
82 public WifiIconState getWifiState() {
83 return mWifiState;
84 }
85
86 public void setWifiState(WifiIconState state) {
87 mWifiState = state;
88 }
89
90 @Nullable
91 public MobileIconState getMobileState() {
92 return mMobileState;
93 }
94
95 public void setMobileState(MobileIconState state) {
96 mMobileState = state;
97 }
98
99 public boolean isVisible() {
100 switch (mType) {
101 case TYPE_ICON:
102 return mIcon.visible;
103 case TYPE_WIFI:
104 return mWifiState.visible;
105 case TYPE_MOBILE:
106 return mMobileState.visible;
107
108 default: return true;
109 }
110 }
111
112 public void setVisible(boolean visible) {
Evan Laird56fb9f82018-04-24 21:11:15 -0400113 if (isVisible() == visible) {
114 return;
115 }
116
Evan Lairde1d13c92018-03-20 16:58:01 -0400117 switch (mType) {
118 case TYPE_ICON:
119 mIcon.visible = visible;
120 break;
121
122 case TYPE_WIFI:
123 mWifiState.visible = visible;
124 break;
125
126 case TYPE_MOBILE:
127 mMobileState.visible = visible;
128 break;
129 }
130 }
131
132 public int getTag() {
133 return mTag;
134 }
135}