blob: 46916f7175445eccb226e217cea8b9335969840a [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;
Daniel Sandler28f89d42011-08-15 14:04:15 -040021import android.util.Slog;
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
28import com.android.systemui.statusbar.policy.NetworkController;
29
30import com.android.systemui.R;
31
Daniel Sandler5ccff812011-09-13 15:17:58 -040032// Intimately tied to the design of res/layout/signal_cluster_view.xml
Christian Robertson2e347422011-08-11 14:01:04 -070033public class SignalClusterView
John Spurlock2f7dfa72012-05-16 20:20:59 -040034 extends LinearLayout
Christian Robertson2e347422011-08-11 14:01:04 -070035 implements NetworkController.SignalCluster {
36
Daniel Sandler28f89d42011-08-15 14:04:15 -040037 static final boolean DEBUG = false;
38 static final String TAG = "SignalClusterView";
John Spurlock2f7dfa72012-05-16 20:20:59 -040039
Christian Robertson2e347422011-08-11 14:01:04 -070040 NetworkController mNC;
41
Daniel Sandler28f89d42011-08-15 14:04:15 -040042 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;
Daniel Sandler5ccff812011-09-13 15:17:58 -040046 private boolean mIsAirplaneMode = false;
Andrew Flynn061d43c2012-05-04 10:57:58 -070047 private int mAirplaneIconId = 0;
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -040048 private String mWifiDescription, mMobileDescription, mMobileTypeDescription;
Daniel Sandler28f89d42011-08-15 14:04:15 -040049
Christian Robertson2e347422011-08-11 14:01:04 -070050 ViewGroup mWifiGroup, mMobileGroup;
Andrew Flynn061d43c2012-05-04 10:57:58 -070051 ImageView mWifi, mMobile, mWifiActivity, mMobileActivity, mMobileType, mAirplane;
Daniel Sandler5ccff812011-09-13 15:17:58 -040052 View mSpacer;
Christian Robertson2e347422011-08-11 14:01:04 -070053
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) {
Daniel Sandler28f89d42011-08-15 14:04:15 -040067 if (DEBUG) Slog.d(TAG, "NetworkController=" + nc);
Christian Robertson2e347422011-08-11 14:01:04 -070068 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);
Daniel Sandler5ccff812011-09-13 15:17:58 -040082 mSpacer = findViewById(R.id.spacer);
Andrew Flynn061d43c2012-05-04 10:57:58 -070083 mAirplane = (ImageView) findViewById(R.id.airplane);
Daniel Sandler28f89d42011-08-15 14:04:15 -040084
85 apply();
Christian Robertson2e347422011-08-11 14:01:04 -070086 }
87
88 @Override
89 protected void onDetachedFromWindow() {
Daniel Sandler28f89d42011-08-15 14:04:15 -040090 mWifiGroup = null;
91 mWifi = null;
92 mWifiActivity = null;
93 mMobileGroup = null;
94 mMobile = null;
95 mMobileActivity = null;
96 mMobileType = null;
Andrew Flynn061d43c2012-05-04 10:57:58 -070097 mSpacer = null;
98 mAirplane = null;
Daniel Sandler28f89d42011-08-15 14:04:15 -040099
Christian Robertson2e347422011-08-11 14:01:04 -0700100 super.onDetachedFromWindow();
101 }
102
Andrew Flynn061d43c2012-05-04 10:57:58 -0700103 @Override
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400104 public void setWifiIndicators(boolean visible, int strengthIcon, int activityIcon,
105 String contentDescription) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400106 mWifiVisible = visible;
107 mWifiStrengthId = strengthIcon;
108 mWifiActivityId = activityIcon;
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400109 mWifiDescription = contentDescription;
Christian Robertson2e347422011-08-11 14:01:04 -0700110
Daniel Sandler28f89d42011-08-15 14:04:15 -0400111 apply();
Christian Robertson2e347422011-08-11 14:01:04 -0700112 }
113
Andrew Flynn061d43c2012-05-04 10:57:58 -0700114 @Override
Christian Robertson2e347422011-08-11 14:01:04 -0700115 public void setMobileDataIndicators(boolean visible, int strengthIcon, int activityIcon,
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400116 int typeIcon, String contentDescription, String typeContentDescription) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400117 mMobileVisible = visible;
118 mMobileStrengthId = strengthIcon;
119 mMobileActivityId = activityIcon;
120 mMobileTypeId = typeIcon;
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400121 mMobileDescription = contentDescription;
122 mMobileTypeDescription = typeContentDescription;
Christian Robertson2e347422011-08-11 14:01:04 -0700123
Daniel Sandler28f89d42011-08-15 14:04:15 -0400124 apply();
125 }
126
Andrew Flynn061d43c2012-05-04 10:57:58 -0700127 @Override
128 public void setIsAirplaneMode(boolean is, int airplaneIconId) {
Daniel Sandler5ccff812011-09-13 15:17:58 -0400129 mIsAirplaneMode = is;
Andrew Flynn061d43c2012-05-04 10:57:58 -0700130 mAirplaneIconId = airplaneIconId;
131
132 apply();
Daniel Sandler5ccff812011-09-13 15:17:58 -0400133 }
134
John Spurlock2f7dfa72012-05-16 20:20:59 -0400135 @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
Fabrice Di Meglio46626112013-05-07 11:32:51 -0700146 @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
Daniel Sandler28f89d42011-08-15 14:04:15 -0400174 // Run after each indicator change.
175 private void apply() {
176 if (mWifiGroup == null) return;
177
178 if (mWifiVisible) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400179 mWifi.setImageResource(mWifiStrengthId);
180 mWifiActivity.setImageResource(mWifiActivityId);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800181
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400182 mWifiGroup.setContentDescription(mWifiDescription);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800183 mWifiGroup.setVisibility(View.VISIBLE);
Daniel Sandler28f89d42011-08-15 14:04:15 -0400184 } 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
Andrew Flynn061d43c2012-05-04 10:57:58 -0700193 if (mMobileVisible && !mIsAirplaneMode) {
Daniel Sandler28f89d42011-08-15 14:04:15 -0400194 mMobile.setImageResource(mMobileStrengthId);
195 mMobileActivity.setImageResource(mMobileActivityId);
196 mMobileType.setImageResource(mMobileTypeId);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800197
Daniel Sandlerbcf6ef0b2011-09-30 11:43:36 -0400198 mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription);
Fabrice Di Megliocda096e2012-12-26 17:11:13 -0800199 mMobileGroup.setVisibility(View.VISIBLE);
Christian Robertson2e347422011-08-11 14:01:04 -0700200 } else {
201 mMobileGroup.setVisibility(View.GONE);
202 }
Daniel Sandler28f89d42011-08-15 14:04:15 -0400203
Andrew Flynn061d43c2012-05-04 10:57:58 -0700204 if (mIsAirplaneMode) {
Andrew Flynn061d43c2012-05-04 10:57:58 -0700205 mAirplane.setImageResource(mAirplaneIconId);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700206 mAirplane.setVisibility(View.VISIBLE);
Andrew Flynn061d43c2012-05-04 10:57:58 -0700207 } else {
208 mAirplane.setVisibility(View.GONE);
209 }
210
Daniel Sandler5ccff812011-09-13 15:17:58 -0400211 if (mMobileVisible && mWifiVisible && mIsAirplaneMode) {
212 mSpacer.setVisibility(View.INVISIBLE);
213 } else {
214 mSpacer.setVisibility(View.GONE);
215 }
216
Daniel Sandler28f89d42011-08-15 14:04:15 -0400217 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);
Christian Robertson2e347422011-08-11 14:01:04 -0700224 }
225}
226