John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 19 | import android.graphics.Rect; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 20 | import android.graphics.drawable.Icon; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 21 | import android.os.Bundle; |
| 22 | import android.os.UserHandle; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 23 | import android.util.Log; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 24 | import android.view.Gravity; |
| 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
| 27 | import android.widget.LinearLayout; |
| 28 | |
| 29 | import com.android.internal.statusbar.StatusBarIcon; |
| 30 | import com.android.systemui.DemoMode; |
| 31 | import com.android.systemui.R; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 32 | import com.android.systemui.statusbar.StatusIconDisplayable; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 33 | import com.android.systemui.statusbar.StatusBarIconView; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.StatusBarMobileView; |
| 35 | import com.android.systemui.statusbar.StatusBarWifiView; |
| 36 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState; |
| 37 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState; |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 38 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
| 39 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 40 | import java.util.ArrayList; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 41 | |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 42 | public class DemoStatusIcons extends StatusIconContainer implements DemoMode, DarkReceiver { |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 43 | private static final String TAG = "DemoStatusIcons"; |
| 44 | |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 45 | private final LinearLayout mStatusIcons; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 46 | private final ArrayList<StatusBarMobileView> mMobileViews = new ArrayList<>(); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 47 | private final int mIconSize; |
| 48 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 49 | private StatusBarWifiView mWifiView; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 50 | private boolean mDemoMode; |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 51 | private int mColor; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 52 | |
| 53 | public DemoStatusIcons(LinearLayout statusIcons, int iconSize) { |
| 54 | super(statusIcons.getContext()); |
| 55 | mStatusIcons = statusIcons; |
| 56 | mIconSize = iconSize; |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 57 | mColor = DarkIconDispatcher.DEFAULT_ICON_TINT; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 58 | |
| 59 | setLayoutParams(mStatusIcons.getLayoutParams()); |
| 60 | setOrientation(mStatusIcons.getOrientation()); |
| 61 | setGravity(Gravity.CENTER_VERTICAL); // no LL.getGravity() |
| 62 | ViewGroup p = (ViewGroup) mStatusIcons.getParent(); |
| 63 | p.addView(this, p.indexOfChild(mStatusIcons)); |
| 64 | } |
| 65 | |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 66 | public void remove() { |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 67 | mMobileViews.clear(); |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 68 | ((ViewGroup) getParent()).removeView(this); |
| 69 | } |
| 70 | |
| 71 | public void setColor(int color) { |
| 72 | mColor = color; |
| 73 | updateColors(); |
| 74 | } |
| 75 | |
| 76 | private void updateColors() { |
| 77 | for (int i = 0; i < getChildCount(); i++) { |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 78 | StatusIconDisplayable child = (StatusIconDisplayable) getChildAt(i); |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 79 | child.setStaticDrawableColor(mColor); |
| 80 | } |
| 81 | } |
| 82 | |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 83 | @Override |
| 84 | public void dispatchDemoCommand(String command, Bundle args) { |
| 85 | if (!mDemoMode && command.equals(COMMAND_ENTER)) { |
| 86 | mDemoMode = true; |
| 87 | mStatusIcons.setVisibility(View.GONE); |
| 88 | setVisibility(View.VISIBLE); |
| 89 | } else if (mDemoMode && command.equals(COMMAND_EXIT)) { |
| 90 | mDemoMode = false; |
| 91 | mStatusIcons.setVisibility(View.VISIBLE); |
| 92 | setVisibility(View.GONE); |
| 93 | } else if (mDemoMode && command.equals(COMMAND_STATUS)) { |
| 94 | String volume = args.getString("volume"); |
| 95 | if (volume != null) { |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 96 | int iconId = volume.equals("vibrate") ? R.drawable.stat_sys_ringer_vibrate |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 97 | : 0; |
| 98 | updateSlot("volume", null, iconId); |
| 99 | } |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 100 | String zen = args.getString("zen"); |
| 101 | if (zen != null) { |
| 102 | int iconId = zen.equals("important") ? R.drawable.stat_sys_zen_important |
| 103 | : zen.equals("none") ? R.drawable.stat_sys_zen_none |
| 104 | : 0; |
| 105 | updateSlot("zen", null, iconId); |
| 106 | } |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 107 | String bt = args.getString("bluetooth"); |
| 108 | if (bt != null) { |
| 109 | int iconId = bt.equals("disconnected") ? R.drawable.stat_sys_data_bluetooth |
| 110 | : bt.equals("connected") ? R.drawable.stat_sys_data_bluetooth_connected |
| 111 | : 0; |
| 112 | updateSlot("bluetooth", null, iconId); |
| 113 | } |
| 114 | String location = args.getString("location"); |
| 115 | if (location != null) { |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 116 | int iconId = location.equals("show") ? PhoneStatusBarPolicy.LOCATION_STATUS_ICON_ID |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 117 | : 0; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 118 | updateSlot("location", null, iconId); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 119 | } |
| 120 | String alarm = args.getString("alarm"); |
| 121 | if (alarm != null) { |
| 122 | int iconId = alarm.equals("show") ? R.drawable.stat_sys_alarm |
| 123 | : 0; |
| 124 | updateSlot("alarm_clock", null, iconId); |
| 125 | } |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 126 | String tty = args.getString("tty"); |
| 127 | if (tty != null) { |
| 128 | int iconId = tty.equals("show") ? R.drawable.stat_sys_tty_mode |
| 129 | : 0; |
| 130 | updateSlot("tty", null, iconId); |
| 131 | } |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 132 | String mute = args.getString("mute"); |
| 133 | if (mute != null) { |
| 134 | int iconId = mute.equals("show") ? android.R.drawable.stat_notify_call_mute |
| 135 | : 0; |
| 136 | updateSlot("mute", null, iconId); |
| 137 | } |
| 138 | String speakerphone = args.getString("speakerphone"); |
| 139 | if (speakerphone != null) { |
| 140 | int iconId = speakerphone.equals("show") ? android.R.drawable.stat_sys_speakerphone |
| 141 | : 0; |
| 142 | updateSlot("speakerphone", null, iconId); |
| 143 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 144 | String cast = args.getString("cast"); |
| 145 | if (cast != null) { |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 146 | int iconId = cast.equals("show") ? R.drawable.stat_sys_cast : 0; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 147 | updateSlot("cast", null, iconId); |
| 148 | } |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 149 | String hotspot = args.getString("hotspot"); |
| 150 | if (hotspot != null) { |
| 151 | int iconId = hotspot.equals("show") ? R.drawable.stat_sys_hotspot : 0; |
| 152 | updateSlot("hotspot", null, iconId); |
| 153 | } |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 157 | /// Can only be used to update non-signal related slots |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 158 | private void updateSlot(String slot, String iconPkg, int iconId) { |
| 159 | if (!mDemoMode) return; |
Jason Monk | 259e06f | 2015-06-18 14:07:26 -0400 | [diff] [blame] | 160 | if (iconPkg == null) { |
| 161 | iconPkg = mContext.getPackageName(); |
| 162 | } |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 163 | int removeIndex = -1; |
| 164 | for (int i = 0; i < getChildCount(); i++) { |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 165 | View child = getChildAt(i); |
| 166 | if (!(child instanceof StatusBarIconView)) { |
| 167 | continue; |
| 168 | } |
| 169 | StatusBarIconView v = (StatusBarIconView) child; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 170 | if (slot.equals(v.getTag())) { |
| 171 | if (iconId == 0) { |
| 172 | removeIndex = i; |
| 173 | break; |
| 174 | } else { |
| 175 | StatusBarIcon icon = v.getStatusBarIcon(); |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 176 | icon.visible = true; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 177 | icon.icon = Icon.createWithResource(icon.icon.getResPackage(), iconId); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 178 | v.set(icon); |
| 179 | v.updateDrawable(); |
| 180 | return; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | if (iconId == 0) { |
| 185 | if (removeIndex != -1) { |
| 186 | removeViewAt(removeIndex); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 187 | } |
Jason Monk | 259e06f | 2015-06-18 14:07:26 -0400 | [diff] [blame] | 188 | return; |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 189 | } |
Xiaohui Chen | 87d0e25 | 2015-07-30 15:38:16 -0700 | [diff] [blame] | 190 | StatusBarIcon icon = new StatusBarIcon(iconPkg, UserHandle.SYSTEM, iconId, 0, 0, "Demo"); |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 191 | icon.visible = true; |
John Spurlock | fd9aa5f | 2014-10-31 10:28:11 -0400 | [diff] [blame] | 192 | StatusBarIconView v = new StatusBarIconView(getContext(), null, null); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 193 | v.setTag(slot); |
| 194 | v.set(icon); |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 195 | v.setStaticDrawableColor(mColor); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 196 | addView(v, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize)); |
| 197 | } |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 198 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 199 | public void addDemoWifiView(WifiIconState state) { |
| 200 | Log.d(TAG, "addDemoWifiView: "); |
| 201 | StatusBarWifiView view = StatusBarWifiView.fromContext(mContext); |
| 202 | view.setSlot(state.slot); |
| 203 | |
| 204 | int viewIndex = getChildCount(); |
| 205 | // If we have mobile views, put wifi before them |
| 206 | for (int i = 0; i < getChildCount(); i++) { |
| 207 | View child = getChildAt(i); |
| 208 | if (child instanceof StatusBarMobileView) { |
| 209 | viewIndex = i; |
| 210 | break; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | mWifiView = view; |
| 215 | mWifiView.applyWifiState(state); |
| 216 | mWifiView.setStaticDrawableColor(mColor); |
| 217 | addView(view, viewIndex); |
| 218 | } |
| 219 | |
| 220 | public void updateWifiState(WifiIconState state) { |
| 221 | Log.d(TAG, "updateWifiState: "); |
| 222 | if (mWifiView == null) { |
| 223 | addDemoWifiView(state); |
| 224 | } else { |
| 225 | mWifiView.applyWifiState(state); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | public void addMobileView(MobileIconState state) { |
| 230 | Log.d(TAG, "addMobileView: "); |
| 231 | StatusBarMobileView view = StatusBarMobileView.fromContext(mContext); |
| 232 | |
| 233 | view.setSlot(state.slot); |
| 234 | view.applyMobileState(state); |
| 235 | view.setStaticDrawableColor(mColor); |
| 236 | |
| 237 | // mobile always goes at the end |
| 238 | mMobileViews.add(view); |
| 239 | addView(view, getChildCount()); |
| 240 | } |
| 241 | |
| 242 | public void updateMobileState(MobileIconState state) { |
| 243 | Log.d(TAG, "updateMobileState: "); |
| 244 | // If the view for this subId exists already, use it |
| 245 | for (int i = 0; i < mMobileViews.size(); i++) { |
| 246 | StatusBarMobileView view = mMobileViews.get(i); |
| 247 | if (view.getState().subId == state.subId) { |
| 248 | view.applyMobileState(state); |
| 249 | return; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Else we have to add it |
| 254 | addMobileView(state); |
| 255 | } |
| 256 | |
| 257 | public void onRemoveIcon(StatusIconDisplayable view) { |
| 258 | if (view.getSlot().equals("wifi")) { |
| 259 | removeView(mWifiView); |
| 260 | mWifiView = null; |
| 261 | } else { |
| 262 | StatusBarMobileView mobileView = matchingMobileView(view); |
| 263 | if (mobileView != null) { |
| 264 | removeView(mobileView); |
| 265 | mMobileViews.remove(mobileView); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | private StatusBarMobileView matchingMobileView(StatusIconDisplayable otherView) { |
| 271 | if (!(otherView instanceof StatusBarMobileView)) { |
| 272 | return null; |
| 273 | } |
| 274 | |
| 275 | StatusBarMobileView v = (StatusBarMobileView) otherView; |
| 276 | for (StatusBarMobileView view : mMobileViews) { |
| 277 | if (view.getState().subId == v.getState().subId) { |
| 278 | return view; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return null; |
| 283 | } |
| 284 | |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 285 | @Override |
| 286 | public void onDarkChanged(Rect area, float darkIntensity, int tint) { |
| 287 | setColor(DarkIconDispatcher.getTint(area, mStatusIcons, tint)); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 288 | |
| 289 | if (mWifiView != null) { |
| 290 | mWifiView.onDarkChanged(area, darkIntensity, tint); |
| 291 | } |
| 292 | for (StatusBarMobileView view : mMobileViews) { |
| 293 | view.onDarkChanged(area, darkIntensity, tint); |
| 294 | } |
Evan Laird | 937d9fa | 2018-02-08 10:12:16 -0800 | [diff] [blame] | 295 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 296 | } |