blob: f17b143e343d75a9e71de8ec3b38701bc454c4fc [file] [log] [blame]
Christian Robertson2e347422011-08-11 14:01:04 -07001/*
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
17package com.android.systemui.statusbar;
18
19import android.content.Context;
20import android.util.AttributeSet;
John Spurlockcd686b52013-06-05 10:13:46 -040021import android.util.Log;
Christian Robertson2e347422011-08-11 14:01:04 -070022import android.view.View;
23import android.view.ViewGroup;
John Spurlock2f7dfa72012-05-16 20:20:59 -040024import android.view.accessibility.AccessibilityEvent;
Christian Robertson2e347422011-08-11 14:01:04 -070025import android.widget.ImageView;
26import android.widget.LinearLayout;
Christian Robertson2e347422011-08-11 14:01:04 -070027
Christian Robertson2e347422011-08-11 14:01:04 -070028import com.android.systemui.R;
John Spurlockde84f0e2013-06-12 12:41:00 -040029import com.android.systemui.statusbar.policy.NetworkController;
Christian Robertson2e347422011-08-11 14:01:04 -070030
Daniel Sandler5ccff812011-09-13 15:17:58 -040031// Intimately tied to the design of res/layout/signal_cluster_view.xml
Christian Robertson2e347422011-08-11 14:01:04 -070032public class SignalClusterView
John Spurlock2f7dfa72012-05-16 20:20:59 -040033 extends LinearLayout
Christian Robertson2e347422011-08-11 14:01:04 -070034 implements NetworkController.SignalCluster {
35
Daniel Sandler28f89d42011-08-15 14:04:15 -040036 static final boolean DEBUG = false;
37 static final String TAG = "SignalClusterView";
John Spurlock2f7dfa72012-05-16 20:20:59 -040038
Christian Robertson2e347422011-08-11 14:01:04 -070039 NetworkController mNC;
40
Daniel Sandler28f89d42011-08-15 14:04:15 -040041 private boolean mWifiVisible = false;
42 private int mWifiStrengthId = 0, mWifiActivityId = 0;
43 private boolean mMobileVisible = false;
44 private int mMobileStrengthId = 0, mMobileActivityId = 0, mMobileTypeId = 0;
Daniel Sandler5ccff812011-09-13 15:17:58 -040045 private boolean mIsAirplaneMode = false;
Andrew Flynn061d43c2012-05-04 10:57:58 -070046 private int mAirplaneIconId = 0;
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -040047 private String mWifiDescription, mMobileDescription, mMobileTypeDescription;
Daniel Sandler28f89d42011-08-15 14:04:15 -040048
Christian Robertson2e347422011-08-11 14:01:04 -070049 ViewGroup mWifiGroup, mMobileGroup;
Andrew Flynn061d43c2012-05-04 10:57:58 -070050 ImageView mWifi, mMobile, mWifiActivity, mMobileActivity, mMobileType, mAirplane;
Daniel Sandler5ccff812011-09-13 15:17:58 -040051 View mSpacer;
Christian Robertson2e347422011-08-11 14:01:04 -070052
53 public SignalClusterView(Context context) {
54 this(context, null);
55 }
56
57 public SignalClusterView(Context context, AttributeSet attrs) {
58 this(context, attrs, 0);
59 }
60
61 public SignalClusterView(Context context, AttributeSet attrs, int defStyle) {
62 super(context, attrs, defStyle);
63 }
64
65 public void setNetworkController(NetworkController nc) {
John Spurlockcd686b52013-06-05 10:13:46 -040066 if (DEBUG) Log.d(TAG, "NetworkController=" + nc);
Christian Robertson2e347422011-08-11 14:01:04 -070067 mNC = nc;
68 }
69
70 @Override
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);
Daniel Sandler5ccff812011-09-13 15:17:58 -040081 mSpacer = findViewById(R.id.spacer);
Andrew Flynn061d43c2012-05-04 10:57:58 -070082 mAirplane = (ImageView) findViewById(R.id.airplane);
Daniel Sandler28f89d42011-08-15 14:04:15 -040083
84 apply();
Christian Robertson2e347422011-08-11 14:01:04 -070085 }
86
87 @Override
88 protected void onDetachedFromWindow() {
Daniel Sandler28f89d42011-08-15 14:04:15 -040089 mWifiGroup = null;
90 mWifi = null;
91 mWifiActivity = null;
92 mMobileGroup = null;
93 mMobile = null;
94 mMobileActivity = null;
95 mMobileType = null;
Andrew Flynn061d43c2012-05-04 10:57:58 -070096 mSpacer = null;
97 mAirplane = null;
Daniel Sandler28f89d42011-08-15 14:04:15 -040098
Christian Robertson2e347422011-08-11 14:01:04 -070099 super.onDetachedFromWindow();
100 }
101
Andrew Flynn061d43c2012-05-04 10:57:58 -0700102 @Override
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400103 public void setWifiIndicators(boolean visible, int strengthIcon, int activityIcon,
104 String contentDescription) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400105 mWifiVisible = visible;
106 mWifiStrengthId = strengthIcon;
107 mWifiActivityId = activityIcon;
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400108 mWifiDescription = contentDescription;
Christian Robertson2e347422011-08-11 14:01:04 -0700109
Daniel Sandler28f89d42011-08-15 14:04:15 -0400110 apply();
Christian Robertson2e347422011-08-11 14:01:04 -0700111 }
112
Andrew Flynn061d43c2012-05-04 10:57:58 -0700113 @Override
Christian Robertson2e347422011-08-11 14:01:04 -0700114 public void setMobileDataIndicators(boolean visible, int strengthIcon, int activityIcon,
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400115 int typeIcon, String contentDescription, String typeContentDescription) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400116 mMobileVisible = visible;
117 mMobileStrengthId = strengthIcon;
118 mMobileActivityId = activityIcon;
119 mMobileTypeId = typeIcon;
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400120 mMobileDescription = contentDescription;
121 mMobileTypeDescription = typeContentDescription;
Christian Robertson2e347422011-08-11 14:01:04 -0700122
Daniel Sandler28f89d42011-08-15 14:04:15 -0400123 apply();
124 }
125
Andrew Flynn061d43c2012-05-04 10:57:58 -0700126 @Override
127 public void setIsAirplaneMode(boolean is, int airplaneIconId) {
Daniel Sandler5ccff812011-09-13 15:17:58 -0400128 mIsAirplaneMode = is;
Andrew Flynn061d43c2012-05-04 10:57:58 -0700129 mAirplaneIconId = airplaneIconId;
130
131 apply();
Daniel Sandler5ccff812011-09-13 15:17:58 -0400132 }
133
John Spurlock2f7dfa72012-05-16 20:20:59 -0400134 @Override
135 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
136 // Standard group layout onPopulateAccessibilityEvent() implementations
137 // ignore content description, so populate manually
138 if (mWifiVisible && mWifiGroup.getContentDescription() != null)
139 event.getText().add(mWifiGroup.getContentDescription());
140 if (mMobileVisible && mMobileGroup.getContentDescription() != null)
141 event.getText().add(mMobileGroup.getContentDescription());
142 return super.dispatchPopulateAccessibilityEvent(event);
143 }
144
Fabrice Di Meglio46626112013-05-07 11:32:51 -0700145 @Override
146 public void onRtlPropertiesChanged(int layoutDirection) {
147 super.onRtlPropertiesChanged(layoutDirection);
148
149 if (mWifi != null) {
150 mWifi.setImageDrawable(null);
151 }
152 if (mWifiActivity != null) {
153 mWifiActivity.setImageDrawable(null);
154 }
155
156 if (mMobile != null) {
157 mMobile.setImageDrawable(null);
158 }
159 if (mMobileActivity != null) {
160 mMobileActivity.setImageDrawable(null);
161 }
162 if (mMobileType != null) {
163 mMobileType.setImageDrawable(null);
164 }
165
166 if(mAirplane != null) {
167 mAirplane.setImageDrawable(null);
168 }
169
170 apply();
171 }
172
Daniel Sandler28f89d42011-08-15 14:04:15 -0400173 // Run after each indicator change.
174 private void apply() {
175 if (mWifiGroup == null) return;
176
177 if (mWifiVisible) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400178 mWifi.setImageResource(mWifiStrengthId);
179 mWifiActivity.setImageResource(mWifiActivityId);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800180
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400181 mWifiGroup.setContentDescription(mWifiDescription);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800182 mWifiGroup.setVisibility(View.VISIBLE);
Daniel Sandler28f89d42011-08-15 14:04:15 -0400183 } else {
184 mWifiGroup.setVisibility(View.GONE);
185 }
186
John Spurlockcd686b52013-06-05 10:13:46 -0400187 if (DEBUG) Log.d(TAG,
Daniel Sandler28f89d42011-08-15 14:04:15 -0400188 String.format("wifi: %s sig=%d act=%d",
189 (mWifiVisible ? "VISIBLE" : "GONE"),
190 mWifiStrengthId, mWifiActivityId));
191
Andrew Flynn061d43c2012-05-04 10:57:58 -0700192 if (mMobileVisible && !mIsAirplaneMode) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400193 mMobile.setImageResource(mMobileStrengthId);
194 mMobileActivity.setImageResource(mMobileActivityId);
195 mMobileType.setImageResource(mMobileTypeId);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800196
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400197 mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800198 mMobileGroup.setVisibility(View.VISIBLE);
Christian Robertson2e347422011-08-11 14:01:04 -0700199 } else {
200 mMobileGroup.setVisibility(View.GONE);
201 }
Daniel Sandler28f89d42011-08-15 14:04:15 -0400202
Andrew Flynn061d43c2012-05-04 10:57:58 -0700203 if (mIsAirplaneMode) {
Andrew Flynn061d43c2012-05-04 10:57:58 -0700204 mAirplane.setImageResource(mAirplaneIconId);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700205 mAirplane.setVisibility(View.VISIBLE);
Andrew Flynn061d43c2012-05-04 10:57:58 -0700206 } else {
207 mAirplane.setVisibility(View.GONE);
208 }
209
Daniel Sandler5ccff812011-09-13 15:17:58 -0400210 if (mMobileVisible && mWifiVisible && mIsAirplaneMode) {
211 mSpacer.setVisibility(View.INVISIBLE);
212 } else {
213 mSpacer.setVisibility(View.GONE);
214 }
215
John Spurlockcd686b52013-06-05 10:13:46 -0400216 if (DEBUG) Log.d(TAG,
Daniel Sandler28f89d42011-08-15 14:04:15 -0400217 String.format("mobile: %s sig=%d act=%d typ=%d",
218 (mMobileVisible ? "VISIBLE" : "GONE"),
219 mMobileStrengthId, mMobileActivityId, mMobileTypeId));
220
221 mMobileType.setVisibility(
222 !mWifiVisible ? View.VISIBLE : View.GONE);
Christian Robertson2e347422011-08-11 14:01:04 -0700223 }
224}
225