Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 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 | |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 19 | import android.annotation.DrawableRes; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 21 | import android.content.res.ColorStateList; |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 22 | import android.content.res.Resources; |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 23 | import android.graphics.Color; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 24 | import android.graphics.Rect; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 25 | import android.graphics.drawable.Animatable; |
Jorim Jaggi | 035a82d | 2016-02-29 08:42:25 +0100 | [diff] [blame] | 26 | import android.graphics.drawable.AnimatedVectorDrawable; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 28 | import android.telephony.SubscriptionInfo; |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 29 | import android.util.ArraySet; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 30 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 31 | import android.util.Log; |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 32 | import android.util.TypedValue; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 33 | import android.view.LayoutInflater; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 34 | import android.view.View; |
| 35 | import android.view.ViewGroup; |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 36 | import android.view.accessibility.AccessibilityEvent; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 37 | import android.widget.ImageView; |
| 38 | import android.widget.LinearLayout; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 39 | |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 40 | import com.android.systemui.R; |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.NetworkControllerImpl; |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 44 | import com.android.systemui.statusbar.policy.SecurityController; |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 45 | import com.android.systemui.tuner.TunerService; |
| 46 | import com.android.systemui.tuner.TunerService.Tunable; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 47 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 48 | import java.util.ArrayList; |
| 49 | import java.util.List; |
| 50 | |
Daniel Sandler | 5ccff81 | 2011-09-13 15:17:58 -0400 | [diff] [blame] | 51 | // Intimately tied to the design of res/layout/signal_cluster_view.xml |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 52 | public class SignalClusterView |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 53 | extends LinearLayout |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 54 | implements NetworkControllerImpl.SignalCallback, |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 55 | SecurityController.SecurityControllerCallback, Tunable { |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 56 | |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 57 | static final String TAG = "SignalClusterView"; |
John Spurlock | b3eb891 | 2014-07-30 11:03:03 -0400 | [diff] [blame] | 58 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 59 | |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 60 | private static final String SLOT_AIRPLANE = "airplane"; |
| 61 | private static final String SLOT_MOBILE = "mobile"; |
| 62 | private static final String SLOT_WIFI = "wifi"; |
| 63 | private static final String SLOT_ETHERNET = "ethernet"; |
| 64 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 65 | NetworkControllerImpl mNC; |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 66 | SecurityController mSC; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 67 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 68 | private boolean mNoSimsVisible = false; |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 69 | private boolean mVpnVisible = false; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 70 | private boolean mEthernetVisible = false; |
| 71 | private int mEthernetIconId = 0; |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 72 | private int mLastEthernetIconId = -1; |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 73 | private boolean mWifiVisible = false; |
John Spurlock | fcc901c | 2013-09-04 10:36:27 -0400 | [diff] [blame] | 74 | private int mWifiStrengthId = 0; |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 75 | private int mLastWifiStrengthId = -1; |
Daniel Sandler | 5ccff81 | 2011-09-13 15:17:58 -0400 | [diff] [blame] | 76 | private boolean mIsAirplaneMode = false; |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 77 | private int mAirplaneIconId = 0; |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 78 | private int mLastAirplaneIconId = -1; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 79 | private String mAirplaneContentDescription; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 80 | private String mWifiDescription; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 81 | private String mEthernetDescription; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 82 | private ArrayList<PhoneState> mPhoneStates = new ArrayList<PhoneState>(); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 83 | private int mIconTint = Color.WHITE; |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 84 | private float mDarkIntensity; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 85 | private final Rect mTintArea = new Rect(); |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 86 | |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 87 | ViewGroup mEthernetGroup, mWifiGroup; |
Adrian Roos | 1b5eb97 | 2015-06-11 18:22:52 -0700 | [diff] [blame] | 88 | View mNoSimsCombo; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 89 | ImageView mVpn, mEthernet, mWifi, mAirplane, mNoSims, mEthernetDark, mWifiDark, mNoSimsDark; |
Jorim Jaggi | 5172dc2 | 2014-09-02 14:59:06 +0200 | [diff] [blame] | 90 | View mWifiAirplaneSpacer; |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 91 | View mWifiSignalSpacer; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 92 | LinearLayout mMobileSignalGroup; |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 93 | |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 94 | private final int mMobileSignalGroupEndPadding; |
| 95 | private final int mMobileDataIconStartPadding; |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 96 | private final int mWideTypeIconStartPadding; |
| 97 | private final int mSecondaryTelephonyPadding; |
| 98 | private final int mEndPadding; |
| 99 | private final int mEndPaddingNothingVisible; |
| 100 | private final float mIconScaleFactor; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 101 | |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 102 | private boolean mBlockAirplane; |
| 103 | private boolean mBlockMobile; |
| 104 | private boolean mBlockWifi; |
| 105 | private boolean mBlockEthernet; |
| 106 | |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 107 | public SignalClusterView(Context context) { |
| 108 | this(context, null); |
| 109 | } |
| 110 | |
| 111 | public SignalClusterView(Context context, AttributeSet attrs) { |
| 112 | this(context, attrs, 0); |
| 113 | } |
| 114 | |
| 115 | public SignalClusterView(Context context, AttributeSet attrs, int defStyle) { |
| 116 | super(context, attrs, defStyle); |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 117 | |
| 118 | Resources res = getResources(); |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 119 | mMobileSignalGroupEndPadding = |
| 120 | res.getDimensionPixelSize(R.dimen.mobile_signal_group_end_padding); |
| 121 | mMobileDataIconStartPadding = |
| 122 | res.getDimensionPixelSize(R.dimen.mobile_data_icon_start_padding); |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 123 | mWideTypeIconStartPadding = res.getDimensionPixelSize(R.dimen.wide_type_icon_start_padding); |
| 124 | mSecondaryTelephonyPadding = res.getDimensionPixelSize(R.dimen.secondary_telephony_padding); |
| 125 | mEndPadding = res.getDimensionPixelSize(R.dimen.signal_cluster_battery_padding); |
| 126 | mEndPaddingNothingVisible = res.getDimensionPixelSize( |
| 127 | R.dimen.no_signal_cluster_battery_padding); |
| 128 | |
| 129 | TypedValue typedValue = new TypedValue(); |
| 130 | res.getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true); |
| 131 | mIconScaleFactor = typedValue.getFloat(); |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 132 | } |
| 133 | |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 134 | @Override |
| 135 | public void onTuningChanged(String key, String newValue) { |
| 136 | if (!StatusBarIconController.ICON_BLACKLIST.equals(key)) { |
| 137 | return; |
| 138 | } |
| 139 | ArraySet<String> blockList = StatusBarIconController.getIconBlacklist(newValue); |
Jason Monk | f3d1715 | 2015-06-15 15:02:56 -0400 | [diff] [blame] | 140 | boolean blockAirplane = blockList.contains(SLOT_AIRPLANE); |
| 141 | boolean blockMobile = blockList.contains(SLOT_MOBILE); |
| 142 | boolean blockWifi = blockList.contains(SLOT_WIFI); |
| 143 | boolean blockEthernet = blockList.contains(SLOT_ETHERNET); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 144 | |
Jason Monk | f3d1715 | 2015-06-15 15:02:56 -0400 | [diff] [blame] | 145 | if (blockAirplane != mBlockAirplane || blockMobile != mBlockMobile |
| 146 | || blockEthernet != mBlockEthernet || blockWifi != mBlockWifi) { |
| 147 | mBlockAirplane = blockAirplane; |
| 148 | mBlockMobile = blockMobile; |
| 149 | mBlockEthernet = blockEthernet; |
| 150 | mBlockWifi = blockWifi; |
| 151 | // Re-register to get new callbacks. |
| 152 | mNC.removeSignalCallback(this); |
| 153 | mNC.addSignalCallback(this); |
| 154 | } |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 155 | } |
| 156 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 157 | public void setNetworkController(NetworkControllerImpl nc) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 158 | if (DEBUG) Log.d(TAG, "NetworkController=" + nc); |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 159 | mNC = nc; |
| 160 | } |
| 161 | |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 162 | public void setSecurityController(SecurityController sc) { |
| 163 | if (DEBUG) Log.d(TAG, "SecurityController=" + sc); |
| 164 | mSC = sc; |
| 165 | mSC.addCallback(this); |
| 166 | mVpnVisible = mSC.isVpnEnabled(); |
| 167 | } |
| 168 | |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 169 | @Override |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 170 | protected void onFinishInflate() { |
| 171 | super.onFinishInflate(); |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 172 | |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 173 | mVpn = (ImageView) findViewById(R.id.vpn); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 174 | mEthernetGroup = (ViewGroup) findViewById(R.id.ethernet_combo); |
| 175 | mEthernet = (ImageView) findViewById(R.id.ethernet); |
| 176 | mEthernetDark = (ImageView) findViewById(R.id.ethernet_dark); |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 177 | mWifiGroup = (ViewGroup) findViewById(R.id.wifi_combo); |
| 178 | mWifi = (ImageView) findViewById(R.id.wifi_signal); |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 179 | mWifiDark = (ImageView) findViewById(R.id.wifi_signal_dark); |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 180 | mAirplane = (ImageView) findViewById(R.id.airplane); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 181 | mNoSims = (ImageView) findViewById(R.id.no_sims); |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 182 | mNoSimsDark = (ImageView) findViewById(R.id.no_sims_dark); |
Adrian Roos | 1b5eb97 | 2015-06-11 18:22:52 -0700 | [diff] [blame] | 183 | mNoSimsCombo = findViewById(R.id.no_sims_combo); |
Jorim Jaggi | 5172dc2 | 2014-09-02 14:59:06 +0200 | [diff] [blame] | 184 | mWifiAirplaneSpacer = findViewById(R.id.wifi_airplane_spacer); |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 185 | mWifiSignalSpacer = findViewById(R.id.wifi_signal_spacer); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 186 | mMobileSignalGroup = (LinearLayout) findViewById(R.id.mobile_signal_group); |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 187 | |
| 188 | maybeScaleVpnAndNoSimsIcons(); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Extracts the icon off of the VPN and no sims views and maybe scale them by |
| 193 | * {@link #mIconScaleFactor}. Note that the other icons are not scaled here because they are |
| 194 | * dynamic. As such, they need to be scaled each time the icon changes in {@link #apply()}. |
| 195 | */ |
| 196 | private void maybeScaleVpnAndNoSimsIcons() { |
| 197 | if (mIconScaleFactor == 1.f) { |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | mVpn.setImageDrawable(new ScalingDrawableWrapper(mVpn.getDrawable(), mIconScaleFactor)); |
| 202 | |
| 203 | mNoSims.setImageDrawable( |
| 204 | new ScalingDrawableWrapper(mNoSims.getDrawable(), mIconScaleFactor)); |
| 205 | mNoSimsDark.setImageDrawable( |
| 206 | new ScalingDrawableWrapper(mNoSimsDark.getDrawable(), mIconScaleFactor)); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | protected void onAttachedToWindow() { |
| 211 | super.onAttachedToWindow(); |
| 212 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 213 | for (PhoneState state : mPhoneStates) { |
| 214 | mMobileSignalGroup.addView(state.mMobileGroup); |
| 215 | } |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 216 | |
| 217 | int endPadding = mMobileSignalGroup.getChildCount() > 0 ? mMobileSignalGroupEndPadding : 0; |
| 218 | mMobileSignalGroup.setPaddingRelative(0, 0, endPadding, 0); |
| 219 | |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 220 | TunerService.get(mContext).addTunable(this, StatusBarIconController.ICON_BLACKLIST); |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 221 | |
| 222 | apply(); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 223 | applyIconTint(); |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
| 227 | protected void onDetachedFromWindow() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 228 | mMobileSignalGroup.removeAllViews(); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 229 | TunerService.get(mContext).removeTunable(this); |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 230 | mSC.removeCallback(this); |
| 231 | mNC.removeSignalCallback(this); |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 232 | |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 233 | super.onDetachedFromWindow(); |
| 234 | } |
| 235 | |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 236 | // From SecurityController. |
| 237 | @Override |
| 238 | public void onStateChanged() { |
| 239 | post(new Runnable() { |
| 240 | @Override |
| 241 | public void run() { |
| 242 | mVpnVisible = mSC.isVpnEnabled(); |
| 243 | apply(); |
| 244 | } |
| 245 | }); |
| 246 | } |
| 247 | |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 248 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 249 | public void setWifiIndicators(boolean enabled, IconState statusIcon, IconState qsIcon, |
| 250 | boolean activityIn, boolean activityOut, String description) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 251 | mWifiVisible = statusIcon.visible && !mBlockWifi; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 252 | mWifiStrengthId = statusIcon.icon; |
| 253 | mWifiDescription = statusIcon.contentDescription; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 254 | |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 255 | apply(); |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 258 | @Override |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 259 | public void setMobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType, |
| 260 | int qsType, boolean activityIn, boolean activityOut, String typeContentDescription, |
| 261 | String description, boolean isWide, int subId) { |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 262 | PhoneState state = getState(subId); |
| 263 | if (state == null) { |
| 264 | return; |
| 265 | } |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 266 | state.mMobileVisible = statusIcon.visible && !mBlockMobile; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 267 | state.mMobileStrengthId = statusIcon.icon; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 268 | state.mMobileTypeId = statusType; |
| 269 | state.mMobileDescription = statusIcon.contentDescription; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 270 | state.mMobileTypeDescription = typeContentDescription; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 271 | state.mIsMobileTypeIconWide = statusType != 0 && isWide; |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 272 | |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 273 | apply(); |
| 274 | } |
| 275 | |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 276 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 277 | public void setEthernetIndicators(IconState state) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 278 | mEthernetVisible = state.visible && !mBlockEthernet; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 279 | mEthernetIconId = state.icon; |
| 280 | mEthernetDescription = state.contentDescription; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 281 | |
| 282 | apply(); |
| 283 | } |
| 284 | |
| 285 | @Override |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 286 | public void setNoSims(boolean show) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 287 | mNoSimsVisible = show && !mBlockMobile; |
Jason Monk | 64f4f98 | 2015-10-08 10:09:21 -0400 | [diff] [blame] | 288 | apply(); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public void setSubs(List<SubscriptionInfo> subs) { |
Jason Monk | f535cf0 | 2015-06-17 12:52:43 -0400 | [diff] [blame] | 293 | if (hasCorrectSubs(subs)) { |
| 294 | return; |
| 295 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 296 | // Clear out all old subIds. |
| 297 | mPhoneStates.clear(); |
| 298 | if (mMobileSignalGroup != null) { |
| 299 | mMobileSignalGroup.removeAllViews(); |
| 300 | } |
| 301 | final int n = subs.size(); |
| 302 | for (int i = 0; i < n; i++) { |
| 303 | inflatePhoneState(subs.get(i).getSubscriptionId()); |
| 304 | } |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 305 | if (isAttachedToWindow()) { |
| 306 | applyIconTint(); |
| 307 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Jason Monk | f535cf0 | 2015-06-17 12:52:43 -0400 | [diff] [blame] | 310 | private boolean hasCorrectSubs(List<SubscriptionInfo> subs) { |
| 311 | final int N = subs.size(); |
| 312 | if (N != mPhoneStates.size()) { |
| 313 | return false; |
| 314 | } |
| 315 | for (int i = 0; i < N; i++) { |
| 316 | if (mPhoneStates.get(i).mSubId != subs.get(i).getSubscriptionId()) { |
| 317 | return false; |
| 318 | } |
| 319 | } |
| 320 | return true; |
| 321 | } |
| 322 | |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 323 | private PhoneState getState(int subId) { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 324 | for (PhoneState state : mPhoneStates) { |
| 325 | if (state.mSubId == subId) { |
| 326 | return state; |
| 327 | } |
| 328 | } |
Jason Monk | 8fcab35 | 2015-06-29 10:57:00 -0400 | [diff] [blame] | 329 | Log.e(TAG, "Unexpected subscription " + subId); |
| 330 | return null; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | private PhoneState inflatePhoneState(int subId) { |
| 334 | PhoneState state = new PhoneState(subId, mContext); |
| 335 | if (mMobileSignalGroup != null) { |
| 336 | mMobileSignalGroup.addView(state.mMobileGroup); |
| 337 | } |
| 338 | mPhoneStates.add(state); |
| 339 | return state; |
| 340 | } |
| 341 | |
| 342 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 343 | public void setIsAirplaneMode(IconState icon) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 344 | mIsAirplaneMode = icon.visible && !mBlockAirplane; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 345 | mAirplaneIconId = icon.icon; |
| 346 | mAirplaneContentDescription = icon.contentDescription; |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 347 | |
| 348 | apply(); |
Daniel Sandler | 5ccff81 | 2011-09-13 15:17:58 -0400 | [diff] [blame] | 349 | } |
| 350 | |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 351 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 352 | public void setMobileDataEnabled(boolean enabled) { |
| 353 | // Don't care. |
| 354 | } |
| 355 | |
| 356 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 357 | public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 358 | // Standard group layout onPopulateAccessibilityEvent() implementations |
| 359 | // ignore content description, so populate manually |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 360 | if (mEthernetVisible && mEthernetGroup != null && |
| 361 | mEthernetGroup.getContentDescription() != null) |
| 362 | event.getText().add(mEthernetGroup.getContentDescription()); |
Daniel Sandler | 24e028e | 2013-08-13 20:18:01 -0700 | [diff] [blame] | 363 | if (mWifiVisible && mWifiGroup != null && mWifiGroup.getContentDescription() != null) |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 364 | event.getText().add(mWifiGroup.getContentDescription()); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 365 | for (PhoneState state : mPhoneStates) { |
| 366 | state.populateAccessibilityEvent(event); |
| 367 | } |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 368 | return super.dispatchPopulateAccessibilityEventInternal(event); |
John Spurlock | 2f7dfa7 | 2012-05-16 20:20:59 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 371 | @Override |
| 372 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 373 | super.onRtlPropertiesChanged(layoutDirection); |
| 374 | |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 375 | if (mEthernet != null) { |
| 376 | mEthernet.setImageDrawable(null); |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 377 | mEthernetDark.setImageDrawable(null); |
| 378 | mLastEthernetIconId = -1; |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 379 | } |
| 380 | |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 381 | if (mWifi != null) { |
| 382 | mWifi.setImageDrawable(null); |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 383 | mWifiDark.setImageDrawable(null); |
| 384 | mLastWifiStrengthId = -1; |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 385 | } |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 386 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 387 | for (PhoneState state : mPhoneStates) { |
| 388 | if (state.mMobile != null) { |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 389 | state.maybeStopAnimatableDrawable(state.mMobile); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 390 | state.mMobile.setImageDrawable(null); |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 391 | state.mLastMobileStrengthId = -1; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 392 | } |
| 393 | if (state.mMobileType != null) { |
| 394 | state.mMobileType.setImageDrawable(null); |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 395 | state.mLastMobileTypeId = -1; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 396 | } |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 399 | if (mAirplane != null) { |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 400 | mAirplane.setImageDrawable(null); |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 401 | mLastAirplaneIconId = -1; |
Fabrice Di Meglio | 4662611 | 2013-05-07 11:32:51 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | apply(); |
| 405 | } |
| 406 | |
Jorim Jaggi | 0d26689 | 2014-07-28 14:49:13 +0200 | [diff] [blame] | 407 | @Override |
| 408 | public boolean hasOverlappingRendering() { |
| 409 | return false; |
| 410 | } |
| 411 | |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 412 | // Run after each indicator change. |
| 413 | private void apply() { |
| 414 | if (mWifiGroup == null) return; |
| 415 | |
Jason Monk | 3128f12 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 416 | mVpn.setVisibility(mVpnVisible ? View.VISIBLE : View.GONE); |
| 417 | if (DEBUG) Log.d(TAG, String.format("vpn: %s", mVpnVisible ? "VISIBLE" : "GONE")); |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 418 | |
| 419 | if (mEthernetVisible) { |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 420 | if (mLastEthernetIconId != mEthernetIconId) { |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 421 | setIconForView(mEthernet, mEthernetIconId); |
| 422 | setIconForView(mEthernetDark, mEthernetIconId); |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 423 | mLastEthernetIconId = mEthernetIconId; |
| 424 | } |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 425 | mEthernetGroup.setContentDescription(mEthernetDescription); |
| 426 | mEthernetGroup.setVisibility(View.VISIBLE); |
| 427 | } else { |
| 428 | mEthernetGroup.setVisibility(View.GONE); |
| 429 | } |
| 430 | |
| 431 | if (DEBUG) Log.d(TAG, |
| 432 | String.format("ethernet: %s", |
| 433 | (mEthernetVisible ? "VISIBLE" : "GONE"))); |
| 434 | |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 435 | if (mWifiVisible) { |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 436 | if (mWifiStrengthId != mLastWifiStrengthId) { |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 437 | setIconForView(mWifi, mWifiStrengthId); |
| 438 | setIconForView(mWifiDark, mWifiStrengthId); |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 439 | mLastWifiStrengthId = mWifiStrengthId; |
| 440 | } |
Daniel Sandler | bcf6ef0b | 2011-09-30 11:43:36 -0400 | [diff] [blame] | 441 | mWifiGroup.setContentDescription(mWifiDescription); |
Fabrice Di Meglio | cda096e | 2012-12-26 17:11:13 -0800 | [diff] [blame] | 442 | mWifiGroup.setVisibility(View.VISIBLE); |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 443 | } else { |
| 444 | mWifiGroup.setVisibility(View.GONE); |
| 445 | } |
| 446 | |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 447 | if (DEBUG) Log.d(TAG, |
John Spurlock | fcc901c | 2013-09-04 10:36:27 -0400 | [diff] [blame] | 448 | String.format("wifi: %s sig=%d", |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 449 | (mWifiVisible ? "VISIBLE" : "GONE"), |
John Spurlock | fcc901c | 2013-09-04 10:36:27 -0400 | [diff] [blame] | 450 | mWifiStrengthId)); |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 451 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 452 | boolean anyMobileVisible = false; |
Dan Sandler | e912c9c | 2014-12-08 15:00:09 -0500 | [diff] [blame] | 453 | int firstMobileTypeId = 0; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 454 | for (PhoneState state : mPhoneStates) { |
| 455 | if (state.apply(anyMobileVisible)) { |
Dan Sandler | e912c9c | 2014-12-08 15:00:09 -0500 | [diff] [blame] | 456 | if (!anyMobileVisible) { |
| 457 | firstMobileTypeId = state.mMobileTypeId; |
| 458 | anyMobileVisible = true; |
| 459 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 460 | } |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 461 | } |
Daniel Sandler | 28f89d4 | 2011-08-15 14:04:15 -0400 | [diff] [blame] | 462 | |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 463 | if (mIsAirplaneMode) { |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 464 | if (mLastAirplaneIconId != mAirplaneIconId) { |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 465 | setIconForView(mAirplane, mAirplaneIconId); |
Jorim Jaggi | 06302c2 | 2015-05-20 17:05:23 -0700 | [diff] [blame] | 466 | mLastAirplaneIconId = mAirplaneIconId; |
| 467 | } |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 468 | mAirplane.setContentDescription(mAirplaneContentDescription); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 469 | mAirplane.setVisibility(View.VISIBLE); |
Andrew Flynn | 061d43c | 2012-05-04 10:57:58 -0700 | [diff] [blame] | 470 | } else { |
| 471 | mAirplane.setVisibility(View.GONE); |
| 472 | } |
| 473 | |
Jorim Jaggi | 5172dc2 | 2014-09-02 14:59:06 +0200 | [diff] [blame] | 474 | if (mIsAirplaneMode && mWifiVisible) { |
| 475 | mWifiAirplaneSpacer.setVisibility(View.VISIBLE); |
Daniel Sandler | 5ccff81 | 2011-09-13 15:17:58 -0400 | [diff] [blame] | 476 | } else { |
Jorim Jaggi | 5172dc2 | 2014-09-02 14:59:06 +0200 | [diff] [blame] | 477 | mWifiAirplaneSpacer.setVisibility(View.GONE); |
Daniel Sandler | 5ccff81 | 2011-09-13 15:17:58 -0400 | [diff] [blame] | 478 | } |
| 479 | |
Dan Sandler | e912c9c | 2014-12-08 15:00:09 -0500 | [diff] [blame] | 480 | if (((anyMobileVisible && firstMobileTypeId != 0) || mNoSimsVisible) && mWifiVisible) { |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 481 | mWifiSignalSpacer.setVisibility(View.VISIBLE); |
| 482 | } else { |
| 483 | mWifiSignalSpacer.setVisibility(View.GONE); |
| 484 | } |
| 485 | |
Adrian Roos | 1b5eb97 | 2015-06-11 18:22:52 -0700 | [diff] [blame] | 486 | mNoSimsCombo.setVisibility(mNoSimsVisible ? View.VISIBLE : View.GONE); |
Jorim Jaggi | c737b9b | 2014-09-08 23:57:20 +0200 | [diff] [blame] | 487 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 488 | boolean anythingVisible = mNoSimsVisible || mWifiVisible || mIsAirplaneMode |
Lorenzo Colitti | d46bb58 | 2015-04-27 20:32:01 +0900 | [diff] [blame] | 489 | || anyMobileVisible || mVpnVisible || mEthernetVisible; |
Jorim Jaggi | 6d035f1 | 2014-10-17 18:43:43 +0200 | [diff] [blame] | 490 | setPaddingRelative(0, 0, anythingVisible ? mEndPadding : mEndPaddingNothingVisible, 0); |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 491 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 492 | |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 493 | /** |
| 494 | * Sets the given drawable id on the view. This method will also scale the icon by |
| 495 | * {@link #mIconScaleFactor} if appropriate. |
| 496 | */ |
| 497 | private void setIconForView(ImageView imageView, @DrawableRes int iconId) { |
| 498 | // Using the imageView's context to retrieve the Drawable so that theme is preserved. |
| 499 | Drawable icon = imageView.getContext().getDrawable(iconId); |
| 500 | |
| 501 | if (mIconScaleFactor == 1.f) { |
| 502 | imageView.setImageDrawable(icon); |
| 503 | } else { |
| 504 | imageView.setImageDrawable(new ScalingDrawableWrapper(icon, mIconScaleFactor)); |
| 505 | } |
| 506 | } |
| 507 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 508 | public void setIconTint(int tint, float darkIntensity, Rect tintArea) { |
| 509 | boolean changed = tint != mIconTint || darkIntensity != mDarkIntensity |
| 510 | || !mTintArea.equals(tintArea); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 511 | mIconTint = tint; |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 512 | mDarkIntensity = darkIntensity; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 513 | mTintArea.set(tintArea); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 514 | if (changed && isAttachedToWindow()) { |
| 515 | applyIconTint(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | private void applyIconTint() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 520 | setTint(mVpn, StatusBarIconController.getTint(mTintArea, mVpn, mIconTint)); |
| 521 | setTint(mAirplane, StatusBarIconController.getTint(mTintArea, mAirplane, mIconTint)); |
| 522 | applyDarkIntensity( |
| 523 | StatusBarIconController.getDarkIntensity(mTintArea, mNoSims, mDarkIntensity), |
| 524 | mNoSims, mNoSimsDark); |
| 525 | applyDarkIntensity( |
| 526 | StatusBarIconController.getDarkIntensity(mTintArea, mWifi, mDarkIntensity), |
| 527 | mWifi, mWifiDark); |
| 528 | applyDarkIntensity( |
| 529 | StatusBarIconController.getDarkIntensity(mTintArea, mEthernet, mDarkIntensity), |
| 530 | mEthernet, mEthernetDark); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 531 | for (int i = 0; i < mPhoneStates.size(); i++) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 532 | mPhoneStates.get(i).setIconTint(mIconTint, mDarkIntensity, mTintArea); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 536 | private void applyDarkIntensity(float darkIntensity, View lightIcon, View darkIcon) { |
| 537 | lightIcon.setAlpha(1 - darkIntensity); |
| 538 | darkIcon.setAlpha(darkIntensity); |
| 539 | } |
| 540 | |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 541 | private void setTint(ImageView v, int tint) { |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 542 | v.setImageTintList(ColorStateList.valueOf(tint)); |
| 543 | } |
| 544 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 545 | private class PhoneState { |
| 546 | private final int mSubId; |
| 547 | private boolean mMobileVisible = false; |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 548 | private int mMobileStrengthId = 0, mMobileTypeId = 0; |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 549 | private int mLastMobileStrengthId = -1; |
| 550 | private int mLastMobileTypeId = -1; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 551 | private boolean mIsMobileTypeIconWide; |
| 552 | private String mMobileDescription, mMobileTypeDescription; |
| 553 | |
| 554 | private ViewGroup mMobileGroup; |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 555 | private ImageView mMobile, mMobileDark, mMobileType; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 556 | |
| 557 | public PhoneState(int subId, Context context) { |
| 558 | ViewGroup root = (ViewGroup) LayoutInflater.from(context) |
| 559 | .inflate(R.layout.mobile_signal_group, null); |
| 560 | setViews(root); |
| 561 | mSubId = subId; |
| 562 | } |
| 563 | |
| 564 | public void setViews(ViewGroup root) { |
| 565 | mMobileGroup = root; |
| 566 | mMobile = (ImageView) root.findViewById(R.id.mobile_signal); |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 567 | mMobileDark = (ImageView) root.findViewById(R.id.mobile_signal_dark); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 568 | mMobileType = (ImageView) root.findViewById(R.id.mobile_type); |
| 569 | } |
| 570 | |
| 571 | public boolean apply(boolean isSecondaryIcon) { |
| 572 | if (mMobileVisible && !mIsAirplaneMode) { |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 573 | if (mLastMobileStrengthId != mMobileStrengthId) { |
| 574 | updateAnimatableIcon(mMobile, mMobileStrengthId); |
| 575 | updateAnimatableIcon(mMobileDark, mMobileStrengthId); |
| 576 | mLastMobileStrengthId = mMobileStrengthId; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 579 | if (mLastMobileTypeId != mMobileTypeId) { |
| 580 | mMobileType.setImageResource(mMobileTypeId); |
| 581 | mLastMobileTypeId = mMobileTypeId; |
Andrew Flynn | a478d70 | 2015-04-14 23:33:45 -0400 | [diff] [blame] | 582 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 583 | mMobileGroup.setContentDescription(mMobileTypeDescription |
| 584 | + " " + mMobileDescription); |
| 585 | mMobileGroup.setVisibility(View.VISIBLE); |
| 586 | } else { |
| 587 | mMobileGroup.setVisibility(View.GONE); |
| 588 | } |
| 589 | |
| 590 | // When this isn't next to wifi, give it some extra padding between the signals. |
| 591 | mMobileGroup.setPaddingRelative(isSecondaryIcon ? mSecondaryTelephonyPadding : 0, |
| 592 | 0, 0, 0); |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 593 | mMobile.setPaddingRelative( |
| 594 | mIsMobileTypeIconWide ? mWideTypeIconStartPadding : mMobileDataIconStartPadding, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 595 | 0, 0, 0); |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 596 | mMobileDark.setPaddingRelative( |
| 597 | mIsMobileTypeIconWide ? mWideTypeIconStartPadding : mMobileDataIconStartPadding, |
Jorim Jaggi | 5443cc5 | 2015-03-20 14:39:24 -0700 | [diff] [blame] | 598 | 0, 0, 0); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 599 | |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 600 | if (DEBUG) Log.d(TAG, String.format("mobile: %s sig=%d typ=%d", |
| 601 | (mMobileVisible ? "VISIBLE" : "GONE"), mMobileStrengthId, mMobileTypeId)); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 602 | |
| 603 | mMobileType.setVisibility(mMobileTypeId != 0 ? View.VISIBLE : View.GONE); |
| 604 | |
| 605 | return mMobileVisible; |
| 606 | } |
| 607 | |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 608 | private void updateAnimatableIcon(ImageView view, int resId) { |
| 609 | maybeStopAnimatableDrawable(view); |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 610 | setIconForView(view, resId); |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 611 | maybeStartAnimatableDrawable(view); |
| 612 | } |
| 613 | |
| 614 | private void maybeStopAnimatableDrawable(ImageView view) { |
| 615 | Drawable drawable = view.getDrawable(); |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 616 | |
| 617 | // Check if the icon has been scaled. If it has retrieve the actual drawable out of the |
| 618 | // wrapper. |
| 619 | if (drawable instanceof ScalingDrawableWrapper) { |
| 620 | drawable = ((ScalingDrawableWrapper) drawable).getDrawable(); |
| 621 | } |
| 622 | |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 623 | if (drawable instanceof Animatable) { |
| 624 | Animatable ad = (Animatable) drawable; |
| 625 | if (ad.isRunning()) { |
| 626 | ad.stop(); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | private void maybeStartAnimatableDrawable(ImageView view) { |
| 632 | Drawable drawable = view.getDrawable(); |
Anthony Chen | e87032c | 2016-02-09 07:42:25 -0800 | [diff] [blame] | 633 | |
| 634 | // Check if the icon has been scaled. If it has retrieve the actual drawable out of the |
| 635 | // wrapper. |
| 636 | if (drawable instanceof ScalingDrawableWrapper) { |
| 637 | drawable = ((ScalingDrawableWrapper) drawable).getDrawable(); |
| 638 | } |
| 639 | |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 640 | if (drawable instanceof Animatable) { |
| 641 | Animatable ad = (Animatable) drawable; |
Jorim Jaggi | 035a82d | 2016-02-29 08:42:25 +0100 | [diff] [blame] | 642 | if (ad instanceof AnimatedVectorDrawable) { |
| 643 | ((AnimatedVectorDrawable) ad).forceAnimationOnUI(); |
| 644 | } |
Jorim Jaggi | 3c98819 | 2016-01-19 16:32:17 -0800 | [diff] [blame] | 645 | if (!ad.isRunning()) { |
| 646 | ad.start(); |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 651 | public void populateAccessibilityEvent(AccessibilityEvent event) { |
| 652 | if (mMobileVisible && mMobileGroup != null |
| 653 | && mMobileGroup.getContentDescription() != null) { |
| 654 | event.getText().add(mMobileGroup.getContentDescription()); |
| 655 | } |
| 656 | } |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 657 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 658 | public void setIconTint(int tint, float darkIntensity, Rect tintArea) { |
| 659 | applyDarkIntensity( |
| 660 | StatusBarIconController.getDarkIntensity(tintArea, mMobile, darkIntensity), |
| 661 | mMobile, mMobileDark); |
| 662 | setTint(mMobileType, StatusBarIconController.getTint(tintArea, mMobileType, tint)); |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 663 | } |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 664 | } |
Christian Robertson | 2e34742 | 2011-08-11 14:01:04 -0700 | [diff] [blame] | 665 | } |
| 666 | |