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.Log; 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.R; 29 import com.android.systemui.statusbar.policy.NetworkController; 30 31 // Intimately tied to the design of res/layout/signal_cluster_view.xml 32 public class SignalClusterView 33 extends LinearLayout 34 implements NetworkController.SignalCluster { 35 36 static final boolean DEBUG = false; 37 static final String TAG = "SignalClusterView"; 38 39 NetworkController mNC; 40 41 private boolean mWifiVisible = false; 42 private int mWifiStrengthId = 0; 43 private boolean mMobileVisible = false; 44 private int mMobileStrengthId = 0, mMobileTypeId = 0; 45 private boolean mIsAirplaneMode = false; 46 private int mAirplaneIconId = 0; 47 private String mWifiDescription, mMobileDescription, mMobileTypeDescription; 48 49 ViewGroup mWifiGroup, mMobileGroup; 50 ImageView mWifi, mMobile, mMobileType, mAirplane; 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) Log.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 mMobileGroup = (ViewGroup) findViewById(R.id.mobile_combo); 77 mMobile = (ImageView) findViewById(R.id.mobile_signal); 78 mMobileType = (ImageView) findViewById(R.id.mobile_type); 79 mSpacer = findViewById(R.id.spacer); 80 mAirplane = (ImageView) findViewById(R.id.airplane); 81 82 apply(); 83 } 84 85 @Override onDetachedFromWindow()86 protected void onDetachedFromWindow() { 87 mWifiGroup = null; 88 mWifi = null; 89 mMobileGroup = null; 90 mMobile = null; 91 mMobileType = null; 92 mSpacer = null; 93 mAirplane = null; 94 95 super.onDetachedFromWindow(); 96 } 97 98 @Override setWifiIndicators(boolean visible, int strengthIcon, String contentDescription)99 public void setWifiIndicators(boolean visible, int strengthIcon, String contentDescription) { 100 mWifiVisible = visible; 101 mWifiStrengthId = strengthIcon; 102 mWifiDescription = contentDescription; 103 104 apply(); 105 } 106 107 @Override setMobileDataIndicators(boolean visible, int strengthIcon, int typeIcon, String contentDescription, String typeContentDescription)108 public void setMobileDataIndicators(boolean visible, int strengthIcon, 109 int typeIcon, String contentDescription, String typeContentDescription) { 110 mMobileVisible = visible; 111 mMobileStrengthId = strengthIcon; 112 mMobileTypeId = typeIcon; 113 mMobileDescription = contentDescription; 114 mMobileTypeDescription = typeContentDescription; 115 116 apply(); 117 } 118 119 @Override setIsAirplaneMode(boolean is, int airplaneIconId)120 public void setIsAirplaneMode(boolean is, int airplaneIconId) { 121 mIsAirplaneMode = is; 122 mAirplaneIconId = airplaneIconId; 123 124 apply(); 125 } 126 127 @Override dispatchPopulateAccessibilityEvent(AccessibilityEvent event)128 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { 129 // Standard group layout onPopulateAccessibilityEvent() implementations 130 // ignore content description, so populate manually 131 if (mWifiVisible && mWifiGroup != null && mWifiGroup.getContentDescription() != null) 132 event.getText().add(mWifiGroup.getContentDescription()); 133 if (mMobileVisible && mMobileGroup != null && mMobileGroup.getContentDescription() != null) 134 event.getText().add(mMobileGroup.getContentDescription()); 135 return super.dispatchPopulateAccessibilityEvent(event); 136 } 137 138 @Override onRtlPropertiesChanged(int layoutDirection)139 public void onRtlPropertiesChanged(int layoutDirection) { 140 super.onRtlPropertiesChanged(layoutDirection); 141 142 if (mWifi != null) { 143 mWifi.setImageDrawable(null); 144 } 145 146 if (mMobile != null) { 147 mMobile.setImageDrawable(null); 148 } 149 150 if (mMobileType != null) { 151 mMobileType.setImageDrawable(null); 152 } 153 154 if(mAirplane != null) { 155 mAirplane.setImageDrawable(null); 156 } 157 158 apply(); 159 } 160 161 // Run after each indicator change. apply()162 private void apply() { 163 if (mWifiGroup == null) return; 164 165 if (mWifiVisible) { 166 mWifi.setImageResource(mWifiStrengthId); 167 168 mWifiGroup.setContentDescription(mWifiDescription); 169 mWifiGroup.setVisibility(View.VISIBLE); 170 } else { 171 mWifiGroup.setVisibility(View.GONE); 172 } 173 174 if (DEBUG) Log.d(TAG, 175 String.format("wifi: %s sig=%d", 176 (mWifiVisible ? "VISIBLE" : "GONE"), 177 mWifiStrengthId)); 178 179 if (mMobileVisible && !mIsAirplaneMode) { 180 mMobile.setImageResource(mMobileStrengthId); 181 mMobileType.setImageResource(mMobileTypeId); 182 183 mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription); 184 mMobileGroup.setVisibility(View.VISIBLE); 185 } else { 186 mMobileGroup.setVisibility(View.GONE); 187 } 188 189 if (mIsAirplaneMode) { 190 mAirplane.setImageResource(mAirplaneIconId); 191 mAirplane.setVisibility(View.VISIBLE); 192 } else { 193 mAirplane.setVisibility(View.GONE); 194 } 195 196 if (mMobileVisible && mWifiVisible && mIsAirplaneMode) { 197 mSpacer.setVisibility(View.INVISIBLE); 198 } else { 199 mSpacer.setVisibility(View.GONE); 200 } 201 202 if (DEBUG) Log.d(TAG, 203 String.format("mobile: %s sig=%d typ=%d", 204 (mMobileVisible ? "VISIBLE" : "GONE"), 205 mMobileStrengthId, mMobileTypeId)); 206 207 mMobileType.setVisibility( 208 !mWifiVisible ? View.VISIBLE : View.GONE); 209 } 210 } 211 212