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 19 import android.os.Bundle; 20 import android.os.UserHandle; 21 import android.view.Gravity; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.LinearLayout; 25 26 import com.android.internal.statusbar.StatusBarIcon; 27 import com.android.systemui.DemoMode; 28 import com.android.systemui.R; 29 import com.android.systemui.statusbar.StatusBarIconView; 30 import com.android.systemui.statusbar.policy.LocationController; 31 32 public class DemoStatusIcons extends LinearLayout implements DemoMode { 33 private final LinearLayout mStatusIcons; 34 private final int mIconSize; 35 36 private boolean mDemoMode; 37 38 public DemoStatusIcons(LinearLayout statusIcons, int iconSize) { 39 super(statusIcons.getContext()); 40 mStatusIcons = statusIcons; 41 mIconSize = iconSize; 42 43 setLayoutParams(mStatusIcons.getLayoutParams()); 44 setOrientation(mStatusIcons.getOrientation()); 45 setGravity(Gravity.CENTER_VERTICAL); // no LL.getGravity() 46 ViewGroup p = (ViewGroup) mStatusIcons.getParent(); 47 p.addView(this, p.indexOfChild(mStatusIcons)); 48 } 49 50 @Override 51 public void dispatchDemoCommand(String command, Bundle args) { 52 if (!mDemoMode && command.equals(COMMAND_ENTER)) { 53 mDemoMode = true; 54 mStatusIcons.setVisibility(View.GONE); 55 setVisibility(View.VISIBLE); 56 } else if (mDemoMode && command.equals(COMMAND_EXIT)) { 57 mDemoMode = false; 58 mStatusIcons.setVisibility(View.VISIBLE); 59 setVisibility(View.GONE); 60 } else if (mDemoMode && command.equals(COMMAND_STATUS)) { 61 String volume = args.getString("volume"); 62 if (volume != null) { 63 int iconId = volume.equals("silent") ? R.drawable.stat_sys_ringer_silent 64 : volume.equals("vibrate") ? R.drawable.stat_sys_ringer_vibrate 65 : 0; 66 updateSlot("volume", null, iconId); 67 } 68 String bt = args.getString("bluetooth"); 69 if (bt != null) { 70 int iconId = bt.equals("disconnected") ? R.drawable.stat_sys_data_bluetooth 71 : bt.equals("connected") ? R.drawable.stat_sys_data_bluetooth_connected 72 : 0; 73 updateSlot("bluetooth", null, iconId); 74 } 75 String location = args.getString("location"); 76 if (location != null) { 77 int iconId = location.equals("show") ? LocationController.LOCATION_STATUS_ICON_ID 78 : 0; 79 updateSlot(LocationController.LOCATION_STATUS_ICON_PLACEHOLDER, null, iconId); 80 } 81 String alarm = args.getString("alarm"); 82 if (alarm != null) { 83 int iconId = alarm.equals("show") ? R.drawable.stat_sys_alarm 84 : 0; 85 updateSlot("alarm_clock", null, iconId); 86 } 87 String sync = args.getString("sync"); 88 if (sync != null) { 89 int iconId = sync.equals("show") ? R.drawable.stat_sys_sync 90 : 0; 91 updateSlot("sync_active", null, iconId); 92 } 93 String tty = args.getString("tty"); 94 if (tty != null) { 95 int iconId = tty.equals("show") ? R.drawable.stat_sys_tty_mode 96 : 0; 97 updateSlot("tty", null, iconId); 98 } 99 String eri = args.getString("eri"); 100 if (eri != null) { 101 int iconId = eri.equals("show") ? R.drawable.stat_sys_roaming_cdma_0 102 : 0; 103 updateSlot("cdma_eri", null, iconId); 104 } 105 String mute = args.getString("mute"); 106 if (mute != null) { 107 int iconId = mute.equals("show") ? android.R.drawable.stat_notify_call_mute 108 : 0; 109 updateSlot("mute", null, iconId); 110 } 111 String speakerphone = args.getString("speakerphone"); 112 if (speakerphone != null) { 113 int iconId = speakerphone.equals("show") ? android.R.drawable.stat_sys_speakerphone 114 : 0; 115 updateSlot("speakerphone", null, iconId); 116 } 117 } 118 } 119 120 private void updateSlot(String slot, String iconPkg, int iconId) { 121 if (!mDemoMode) return; 122 int removeIndex = -1; 123 for (int i = 0; i < getChildCount(); i++) { 124 StatusBarIconView v = (StatusBarIconView) getChildAt(i); 125 if (slot.equals(v.getTag())) { 126 if (iconId == 0) { 127 removeIndex = i; 128 break; 129 } else { 130 StatusBarIcon icon = v.getStatusBarIcon(); 131 icon.iconPackage = iconPkg; 132 icon.iconId = iconId; 133 v.set(icon); 134 v.updateDrawable(); 135 return; 136 } 137 } 138 } 139 if (iconId == 0) { 140 if (removeIndex != -1) { 141 removeViewAt(removeIndex); 142 return; 143 } 144 } 145 StatusBarIcon icon = new StatusBarIcon(iconPkg, UserHandle.CURRENT, iconId, 0, 0, "Demo"); 146 StatusBarIconView v = new StatusBarIconView(mContext, null); 147 v.setTag(slot); 148 v.set(icon); 149 addView(v, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize)); 150 } 151 }