Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 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 | import com.android.internal.statusbar.StatusBarIcon; |
| 24 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState; |
| 25 | import 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 | */ |
| 30 | public 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) { |
| 113 | switch (mType) { |
| 114 | case TYPE_ICON: |
| 115 | mIcon.visible = visible; |
| 116 | break; |
| 117 | |
| 118 | case TYPE_WIFI: |
| 119 | mWifiState.visible = visible; |
| 120 | break; |
| 121 | |
| 122 | case TYPE_MOBILE: |
| 123 | mMobileState.visible = visible; |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | public int getTag() { |
| 129 | return mTag; |
| 130 | } |
| 131 | } |