Home | History | Annotate | Download | only in statusbar
      1 /*
      2  * Copyright (C) 2011 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;
     18 
     19 import android.content.Context;
     20 import android.util.AttributeSet;
     21 import android.util.Slog;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.view.accessibility.AccessibilityEvent;
     25 import android.widget.ImageView;
     26 import android.widget.LinearLayout;
     27 
     28 import com.android.systemui.statusbar.policy.NetworkController;
     29 
     30 import com.android.systemui.R;
     31 
     32 // Intimately tied to the design of res/layout/signal_cluster_view.xml
     33 public class SignalClusterView
     34         extends LinearLayout
     35         implements NetworkController.SignalCluster {
     36 
     37     static final boolean DEBUG = false;
     38     static final String TAG = "SignalClusterView";
     39 
     40     NetworkController mNC;
     41 
     42     private boolean mWifiVisible = false;
     43     private int mWifiStrengthId = 0, mWifiActivityId = 0;
     44     private boolean mMobileVisible = false;
     45     private int mMobileStrengthId = 0, mMobileActivityId = 0, mMobileTypeId = 0;
     46     private boolean mIsAirplaneMode = false;
     47     private int mAirplaneIconId = 0;
     48     private String mWifiDescription, mMobileDescription, mMobileTypeDescription;
     49 
     50     ViewGroup mWifiGroup, mMobileGroup;
     51     ImageView mWifi, mMobile, mWifiActivity, mMobileActivity, mMobileType, mAirplane;
     52     View mSpacer;
     53 
     54     public SignalClusterView(Context context) {
     55         this(context, null);
     56     }
     57 
     58     public SignalClusterView(Context context, AttributeSet attrs) {
     59         this(context, attrs, 0);
     60     }
     61 
     62     public SignalClusterView(Context context, AttributeSet attrs, int defStyle) {
     63         super(context, attrs, defStyle);
     64     }
     65 
     66     public void setNetworkController(NetworkController nc) {
     67         if (DEBUG) Slog.d(TAG, "NetworkController=" + nc);
     68         mNC = nc;
     69     }
     70 
     71     @Override
     72     protected void onAttachedToWindow() {
     73         super.onAttachedToWindow();
     74 
     75         mWifiGroup      = (ViewGroup) findViewById(R.id.wifi_combo);
     76         mWifi           = (ImageView) findViewById(R.id.wifi_signal);
     77         mWifiActivity   = (ImageView) findViewById(R.id.wifi_inout);
     78         mMobileGroup    = (ViewGroup) findViewById(R.id.mobile_combo);
     79         mMobile         = (ImageView) findViewById(R.id.mobile_signal);
     80         mMobileActivity = (ImageView) findViewById(R.id.mobile_inout);
     81         mMobileType     = (ImageView) findViewById(R.id.mobile_type);
     82         mSpacer         =             findViewById(R.id.spacer);
     83         mAirplane       = (ImageView) findViewById(R.id.airplane);
     84 
     85         apply();
     86     }
     87 
     88     @Override
     89     protected void onDetachedFromWindow() {
     90         mWifiGroup      = null;
     91         mWifi           = null;
     92         mWifiActivity   = null;
     93         mMobileGroup    = null;
     94         mMobile         = null;
     95         mMobileActivity = null;
     96         mMobileType     = null;
     97         mSpacer         = null;
     98         mAirplane       = null;
     99 
    100         super.onDetachedFromWindow();
    101     }
    102 
    103     @Override
    104     public void setWifiIndicators(boolean visible, int strengthIcon, int activityIcon,
    105             String contentDescription) {
    106         mWifiVisible = visible;
    107         mWifiStrengthId = strengthIcon;
    108         mWifiActivityId = activityIcon;
    109         mWifiDescription = contentDescription;
    110 
    111         apply();
    112     }
    113 
    114     @Override
    115     public void setMobileDataIndicators(boolean visible, int strengthIcon, int activityIcon,
    116             int typeIcon, String contentDescription, String typeContentDescription) {
    117         mMobileVisible = visible;
    118         mMobileStrengthId = strengthIcon;
    119         mMobileActivityId = activityIcon;
    120         mMobileTypeId = typeIcon;
    121         mMobileDescription = contentDescription;
    122         mMobileTypeDescription = typeContentDescription;
    123 
    124         apply();
    125     }
    126 
    127     @Override
    128     public void setIsAirplaneMode(boolean is, int airplaneIconId) {
    129         mIsAirplaneMode = is;
    130         mAirplaneIconId = airplaneIconId;
    131 
    132         apply();
    133     }
    134 
    135     @Override
    136     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    137         // Standard group layout onPopulateAccessibilityEvent() implementations
    138         // ignore content description, so populate manually
    139         if (mWifiVisible && mWifiGroup.getContentDescription() != null)
    140             event.getText().add(mWifiGroup.getContentDescription());
    141         if (mMobileVisible && mMobileGroup.getContentDescription() != null)
    142             event.getText().add(mMobileGroup.getContentDescription());
    143         return super.dispatchPopulateAccessibilityEvent(event);
    144     }
    145 
    146     @Override
    147     public void onRtlPropertiesChanged(int layoutDirection) {
    148         super.onRtlPropertiesChanged(layoutDirection);
    149 
    150         if (mWifi != null) {
    151             mWifi.setImageDrawable(null);
    152         }
    153         if (mWifiActivity != null) {
    154             mWifiActivity.setImageDrawable(null);
    155         }
    156 
    157         if (mMobile != null) {
    158             mMobile.setImageDrawable(null);
    159         }
    160         if (mMobileActivity != null) {
    161             mMobileActivity.setImageDrawable(null);
    162         }
    163         if (mMobileType != null) {
    164             mMobileType.setImageDrawable(null);
    165         }
    166 
    167         if(mAirplane != null) {
    168             mAirplane.setImageDrawable(null);
    169         }
    170 
    171         apply();
    172     }
    173 
    174     // Run after each indicator change.
    175     private void apply() {
    176         if (mWifiGroup == null) return;
    177 
    178         if (mWifiVisible) {
    179             mWifi.setImageResource(mWifiStrengthId);
    180             mWifiActivity.setImageResource(mWifiActivityId);
    181 
    182             mWifiGroup.setContentDescription(mWifiDescription);
    183             mWifiGroup.setVisibility(View.VISIBLE);
    184         } else {
    185             mWifiGroup.setVisibility(View.GONE);
    186         }
    187 
    188         if (DEBUG) Slog.d(TAG,
    189                 String.format("wifi: %s sig=%d act=%d",
    190                     (mWifiVisible ? "VISIBLE" : "GONE"),
    191                     mWifiStrengthId, mWifiActivityId));
    192 
    193         if (mMobileVisible && !mIsAirplaneMode) {
    194             mMobile.setImageResource(mMobileStrengthId);
    195             mMobileActivity.setImageResource(mMobileActivityId);
    196             mMobileType.setImageResource(mMobileTypeId);
    197 
    198             mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription);
    199             mMobileGroup.setVisibility(View.VISIBLE);
    200         } else {
    201             mMobileGroup.setVisibility(View.GONE);
    202         }
    203 
    204         if (mIsAirplaneMode) {
    205             mAirplane.setImageResource(mAirplaneIconId);
    206             mAirplane.setVisibility(View.VISIBLE);
    207         } else {
    208             mAirplane.setVisibility(View.GONE);
    209         }
    210 
    211         if (mMobileVisible && mWifiVisible && mIsAirplaneMode) {
    212             mSpacer.setVisibility(View.INVISIBLE);
    213         } else {
    214             mSpacer.setVisibility(View.GONE);
    215         }
    216 
    217         if (DEBUG) Slog.d(TAG,
    218                 String.format("mobile: %s sig=%d act=%d typ=%d",
    219                     (mMobileVisible ? "VISIBLE" : "GONE"),
    220                     mMobileStrengthId, mMobileActivityId, mMobileTypeId));
    221 
    222         mMobileType.setVisibility(
    223                 !mWifiVisible ? View.VISIBLE : View.GONE);
    224     }
    225 }
    226 
    227