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