• 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.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 
SignalClusterView(Context context)54     public SignalClusterView(Context context) {
55         this(context, null);
56     }
57 
SignalClusterView(Context context, AttributeSet attrs)58     public SignalClusterView(Context context, AttributeSet attrs) {
59         this(context, attrs, 0);
60     }
61 
SignalClusterView(Context context, AttributeSet attrs, int defStyle)62     public SignalClusterView(Context context, AttributeSet attrs, int defStyle) {
63         super(context, attrs, defStyle);
64     }
65 
setNetworkController(NetworkController nc)66     public void setNetworkController(NetworkController nc) {
67         if (DEBUG) Slog.d(TAG, "NetworkController=" + nc);
68         mNC = nc;
69     }
70 
71     @Override
onAttachedToWindow()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
onDetachedFromWindow()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
setWifiIndicators(boolean visible, int strengthIcon, int activityIcon, String contentDescription)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
setMobileDataIndicators(boolean visible, int strengthIcon, int activityIcon, int typeIcon, String contentDescription, String typeContentDescription)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
setIsAirplaneMode(boolean is, int airplaneIconId)128     public void setIsAirplaneMode(boolean is, int airplaneIconId) {
129         mIsAirplaneMode = is;
130         mAirplaneIconId = airplaneIconId;
131 
132         apply();
133     }
134 
135     @Override
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)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     // Run after each indicator change.
apply()147     private void apply() {
148         if (mWifiGroup == null) return;
149 
150         if (mWifiVisible) {
151             mWifiGroup.setVisibility(View.VISIBLE);
152             mWifi.setImageResource(mWifiStrengthId);
153             mWifiActivity.setImageResource(mWifiActivityId);
154             mWifiGroup.setContentDescription(mWifiDescription);
155         } else {
156             mWifiGroup.setVisibility(View.GONE);
157         }
158 
159         if (DEBUG) Slog.d(TAG,
160                 String.format("wifi: %s sig=%d act=%d",
161                     (mWifiVisible ? "VISIBLE" : "GONE"),
162                     mWifiStrengthId, mWifiActivityId));
163 
164         if (mMobileVisible && !mIsAirplaneMode) {
165             mMobileGroup.setVisibility(View.VISIBLE);
166             mMobile.setImageResource(mMobileStrengthId);
167             mMobileActivity.setImageResource(mMobileActivityId);
168             mMobileType.setImageResource(mMobileTypeId);
169             mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription);
170         } else {
171             mMobileGroup.setVisibility(View.GONE);
172         }
173 
174         if (mIsAirplaneMode) {
175             mAirplane.setVisibility(View.VISIBLE);
176             mAirplane.setImageResource(mAirplaneIconId);
177         } else {
178             mAirplane.setVisibility(View.GONE);
179         }
180 
181         if (mMobileVisible && mWifiVisible && mIsAirplaneMode) {
182             mSpacer.setVisibility(View.INVISIBLE);
183         } else {
184             mSpacer.setVisibility(View.GONE);
185         }
186 
187         if (DEBUG) Slog.d(TAG,
188                 String.format("mobile: %s sig=%d act=%d typ=%d",
189                     (mMobileVisible ? "VISIBLE" : "GONE"),
190                     mMobileStrengthId, mMobileActivityId, mMobileTypeId));
191 
192         mMobileType.setVisibility(
193                 !mWifiVisible ? View.VISIBLE : View.GONE);
194     }
195 }
196 
197