Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.qs; |
| 18 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 19 | import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; |
| 20 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Amin Shaikh | 50c1789 | 2018-03-21 18:15:22 -0400 | [diff] [blame] | 23 | import android.content.pm.UserInfo; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 24 | import android.content.res.ColorStateList; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 26 | import android.graphics.PorterDuff.Mode; |
| 27 | import android.graphics.drawable.Drawable; |
| 28 | import android.graphics.drawable.RippleDrawable; |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 29 | import android.os.Bundle; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 30 | import android.os.UserManager; |
Aurimas Liutikas | a14377a | 2018-04-17 09:50:46 -0700 | [diff] [blame] | 31 | import androidx.annotation.Nullable; |
| 32 | import androidx.annotation.VisibleForTesting; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 33 | import android.text.TextUtils; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 34 | import android.util.AttributeSet; |
| 35 | import android.view.View; |
| 36 | import android.view.View.OnClickListener; |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 37 | import android.view.accessibility.AccessibilityNodeInfo; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 38 | import android.widget.FrameLayout; |
| 39 | import android.widget.ImageView; |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 40 | import android.widget.LinearLayout; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 41 | import android.widget.Toast; |
| 42 | |
| 43 | import com.android.internal.logging.MetricsLogger; |
| 44 | import com.android.internal.logging.nano.MetricsProto; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 45 | import com.android.keyguard.CarrierText; |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 46 | import com.android.keyguard.KeyguardUpdateMonitor; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 47 | import com.android.settingslib.Utils; |
Jason Monk | 826b609 | 2017-08-29 11:30:52 -0400 | [diff] [blame] | 48 | import com.android.settingslib.drawable.UserIconDrawable; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 49 | import com.android.settingslib.graph.SignalDrawable; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 50 | import com.android.systemui.Dependency; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 51 | import com.android.systemui.R; |
| 52 | import com.android.systemui.R.dimen; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 53 | import com.android.systemui.plugins.ActivityStarter; |
| 54 | import com.android.systemui.qs.TouchAnimator.Builder; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 55 | import com.android.systemui.statusbar.phone.MultiUserSwitch; |
| 56 | import com.android.systemui.statusbar.phone.SettingsButton; |
| 57 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 58 | import com.android.systemui.statusbar.policy.NetworkController; |
| 59 | import com.android.systemui.statusbar.policy.NetworkController.EmergencyListener; |
| 60 | import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.UserInfoController; |
| 62 | import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; |
| 63 | import com.android.systemui.tuner.TunerService; |
| 64 | |
| 65 | public class QSFooterImpl extends FrameLayout implements QSFooter, |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 66 | OnClickListener, OnUserInfoChangedListener, EmergencyListener, SignalCallback { |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 67 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 68 | private ActivityStarter mActivityStarter; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 69 | private UserInfoController mUserInfoController; |
| 70 | private SettingsButton mSettingsButton; |
| 71 | protected View mSettingsContainer; |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 72 | private PageIndicator mPageIndicator; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 73 | private CarrierText mCarrierText; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 74 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 75 | private boolean mQsDisabled; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 76 | private QSPanel mQsPanel; |
| 77 | |
| 78 | private boolean mExpanded; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 79 | |
| 80 | private boolean mListening; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 81 | |
| 82 | private boolean mShowEmergencyCallsOnly; |
Amin Shaikh | acf322d | 2018-01-31 17:04:56 -0500 | [diff] [blame] | 83 | private View mDivider; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 84 | protected MultiUserSwitch mMultiUserSwitch; |
| 85 | private ImageView mMultiUserAvatar; |
| 86 | |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 87 | protected TouchAnimator mFooterAnimator; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 88 | private float mExpansionAmount; |
| 89 | |
| 90 | protected View mEdit; |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 91 | private TouchAnimator mSettingsCogAnimator; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 92 | |
Evan Laird | 00e43c4 | 2018-01-22 20:25:45 -0500 | [diff] [blame] | 93 | private View mActionsContainer; |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 94 | private View mDragHandle; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 95 | private View mMobileGroup; |
| 96 | private ImageView mMobileSignal; |
| 97 | private ImageView mMobileRoaming; |
| 98 | private final int mColorForeground; |
| 99 | private final CellSignalState mInfo = new CellSignalState(); |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 100 | private OnClickListener mExpandClickListener; |
Evan Laird | 00e43c4 | 2018-01-22 20:25:45 -0500 | [diff] [blame] | 101 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 102 | public QSFooterImpl(Context context, AttributeSet attrs) { |
| 103 | super(context, attrs); |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 104 | mColorForeground = Utils.getColorAttr(context, android.R.attr.colorForeground); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | protected void onFinishInflate() { |
| 109 | super.onFinishInflate(); |
Amin Shaikh | acf322d | 2018-01-31 17:04:56 -0500 | [diff] [blame] | 110 | mDivider = findViewById(R.id.qs_footer_divider); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 111 | mEdit = findViewById(android.R.id.edit); |
| 112 | mEdit.setOnClickListener(view -> |
| 113 | Dependency.get(ActivityStarter.class).postQSRunnableDismissingKeyguard(() -> |
| 114 | mQsPanel.showEdit(view))); |
| 115 | |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 116 | mPageIndicator = findViewById(R.id.footer_page_indicator); |
| 117 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 118 | mSettingsButton = findViewById(R.id.settings_button); |
| 119 | mSettingsContainer = findViewById(R.id.settings_button_container); |
| 120 | mSettingsButton.setOnClickListener(this); |
| 121 | |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 122 | mMobileGroup = findViewById(R.id.mobile_combo); |
| 123 | mMobileSignal = findViewById(R.id.mobile_signal); |
| 124 | mMobileRoaming = findViewById(R.id.mobile_roaming); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 125 | mCarrierText = findViewById(R.id.qs_carrier_text); |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 126 | mCarrierText.setDisplayFlags( |
| 127 | CarrierText.FLAG_HIDE_AIRPLANE_MODE | CarrierText.FLAG_HIDE_MISSING_SIM); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 128 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 129 | mMultiUserSwitch = findViewById(R.id.multi_user_switch); |
| 130 | mMultiUserAvatar = mMultiUserSwitch.findViewById(R.id.multi_user_avatar); |
| 131 | |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 132 | mDragHandle = findViewById(R.id.qs_drag_handle_view); |
Evan Laird | 00e43c4 | 2018-01-22 20:25:45 -0500 | [diff] [blame] | 133 | mActionsContainer = findViewById(R.id.qs_footer_actions_container); |
| 134 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 135 | // RenderThread is doing more harm than good when touching the header (to expand quick |
| 136 | // settings), so disable it for this view |
| 137 | ((RippleDrawable) mSettingsButton.getBackground()).setForceSoftware(true); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 138 | |
| 139 | updateResources(); |
| 140 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 141 | mUserInfoController = Dependency.get(UserInfoController.class); |
| 142 | mActivityStarter = Dependency.get(ActivityStarter.class); |
| 143 | addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, |
| 144 | oldBottom) -> updateAnimator(right - left)); |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 145 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | private void updateAnimator(int width) { |
| 149 | int numTiles = QuickQSPanel.getNumQuickTiles(mContext); |
| 150 | int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size) |
| 151 | - mContext.getResources().getDimensionPixelSize(dimen.qs_quick_tile_padding); |
| 152 | int remaining = (width - numTiles * size) / (numTiles - 1); |
| 153 | int defSpace = mContext.getResources().getDimensionPixelOffset(R.dimen.default_gear_space); |
| 154 | |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 155 | mSettingsCogAnimator = new Builder() |
Jason Monk | 6dadd3e4 | 2017-09-01 09:36:19 -0400 | [diff] [blame] | 156 | .addFloat(mSettingsContainer, "translationX", |
| 157 | isLayoutRtl() ? (remaining - defSpace) : -(remaining - defSpace), 0) |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 158 | .addFloat(mSettingsButton, "rotation", -120, 0) |
| 159 | .build(); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 160 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 161 | setExpansion(mExpansionAmount); |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | protected void onConfigurationChanged(Configuration newConfig) { |
| 166 | super.onConfigurationChanged(newConfig); |
| 167 | updateResources(); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 172 | super.onRtlPropertiesChanged(layoutDirection); |
| 173 | updateResources(); |
| 174 | } |
| 175 | |
| 176 | private void updateResources() { |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 177 | updateFooterAnimator(); |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 178 | |
| 179 | // Update the width and weight of the actions container as the page indicator can sometimes |
| 180 | // show and the layout needs to center it between the carrier text and actions container. |
| 181 | LinearLayout.LayoutParams params = |
| 182 | (LinearLayout.LayoutParams) mActionsContainer.getLayoutParams(); |
| 183 | params.width = mContext.getResources().getInteger(R.integer.qs_footer_actions_width); |
| 184 | params.weight = mContext.getResources().getInteger(R.integer.qs_footer_actions_weight); |
| 185 | mActionsContainer.setLayoutParams(params); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 188 | private void updateFooterAnimator() { |
| 189 | mFooterAnimator = createFooterAnimator(); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Nullable |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 193 | private TouchAnimator createFooterAnimator() { |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 194 | return new TouchAnimator.Builder() |
Amin Shaikh | acf322d | 2018-01-31 17:04:56 -0500 | [diff] [blame] | 195 | .addFloat(mDivider, "alpha", 0, 1) |
Amin Shaikh | d620def | 2018-02-27 16:52:53 -0500 | [diff] [blame] | 196 | .addFloat(mCarrierText, "alpha", 0, 0, 1) |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 197 | .addFloat(mMobileGroup, "alpha", 0, 1) |
Evan Laird | 00e43c4 | 2018-01-22 20:25:45 -0500 | [diff] [blame] | 198 | .addFloat(mActionsContainer, "alpha", 0, 1) |
Amin Shaikh | d620def | 2018-02-27 16:52:53 -0500 | [diff] [blame] | 199 | .addFloat(mDragHandle, "alpha", 1, 0, 0) |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 200 | .addFloat(mPageIndicator, "alpha", 0, 1) |
Amin Shaikh | 92fac56 | 2018-02-16 15:08:16 -0500 | [diff] [blame] | 201 | .setStartDelay(0.15f) |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 202 | .build(); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void setKeyguardShowing(boolean keyguardShowing) { |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 207 | setExpansion(mExpansionAmount); |
| 208 | } |
| 209 | |
| 210 | @Override |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 211 | public void setExpandClickListener(OnClickListener onClickListener) { |
| 212 | mExpandClickListener = onClickListener; |
| 213 | } |
| 214 | |
| 215 | @Override |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 216 | public void setExpanded(boolean expanded) { |
| 217 | if (mExpanded == expanded) return; |
| 218 | mExpanded = expanded; |
| 219 | updateEverything(); |
| 220 | } |
| 221 | |
| 222 | @Override |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 223 | public void setExpansion(float headerExpansionFraction) { |
| 224 | mExpansionAmount = headerExpansionFraction; |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 225 | if (mSettingsCogAnimator != null) mSettingsCogAnimator.setPosition(headerExpansionFraction); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 226 | |
Evan Laird | eb38aa7 | 2018-02-02 11:10:30 -0500 | [diff] [blame] | 227 | if (mFooterAnimator != null) { |
| 228 | mFooterAnimator.setPosition(headerExpansionFraction); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 229 | } |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
| 233 | @VisibleForTesting |
| 234 | public void onDetachedFromWindow() { |
| 235 | setListening(false); |
| 236 | super.onDetachedFromWindow(); |
| 237 | } |
| 238 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 239 | @Override |
| 240 | public void setListening(boolean listening) { |
| 241 | if (listening == mListening) { |
| 242 | return; |
| 243 | } |
| 244 | mListening = listening; |
| 245 | updateListeners(); |
| 246 | } |
| 247 | |
| 248 | @Override |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 249 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
| 250 | if (action == AccessibilityNodeInfo.ACTION_EXPAND) { |
| 251 | if (mExpandClickListener != null) { |
| 252 | mExpandClickListener.onClick(null); |
| 253 | return true; |
| 254 | } |
| 255 | } |
| 256 | return super.performAccessibilityAction(action, arguments); |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 261 | super.onInitializeAccessibilityNodeInfo(info); |
| 262 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 265 | @Override |
| 266 | public void disable(int state1, int state2, boolean animate) { |
| 267 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 268 | if (disabled == mQsDisabled) return; |
| 269 | mQsDisabled = disabled; |
| 270 | updateEverything(); |
| 271 | } |
| 272 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 273 | public void updateEverything() { |
| 274 | post(() -> { |
| 275 | updateVisibilities(); |
| 276 | setClickable(false); |
| 277 | }); |
| 278 | } |
| 279 | |
| 280 | private void updateVisibilities() { |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 281 | mSettingsContainer.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 282 | mSettingsContainer.findViewById(R.id.tuner_icon).setVisibility( |
| 283 | TunerService.isTunerEnabled(mContext) ? View.VISIBLE : View.INVISIBLE); |
| 284 | final boolean isDemo = UserManager.isDeviceInDemoMode(mContext); |
Amin Shaikh | 50c1789 | 2018-03-21 18:15:22 -0400 | [diff] [blame] | 285 | mMultiUserSwitch.setVisibility(showUserSwitcher(isDemo) ? View.VISIBLE : View.INVISIBLE); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 286 | mEdit.setVisibility(isDemo || !mExpanded ? View.INVISIBLE : View.VISIBLE); |
Amin Shaikh | a59215a | 2018-04-23 08:52:38 -0400 | [diff] [blame] | 287 | mSettingsButton.setVisibility(isDemo || !mExpanded ? View.INVISIBLE : View.VISIBLE); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Amin Shaikh | 50c1789 | 2018-03-21 18:15:22 -0400 | [diff] [blame] | 290 | private boolean showUserSwitcher(boolean isDemo) { |
| 291 | if (!mExpanded || isDemo || !UserManager.supportsMultipleUsers()) { |
| 292 | return false; |
| 293 | } |
| 294 | UserManager userManager = UserManager.get(mContext); |
| 295 | if (userManager.hasUserRestriction(UserManager.DISALLOW_USER_SWITCH)) { |
| 296 | return false; |
| 297 | } |
| 298 | int switchableUserCount = 0; |
| 299 | for (UserInfo user : userManager.getUsers(true)) { |
| 300 | if (user.supportsSwitchToByUser()) { |
| 301 | ++switchableUserCount; |
| 302 | if (switchableUserCount > 1) { |
| 303 | return true; |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | return getResources().getBoolean(R.bool.qs_show_user_switcher_for_single_user); |
| 308 | } |
| 309 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 310 | private void updateListeners() { |
| 311 | if (mListening) { |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 312 | mUserInfoController.addCallback(this); |
| 313 | if (Dependency.get(NetworkController.class).hasVoiceCallingFeature()) { |
| 314 | Dependency.get(NetworkController.class).addEmergencyListener(this); |
| 315 | Dependency.get(NetworkController.class).addCallback(this); |
| 316 | } |
| 317 | } else { |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 318 | mUserInfoController.removeCallback(this); |
| 319 | Dependency.get(NetworkController.class).removeEmergencyListener(this); |
| 320 | Dependency.get(NetworkController.class).removeCallback(this); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void setQSPanel(final QSPanel qsPanel) { |
| 326 | mQsPanel = qsPanel; |
| 327 | if (mQsPanel != null) { |
| 328 | mMultiUserSwitch.setQsPanel(qsPanel); |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 329 | mQsPanel.setFooterPageIndicator(mPageIndicator); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void onClick(View v) { |
Evan Laird | 00e43c4 | 2018-01-22 20:25:45 -0500 | [diff] [blame] | 335 | // Don't do anything until view are unhidden |
| 336 | if (!mExpanded) { |
| 337 | return; |
| 338 | } |
| 339 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 340 | if (v == mSettingsButton) { |
| 341 | if (!Dependency.get(DeviceProvisionedController.class).isCurrentUserSetup()) { |
| 342 | // If user isn't setup just unlock the device and dump them back at SUW. |
| 343 | mActivityStarter.postQSRunnableDismissingKeyguard(() -> { }); |
| 344 | return; |
| 345 | } |
| 346 | MetricsLogger.action(mContext, |
| 347 | mExpanded ? MetricsProto.MetricsEvent.ACTION_QS_EXPANDED_SETTINGS_LAUNCH |
| 348 | : MetricsProto.MetricsEvent.ACTION_QS_COLLAPSED_SETTINGS_LAUNCH); |
| 349 | if (mSettingsButton.isTunerClick()) { |
| 350 | Dependency.get(ActivityStarter.class).postQSRunnableDismissingKeyguard(() -> { |
| 351 | if (TunerService.isTunerEnabled(mContext)) { |
| 352 | TunerService.showResetRequest(mContext, () -> { |
| 353 | // Relaunch settings so that the tuner disappears. |
| 354 | startSettingsActivity(); |
| 355 | }); |
| 356 | } else { |
| 357 | Toast.makeText(getContext(), R.string.tuner_toast, |
| 358 | Toast.LENGTH_LONG).show(); |
| 359 | TunerService.setTunerEnabled(mContext, true); |
| 360 | } |
| 361 | startSettingsActivity(); |
| 362 | |
| 363 | }); |
| 364 | } else { |
| 365 | startSettingsActivity(); |
| 366 | } |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
| 370 | private void startSettingsActivity() { |
| 371 | mActivityStarter.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS), |
| 372 | true /* dismissShade */); |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void setEmergencyCallsOnly(boolean show) { |
| 377 | boolean changed = show != mShowEmergencyCallsOnly; |
| 378 | if (changed) { |
| 379 | mShowEmergencyCallsOnly = show; |
| 380 | if (mExpanded) { |
| 381 | updateEverything(); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
| 388 | if (picture != null && |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 389 | UserManager.get(mContext).isGuestUser(KeyguardUpdateMonitor.getCurrentUser()) && |
Jason Monk | 826b609 | 2017-08-29 11:30:52 -0400 | [diff] [blame] | 390 | !(picture instanceof UserIconDrawable)) { |
| 391 | picture = picture.getConstantState().newDrawable(mContext.getResources()).mutate(); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 392 | picture.setColorFilter( |
| 393 | Utils.getColorAttr(mContext, android.R.attr.colorForeground), |
| 394 | Mode.SRC_IN); |
| 395 | } |
| 396 | mMultiUserAvatar.setImageDrawable(picture); |
| 397 | } |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 398 | |
| 399 | private void handleUpdateState() { |
| 400 | mMobileGroup.setVisibility(mInfo.visible ? View.VISIBLE : View.GONE); |
| 401 | if (mInfo.visible) { |
| 402 | mMobileRoaming.setVisibility(mInfo.roaming ? View.VISIBLE : View.GONE); |
| 403 | mMobileRoaming.setImageTintList(ColorStateList.valueOf(mColorForeground)); |
| 404 | SignalDrawable d = new SignalDrawable(mContext); |
| 405 | d.setDarkIntensity(QuickStatusBarHeader.getColorIntensity(mColorForeground)); |
| 406 | mMobileSignal.setImageDrawable(d); |
| 407 | mMobileSignal.setImageLevel(mInfo.mobileSignalIconId); |
| 408 | |
| 409 | StringBuilder contentDescription = new StringBuilder(); |
| 410 | if (mInfo.contentDescription != null) { |
| 411 | contentDescription.append(mInfo.contentDescription).append(", "); |
| 412 | } |
| 413 | if (mInfo.roaming) { |
| 414 | contentDescription |
| 415 | .append(mContext.getString(R.string.data_connection_roaming)) |
| 416 | .append(", "); |
| 417 | } |
| 418 | // TODO: show mobile data off/no internet text for 5 seconds before carrier text |
| 419 | if (TextUtils.equals(mInfo.typeContentDescription, |
| 420 | mContext.getString(R.string.data_connection_no_internet)) |
| 421 | || TextUtils.equals(mInfo.typeContentDescription, |
Rohan Shah | 7bc3744 | 2018-04-10 00:34:50 -0400 | [diff] [blame] | 422 | mContext.getString(R.string.cell_data_off_content_description))) { |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 423 | contentDescription.append(mInfo.typeContentDescription); |
| 424 | } |
| 425 | mMobileSignal.setContentDescription(contentDescription); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void setMobileDataIndicators(NetworkController.IconState statusIcon, |
| 431 | NetworkController.IconState qsIcon, int statusType, |
| 432 | int qsType, boolean activityIn, boolean activityOut, |
| 433 | String typeContentDescription, |
| 434 | String description, boolean isWide, int subId, boolean roaming) { |
| 435 | mInfo.visible = statusIcon.visible; |
| 436 | mInfo.mobileSignalIconId = statusIcon.icon; |
| 437 | mInfo.contentDescription = statusIcon.contentDescription; |
| 438 | mInfo.typeContentDescription = typeContentDescription; |
| 439 | mInfo.roaming = roaming; |
| 440 | handleUpdateState(); |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void setNoSims(boolean hasNoSims, boolean simDetected) { |
| 445 | if (hasNoSims) { |
| 446 | mInfo.visible = false; |
| 447 | } |
| 448 | handleUpdateState(); |
| 449 | } |
| 450 | |
| 451 | private final class CellSignalState { |
| 452 | boolean visible; |
| 453 | int mobileSignalIconId; |
| 454 | public String contentDescription; |
| 455 | String typeContentDescription; |
| 456 | boolean roaming; |
| 457 | } |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 458 | } |