DemoStatusIcons.java revision fd9aa5ff037f3037ccd4e1623ecc94eb1b43e6c4
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
17package com.android.systemui.statusbar.phone;
18
19import android.os.Bundle;
20import android.os.UserHandle;
21import android.view.Gravity;
22import android.view.View;
23import android.view.ViewGroup;
24import android.widget.LinearLayout;
25
26import com.android.internal.statusbar.StatusBarIcon;
27import com.android.systemui.DemoMode;
28import com.android.systemui.R;
29import com.android.systemui.statusbar.StatusBarIconView;
30import com.android.systemui.statusbar.policy.LocationControllerImpl;
31
32public 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("vibrate") ? R.drawable.stat_sys_ringer_vibrate
64                        : 0;
65                updateSlot("volume", null, iconId);
66            }
67            String zen = args.getString("zen");
68            if (zen != null) {
69                int iconId = zen.equals("important") ? R.drawable.stat_sys_zen_important
70                        : zen.equals("none") ? R.drawable.stat_sys_zen_none
71                        : 0;
72                updateSlot("zen", null, iconId);
73            }
74            String bt = args.getString("bluetooth");
75            if (bt != null) {
76                int iconId = bt.equals("disconnected") ? R.drawable.stat_sys_data_bluetooth
77                        : bt.equals("connected") ? R.drawable.stat_sys_data_bluetooth_connected
78                        : 0;
79                updateSlot("bluetooth", null, iconId);
80            }
81            String location = args.getString("location");
82            if (location != null) {
83                int iconId = location.equals("show") ? LocationControllerImpl.LOCATION_STATUS_ICON_ID
84                        : 0;
85                updateSlot(LocationControllerImpl.LOCATION_STATUS_ICON_PLACEHOLDER, null, iconId);
86            }
87            String alarm = args.getString("alarm");
88            if (alarm != null) {
89                int iconId = alarm.equals("show") ? R.drawable.stat_sys_alarm
90                        : 0;
91                updateSlot("alarm_clock", null, iconId);
92            }
93            String sync = args.getString("sync");
94            if (sync != null) {
95                int iconId = sync.equals("show") ? R.drawable.stat_sys_sync
96                        : 0;
97                updateSlot("sync_active", null, iconId);
98            }
99            String tty = args.getString("tty");
100            if (tty != null) {
101                int iconId = tty.equals("show") ? R.drawable.stat_sys_tty_mode
102                        : 0;
103                updateSlot("tty", null, iconId);
104            }
105            String eri = args.getString("eri");
106            if (eri != null) {
107                int iconId = eri.equals("show") ? R.drawable.stat_sys_roaming_cdma_0
108                        : 0;
109                updateSlot("cdma_eri", null, iconId);
110            }
111            String mute = args.getString("mute");
112            if (mute != null) {
113                int iconId = mute.equals("show") ? android.R.drawable.stat_notify_call_mute
114                        : 0;
115                updateSlot("mute", null, iconId);
116            }
117            String speakerphone = args.getString("speakerphone");
118            if (speakerphone != null) {
119                int iconId = speakerphone.equals("show") ? android.R.drawable.stat_sys_speakerphone
120                        : 0;
121                updateSlot("speakerphone", null, iconId);
122            }
123            String cast = args.getString("cast");
124            if (cast != null) {
125                int iconId = cast.equals("show") ? R.drawable.stat_sys_cast : 0;
126                updateSlot("cast", null, iconId);
127            }
128            String hotspot = args.getString("hotspot");
129            if (hotspot != null) {
130                int iconId = hotspot.equals("show") ? R.drawable.stat_sys_hotspot : 0;
131                updateSlot("hotspot", null, iconId);
132            }
133        }
134    }
135
136    private void updateSlot(String slot, String iconPkg, int iconId) {
137        if (!mDemoMode) return;
138        int removeIndex = -1;
139        for (int i = 0; i < getChildCount(); i++) {
140            StatusBarIconView v = (StatusBarIconView) getChildAt(i);
141            if (slot.equals(v.getTag())) {
142                if (iconId == 0) {
143                    removeIndex = i;
144                    break;
145                } else {
146                    StatusBarIcon icon = v.getStatusBarIcon();
147                    icon.iconPackage = iconPkg;
148                    icon.iconId = iconId;
149                    v.set(icon);
150                    v.updateDrawable();
151                    return;
152                }
153            }
154        }
155        if (iconId == 0) {
156            if (removeIndex != -1) {
157                removeViewAt(removeIndex);
158                return;
159            }
160        }
161        StatusBarIcon icon = new StatusBarIcon(iconPkg, UserHandle.CURRENT, iconId, 0, 0, "Demo");
162        StatusBarIconView v = new StatusBarIconView(getContext(), null, null);
163        v.setTag(slot);
164        v.set(icon);
165        addView(v, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize));
166    }
167}