• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.widget.ImageView;
25 import android.widget.LinearLayout;
26 import android.widget.TextView;
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 String mWifiDescription, mMobileDescription, mMobileTypeDescription;
48 
49     ViewGroup mWifiGroup, mMobileGroup;
50     ImageView mWifi, mMobile, mWifiActivity, mMobileActivity, mMobileType;
51     View mSpacer;
52 
SignalClusterView(Context context)53     public SignalClusterView(Context context) {
54         this(context, null);
55     }
56 
SignalClusterView(Context context, AttributeSet attrs)57     public SignalClusterView(Context context, AttributeSet attrs) {
58         this(context, attrs, 0);
59     }
60 
SignalClusterView(Context context, AttributeSet attrs, int defStyle)61     public SignalClusterView(Context context, AttributeSet attrs, int defStyle) {
62         super(context, attrs, defStyle);
63     }
64 
setNetworkController(NetworkController nc)65     public void setNetworkController(NetworkController nc) {
66         if (DEBUG) Slog.d(TAG, "NetworkController=" + nc);
67         mNC = nc;
68     }
69 
70     @Override
onAttachedToWindow()71     protected void onAttachedToWindow() {
72         super.onAttachedToWindow();
73 
74         mWifiGroup      = (ViewGroup) findViewById(R.id.wifi_combo);
75         mWifi           = (ImageView) findViewById(R.id.wifi_signal);
76         mWifiActivity   = (ImageView) findViewById(R.id.wifi_inout);
77         mMobileGroup    = (ViewGroup) findViewById(R.id.mobile_combo);
78         mMobile         = (ImageView) findViewById(R.id.mobile_signal);
79         mMobileActivity = (ImageView) findViewById(R.id.mobile_inout);
80         mMobileType     = (ImageView) findViewById(R.id.mobile_type);
81         mSpacer         =             findViewById(R.id.spacer);
82 
83         apply();
84     }
85 
86     @Override
onDetachedFromWindow()87     protected void onDetachedFromWindow() {
88         mWifiGroup      = null;
89         mWifi           = null;
90         mWifiActivity   = null;
91         mMobileGroup    = null;
92         mMobile         = null;
93         mMobileActivity = null;
94         mMobileType     = null;
95 
96         super.onDetachedFromWindow();
97     }
98 
setWifiIndicators(boolean visible, int strengthIcon, int activityIcon, String contentDescription)99     public void setWifiIndicators(boolean visible, int strengthIcon, int activityIcon,
100             String contentDescription) {
101         mWifiVisible = visible;
102         mWifiStrengthId = strengthIcon;
103         mWifiActivityId = activityIcon;
104         mWifiDescription = contentDescription;
105 
106         apply();
107     }
108 
setMobileDataIndicators(boolean visible, int strengthIcon, int activityIcon, int typeIcon, String contentDescription, String typeContentDescription)109     public void setMobileDataIndicators(boolean visible, int strengthIcon, int activityIcon,
110             int typeIcon, String contentDescription, String typeContentDescription) {
111         mMobileVisible = visible;
112         mMobileStrengthId = strengthIcon;
113         mMobileActivityId = activityIcon;
114         mMobileTypeId = typeIcon;
115         mMobileDescription = contentDescription;
116         mMobileTypeDescription = typeContentDescription;
117 
118         apply();
119     }
120 
setIsAirplaneMode(boolean is)121     public void setIsAirplaneMode(boolean is) {
122         mIsAirplaneMode = is;
123     }
124 
125     // Run after each indicator change.
apply()126     private void apply() {
127         if (mWifiGroup == null) return;
128 
129         if (mWifiVisible) {
130             mWifiGroup.setVisibility(View.VISIBLE);
131             mWifi.setImageResource(mWifiStrengthId);
132             mWifiActivity.setImageResource(mWifiActivityId);
133             mWifiGroup.setContentDescription(mWifiDescription);
134         } else {
135             mWifiGroup.setVisibility(View.GONE);
136         }
137 
138         if (DEBUG) Slog.d(TAG,
139                 String.format("wifi: %s sig=%d act=%d",
140                     (mWifiVisible ? "VISIBLE" : "GONE"),
141                     mWifiStrengthId, mWifiActivityId));
142 
143         if (mMobileVisible) {
144             mMobileGroup.setVisibility(View.VISIBLE);
145             mMobile.setImageResource(mMobileStrengthId);
146             mMobileActivity.setImageResource(mMobileActivityId);
147             mMobileType.setImageResource(mMobileTypeId);
148             mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription);
149         } else {
150             mMobileGroup.setVisibility(View.GONE);
151         }
152 
153         if (mMobileVisible && mWifiVisible && mIsAirplaneMode) {
154             mSpacer.setVisibility(View.INVISIBLE);
155         } else {
156             mSpacer.setVisibility(View.GONE);
157         }
158 
159         if (DEBUG) Slog.d(TAG,
160                 String.format("mobile: %s sig=%d act=%d typ=%d",
161                     (mMobileVisible ? "VISIBLE" : "GONE"),
162                     mMobileStrengthId, mMobileActivityId, mMobileTypeId));
163 
164         mMobileType.setVisibility(
165                 !mWifiVisible ? View.VISIBLE : View.GONE);
166     }
167 }
168 
169