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