Home | History | Annotate | Download | only in phone
      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.LocationControllerImpl;
     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("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("cast") ? R.drawable.stat_sys_cast : 0;
    126                 updateSlot("cast", null, iconId);
    127             }
    128         }
    129     }
    130 
    131     private void updateSlot(String slot, String iconPkg, int iconId) {
    132         if (!mDemoMode) return;
    133         int removeIndex = -1;
    134         for (int i = 0; i < getChildCount(); i++) {
    135             StatusBarIconView v = (StatusBarIconView) getChildAt(i);
    136             if (slot.equals(v.getTag())) {
    137                 if (iconId == 0) {
    138                     removeIndex = i;
    139                     break;
    140                 } else {
    141                     StatusBarIcon icon = v.getStatusBarIcon();
    142                     icon.iconPackage = iconPkg;
    143                     icon.iconId = iconId;
    144                     v.set(icon);
    145                     v.updateDrawable();
    146                     return;
    147                 }
    148             }
    149         }
    150         if (iconId == 0) {
    151             if (removeIndex != -1) {
    152                 removeViewAt(removeIndex);
    153                 return;
    154             }
    155         }
    156         StatusBarIcon icon = new StatusBarIcon(iconPkg, UserHandle.CURRENT, iconId, 0, 0, "Demo");
    157         StatusBarIconView v = new StatusBarIconView(getContext(), null);
    158         v.setTag(slot);
    159         v.set(icon);
    160         addView(v, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize));
    161     }
    162 }