blob: 72245999b0840b0eabe0d9a21d58fb20414768b3 [file] [log] [blame]
Jason Monke5b770e2017-03-03 21:49:29 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.qs;
16
Charles Hece2a7c02017-10-11 20:25:20 +010017import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS;
Evan Laird4bf21df2018-10-22 14:24:32 -040018import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
Charles Hece2a7c02017-10-11 20:25:20 +010019
Jason Monkea54e8a2018-12-20 10:01:48 -050020import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
21
Rohan Shahd3cf7562018-02-23 11:12:28 -080022import android.animation.Animator;
23import android.animation.AnimatorListenerAdapter;
Amin Shaikh0e003312018-03-08 11:39:01 -050024import android.annotation.ColorInt;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080025import android.app.ActivityManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080026import android.app.AlarmManager;
Fabian Kozynski12638242018-10-12 15:33:41 -040027import android.app.Dialog;
Amin Shaikh761c5662018-03-27 16:55:43 -040028import android.content.BroadcastReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050029import android.content.Context;
Evan Laird4ea2a492018-01-22 11:29:12 -050030import android.content.Intent;
Amin Shaikh761c5662018-03-27 16:55:43 -040031import android.content.IntentFilter;
Jason Monke5b770e2017-03-03 21:49:29 -050032import android.content.res.Configuration;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000033import android.content.res.Resources;
Evan Laird4bf21df2018-10-22 14:24:32 -040034import android.database.ContentObserver;
Jason Monke5b770e2017-03-03 21:49:29 -050035import android.graphics.Color;
36import android.graphics.Rect;
Amin Shaikh761c5662018-03-27 16:55:43 -040037import android.media.AudioManager;
Evan Laird4bf21df2018-10-22 14:24:32 -040038import android.net.Uri;
Rohan Shahd3cf7562018-02-23 11:12:28 -080039import android.os.Handler;
Fabian Kozynski12638242018-10-12 15:33:41 -040040import android.os.Looper;
Evan Laird4ea2a492018-01-22 11:29:12 -050041import android.provider.AlarmClock;
Evan Laird4bf21df2018-10-22 14:24:32 -040042import android.provider.Settings;
Beverlyb9826dd2018-04-12 15:02:45 -040043import android.service.notification.ZenModeConfig;
Rohan Shahd3cf7562018-02-23 11:12:28 -080044import android.text.format.DateUtils;
Jason Monke5b770e2017-03-03 21:49:29 -050045import android.util.AttributeSet;
Rohan Shaha160ab12018-03-09 15:47:36 -080046import android.util.Log;
Adrian Roos13836052018-03-15 21:06:37 +010047import android.util.Pair;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050048import android.view.DisplayCutout;
Jason Monk824ffff2017-04-11 15:49:06 -040049import android.view.View;
Adrian Roos13836052018-03-15 21:06:37 +010050import android.view.WindowInsets;
Fabian Kozynski12638242018-10-12 15:33:41 -040051import android.view.WindowManager;
Beverlyff2df9b2018-10-10 16:54:10 -040052import android.widget.FrameLayout;
Amin Shaikh761c5662018-03-27 16:55:43 -040053import android.widget.ImageView;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050054import android.widget.LinearLayout;
Jason Monke5b770e2017-03-03 21:49:29 -050055import android.widget.RelativeLayout;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050056import android.widget.Space;
Rohan Shahd3cf7562018-02-23 11:12:28 -080057import android.widget.TextView;
Jason Monke5b770e2017-03-03 21:49:29 -050058
Beverlyff2df9b2018-10-10 16:54:10 -040059import androidx.annotation.VisibleForTesting;
60
Jason Monke5b770e2017-03-03 21:49:29 -050061import com.android.settingslib.Utils;
62import com.android.systemui.BatteryMeterView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080063import com.android.systemui.Prefs;
Jason Monke5b770e2017-03-03 21:49:29 -050064import com.android.systemui.R;
65import com.android.systemui.plugins.ActivityStarter;
Beverly1be62f42018-12-19 17:17:48 -050066import com.android.systemui.plugins.DarkIconDispatcher;
67import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
Fabian Kozynski12638242018-10-12 15:33:41 -040068import com.android.systemui.privacy.OngoingPrivacyChip;
69import com.android.systemui.privacy.OngoingPrivacyDialog;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050070import com.android.systemui.privacy.PrivacyItem;
71import com.android.systemui.privacy.PrivacyItemController;
Jason Monke5b770e2017-03-03 21:49:29 -050072import com.android.systemui.qs.QSDetail.Callback;
Adrian Roos13836052018-03-15 21:06:37 +010073import com.android.systemui.statusbar.phone.PhoneStatusBarView;
Evan Laird95896952018-01-22 19:30:05 -050074import com.android.systemui.statusbar.phone.StatusBarIconController;
75import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Evan Laird20b87bf2018-04-12 09:54:11 -040076import com.android.systemui.statusbar.phone.StatusIconContainer;
Fabian Kozynski12638242018-10-12 15:33:41 -040077import com.android.systemui.statusbar.phone.SystemUIDialog;
Evan Laird4bf21df2018-10-22 14:24:32 -040078import com.android.systemui.statusbar.policy.BatteryController;
Beverlyff2df9b2018-10-10 16:54:10 -040079import com.android.systemui.statusbar.policy.Clock;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000080import com.android.systemui.statusbar.policy.DateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080081import com.android.systemui.statusbar.policy.NextAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -040082import com.android.systemui.statusbar.policy.ZenModeController;
Jason Monke5b770e2017-03-03 21:49:29 -050083
Fabian Kozynski8d06c712018-11-07 10:33:02 -050084import java.util.List;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080085import java.util.Locale;
Beverlyb9826dd2018-04-12 15:02:45 -040086import java.util.Objects;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080087
Jason Monkea54e8a2018-12-20 10:01:48 -050088import javax.inject.Inject;
89import javax.inject.Named;
90
Rohan Shahd3cf7562018-02-23 11:12:28 -080091/**
92 * View that contains the top-most bits of the screen (primarily the status bar with date, time, and
93 * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner
94 * contents.
95 */
Amin Shaikhf09450b2018-04-06 17:32:45 -040096public class QuickStatusBarHeader extends RelativeLayout implements
Beverlyb9826dd2018-04-12 15:02:45 -040097 View.OnClickListener, NextAlarmController.NextAlarmChangeCallback,
98 ZenModeController.Callback {
Rohan Shaha160ab12018-03-09 15:47:36 -080099 private static final String TAG = "QuickStatusBarHeader";
100 private static final boolean DEBUG = false;
Jason Monke5b770e2017-03-03 21:49:29 -0500101
Rohan Shahd3cf7562018-02-23 11:12:28 -0800102 /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */
103 private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6;
104 private static final int FADE_ANIMATION_DURATION_MS = 300;
105 private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0;
Rohan Shahb6a915c2018-03-01 11:57:00 -0800106 public static final int MAX_TOOLTIP_SHOWN_COUNT = 2;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800107
108 private final Handler mHandler = new Handler();
Jason Monkea54e8a2018-12-20 10:01:48 -0500109 private final BatteryController mBatteryController;
110 private final NextAlarmController mAlarmController;
111 private final ZenModeController mZenController;
112 private final StatusBarIconController mStatusBarIconController;
113 private final ActivityStarter mActivityStarter;
Jason Monke5b770e2017-03-03 21:49:29 -0500114
115 private QSPanel mQsPanel;
116
117 private boolean mExpanded;
118 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +0100119 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -0500120
121 protected QuickQSPanel mHeaderQsPanel;
122 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -0500123 private TintedIconManager mIconManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800124 private TouchAnimator mStatusIconsAlphaAnimator;
125 private TouchAnimator mHeaderTextContainerAlphaAnimator;
Evan Laird95896952018-01-22 19:30:05 -0500126
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000127 private View mSystemIconsView;
Evan Laird95896952018-01-22 19:30:05 -0500128 private View mQuickQsStatusIcons;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800129 private View mHeaderTextContainerView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400130 /** View containing the next alarm and ringer mode info. */
131 private View mStatusContainer;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800132 /** Tooltip for educating users that they can long press on icons to see more details. */
133 private View mLongPressTooltipView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400134
135 private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
136 private AlarmManager.AlarmClockInfo mNextAlarm;
137
138 private ImageView mNextAlarmIcon;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800139 /** {@link TextView} containing the actual text indicating when the next alarm will go off. */
140 private TextView mNextAlarmTextView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400141 private View mStatusSeparator;
142 private ImageView mRingerModeIcon;
143 private TextView mRingerModeTextView;
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000144 private BatteryMeterView mBatteryMeterView;
145 private Clock mClockView;
146 private DateView mDateView;
Fabian Kozynski12638242018-10-12 15:33:41 -0400147 private OngoingPrivacyChip mPrivacyChip;
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500148 private Space mSpace;
Evan Laird4bf21df2018-10-22 14:24:32 -0400149 private BatteryMeterView mBatteryRemainingIcon;
150 private TextView mBatteryRemainingText;
151 private boolean mShowBatteryPercentAndEstimate;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800152
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500153 private PrivacyItemController mPrivacyItemController;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800154 /** Counts how many times the long press tooltip has been shown to the user. */
155 private int mShownCount;
156
Amin Shaikh761c5662018-03-27 16:55:43 -0400157 private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() {
158 @Override
159 public void onReceive(Context context, Intent intent) {
160 mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1);
161 updateStatusText();
162 }
163 };
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500164 private boolean mHasTopCutout = false;
Amin Shaikh761c5662018-03-27 16:55:43 -0400165
Evan Laird4bf21df2018-10-22 14:24:32 -0400166 private final PercentSettingObserver mPercentSettingObserver =
167 new PercentSettingObserver(new Handler(mContext.getMainLooper()));
168
Rohan Shahd3cf7562018-02-23 11:12:28 -0800169 /**
170 * Runnable for automatically fading out the long press tooltip (as if it were animating away).
171 */
172 private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false);
Evan Laird4ea2a492018-01-22 11:29:12 -0500173
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500174 private PrivacyItemController.Callback mPICCallback = new PrivacyItemController.Callback() {
175 @Override
176 public void privacyChanged(List<PrivacyItem> privacyItems) {
177 mPrivacyChip.setPrivacyList(privacyItems);
178 setChipVisibility(!privacyItems.isEmpty());
179 }
180 };
181
Jason Monkea54e8a2018-12-20 10:01:48 -0500182 @Inject
183 public QuickStatusBarHeader(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs,
184 NextAlarmController nextAlarmController, ZenModeController zenModeController,
185 BatteryController batteryController, StatusBarIconController statusBarIconController,
186 ActivityStarter activityStarter) {
Jason Monke5b770e2017-03-03 21:49:29 -0500187 super(context, attrs);
Jason Monkea54e8a2018-12-20 10:01:48 -0500188 mAlarmController = nextAlarmController;
189 mZenController = zenModeController;
190 mBatteryController = batteryController;
191 mStatusBarIconController = statusBarIconController;
192 mActivityStarter = activityStarter;
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500193 mPrivacyItemController = new PrivacyItemController(context, mPICCallback);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800194 mShownCount = getStoredShownCount();
Jason Monke5b770e2017-03-03 21:49:29 -0500195 }
196
197 @Override
198 protected void onFinishInflate() {
199 super.onFinishInflate();
Jason Monke5b770e2017-03-03 21:49:29 -0500200
201 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000202 mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons);
Evan Laird95896952018-01-22 19:30:05 -0500203 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
Evan Laird20b87bf2018-04-12 09:54:11 -0400204 StatusIconContainer iconContainer = findViewById(R.id.statusIcons);
205 iconContainer.setShouldRestrictIcons(false);
206 mIconManager = new TintedIconManager(iconContainer);
Jason Monke5b770e2017-03-03 21:49:29 -0500207
Rohan Shahd3cf7562018-02-23 11:12:28 -0800208 // Views corresponding to the header info section (e.g. tooltip and next alarm).
209 mHeaderTextContainerView = findViewById(R.id.header_text_container);
210 mLongPressTooltipView = findViewById(R.id.long_press_tooltip);
Amin Shaikh761c5662018-03-27 16:55:43 -0400211 mStatusContainer = findViewById(R.id.status_container);
212 mStatusSeparator = findViewById(R.id.status_separator);
213 mNextAlarmIcon = findViewById(R.id.next_alarm_icon);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800214 mNextAlarmTextView = findViewById(R.id.next_alarm_text);
Amin Shaikh761c5662018-03-27 16:55:43 -0400215 mRingerModeIcon = findViewById(R.id.ringer_mode_icon);
216 mRingerModeTextView = findViewById(R.id.ringer_mode_text);
Jason Monke5b770e2017-03-03 21:49:29 -0500217
218 updateResources();
219
Jason Monk824ffff2017-04-11 15:49:06 -0400220 Rect tintArea = new Rect(0, 0, 0, 0);
Jason Changb4e879d2018-04-11 11:17:58 +0800221 int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
222 android.R.attr.colorForeground);
Amin Shaikh0e003312018-03-08 11:39:01 -0500223 float intensity = getColorIntensity(colorForeground);
Evan Laird95896952018-01-22 19:30:05 -0500224 int fillColor = fillColorForIntensity(intensity, getContext());
225
226 // Set light text on the header icons because they will always be on a black background
Evan Laird39254d42018-01-18 16:05:30 -0500227 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -0500228
229 // Set the correct tint for the status icons so they contrast
230 mIconManager.setTint(fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500231
Evan Laird4bf21df2018-10-22 14:24:32 -0400232 mShowBatteryPercentAndEstimate = mContext.getResources().getBoolean(
233 com.android.internal.R.bool.config_battery_percentage_setting_available);
234
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000235 mBatteryMeterView = findViewById(R.id.battery);
Evan Laird4bf21df2018-10-22 14:24:32 -0400236 mBatteryMeterView.setPercentShowMode(mShowBatteryPercentAndEstimate
237 ? BatteryMeterView.MODE_ON : BatteryMeterView.MODE_OFF);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400238 mBatteryMeterView.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000239 mClockView = findViewById(R.id.clock);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400240 mClockView.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000241 mDateView = findViewById(R.id.date);
Fabian Kozynski12638242018-10-12 15:33:41 -0400242 mPrivacyChip = findViewById(R.id.privacy_chip);
243 mPrivacyChip.setOnClickListener(this);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500244 mSpace = findViewById(R.id.space);
Evan Laird4bf21df2018-10-22 14:24:32 -0400245
246 // Tint for the battery icons are handled in setupHost()
247 mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon);
248 mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_OFF);
Evan Laird698839b2018-12-05 15:49:12 -0500249 // Don't need to worry about tuner settings for this icon
250 mBatteryRemainingIcon.setIgnoreTunerUpdates(true);
Evan Laird4bf21df2018-10-22 14:24:32 -0400251
252 mBatteryRemainingText = findViewById(R.id.batteryRemainingText);
253 mBatteryRemainingText.setTextColor(fillColor);
254
255 updateShowPercent();
Jason Monke5b770e2017-03-03 21:49:29 -0500256 }
257
Amin Shaikh761c5662018-03-27 16:55:43 -0400258 private void updateStatusText() {
Beverlyb9826dd2018-04-12 15:02:45 -0400259 boolean changed = updateRingerStatus() || updateAlarmStatus();
260
261 if (changed) {
262 boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
263 boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
264 mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE
265 : View.GONE);
266 updateTooltipShow();
267 }
268 }
269
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500270 private void setChipVisibility(boolean chipVisible) {
271 mBatteryMeterView.setVisibility(View.VISIBLE);
272 if (chipVisible) {
273 mPrivacyChip.setVisibility(View.VISIBLE);
274 if (mHasTopCutout) mBatteryMeterView.setVisibility(View.GONE);
275 } else {
276 mPrivacyChip.setVisibility(View.GONE);
277 }
278 }
279
Beverlyb9826dd2018-04-12 15:02:45 -0400280 private boolean updateRingerStatus() {
281 boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
282 CharSequence originalRingerText = mRingerModeTextView.getText();
283
Amin Shaikh761c5662018-03-27 16:55:43 -0400284 boolean ringerVisible = false;
Beverlyb9826dd2018-04-12 15:02:45 -0400285 if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(),
Beverlyff2df9b2018-10-10 16:54:10 -0400286 mZenController.getConsolidatedPolicy())) {
Beverlyb9826dd2018-04-12 15:02:45 -0400287 if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
288 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate);
289 mRingerModeTextView.setText(R.string.qs_status_phone_vibrate);
290 ringerVisible = true;
291 } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
292 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent);
293 mRingerModeTextView.setText(R.string.qs_status_phone_muted);
294 ringerVisible = true;
295 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400296 }
297 mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
298 mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
299
Beverlyb9826dd2018-04-12 15:02:45 -0400300 return isOriginalVisible != ringerVisible ||
301 !Objects.equals(originalRingerText, mRingerModeTextView.getText());
302 }
303
304 private boolean updateAlarmStatus() {
305 boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
306 CharSequence originalAlarmText = mNextAlarmTextView.getText();
307
Amin Shaikh761c5662018-03-27 16:55:43 -0400308 boolean alarmVisible = false;
309 if (mNextAlarm != null) {
310 alarmVisible = true;
311 mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm));
312 }
313 mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
314 mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400315
Beverlyb9826dd2018-04-12 15:02:45 -0400316 return isOriginalVisible != alarmVisible ||
317 !Objects.equals(originalAlarmText, mNextAlarmTextView.getText());
318 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400319
Jason Monk824ffff2017-04-11 15:49:06 -0400320 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
321 View v = findViewById(id);
322 if (v instanceof DarkReceiver) {
323 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
324 }
325 }
326
Evan Laird95896952018-01-22 19:30:05 -0500327 private int fillColorForIntensity(float intensity, Context context) {
328 if (intensity == 0) {
Amin Shaikh9cac3382018-04-11 17:10:07 -0400329 return context.getColor(R.color.light_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500330 }
Amin Shaikh9cac3382018-04-11 17:10:07 -0400331 return context.getColor(R.color.dark_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500332 }
333
Jason Monke5b770e2017-03-03 21:49:29 -0500334 @Override
335 protected void onConfigurationChanged(Configuration newConfig) {
336 super.onConfigurationChanged(newConfig);
337 updateResources();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000338
339 // Update color schemes in landscape to use wallpaperTextColor
340 boolean shouldUseWallpaperTextColor =
341 newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
342 mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor);
343 mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500344 }
345
Fabian Kozynskief124492018-11-02 11:02:11 -0400346
347
Jason Monke5b770e2017-03-03 21:49:29 -0500348 @Override
349 public void onRtlPropertiesChanged(int layoutDirection) {
350 super.onRtlPropertiesChanged(layoutDirection);
351 updateResources();
352 }
353
Evan Laird84b98952018-07-02 17:43:59 -0400354 /**
355 * The height of QQS should always be the status bar height + 128dp. This is normally easy, but
356 * when there is a notch involved the status bar can remain a fixed pixel size.
357 */
358 private void updateMinimumHeight() {
359 int sbHeight = mContext.getResources().getDimensionPixelSize(
360 com.android.internal.R.dimen.status_bar_height);
361 int qqsHeight = mContext.getResources().getDimensionPixelSize(
362 R.dimen.qs_quick_header_panel_height);
363
364 setMinimumHeight(sbHeight + qqsHeight);
365 }
366
Jason Monke5b770e2017-03-03 21:49:29 -0500367 private void updateResources() {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000368 Resources resources = mContext.getResources();
Evan Laird84b98952018-07-02 17:43:59 -0400369 updateMinimumHeight();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000370
371 // Update height for a few views, especially due to landscape mode restricting space.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800372 mHeaderTextContainerView.getLayoutParams().height =
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000373 resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800374 mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams());
375
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000376 mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize(
377 com.android.internal.R.dimen.quick_qs_offset_height);
378 mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
379
Evan Laird84b98952018-07-02 17:43:59 -0400380 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
381 if (mQsDisabled) {
382 lp.height = resources.getDimensionPixelSize(
383 com.android.internal.R.dimen.quick_qs_offset_height);
384 } else {
385 lp.height = Math.max(getMinimumHeight(),
386 resources.getDimensionPixelSize(
Evan Lairdbf3794a2018-07-17 15:55:40 -0400387 com.android.internal.R.dimen.quick_qs_total_height));
Evan Laird84b98952018-07-02 17:43:59 -0400388 }
389
390 setLayoutParams(lp);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000391
Fabian Kozynskief124492018-11-02 11:02:11 -0400392 if (mPrivacyChip != null) {
393 MarginLayoutParams lm = (MarginLayoutParams) mPrivacyChip.getLayoutParams();
394 int sideMargins = lm.leftMargin;
395 int topBottomMargins = resources.getDimensionPixelSize(
396 R.dimen.ongoing_appops_top_chip_margin);
397 lm.setMargins(sideMargins, topBottomMargins, sideMargins, topBottomMargins);
398 mPrivacyChip.setLayoutParams(lm);
399 }
400
Rohan Shahd3cf7562018-02-23 11:12:28 -0800401 updateStatusIconAlphaAnimator();
402 updateHeaderTextContainerAlphaAnimator();
Evan Laird95896952018-01-22 19:30:05 -0500403 }
404
Rohan Shahd3cf7562018-02-23 11:12:28 -0800405 private void updateStatusIconAlphaAnimator() {
406 mStatusIconsAlphaAnimator = new TouchAnimator.Builder()
Evan Laird95896952018-01-22 19:30:05 -0500407 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
408 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500409 }
410
Rohan Shahd3cf7562018-02-23 11:12:28 -0800411 private void updateHeaderTextContainerAlphaAnimator() {
412 mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder()
413 .addFloat(mHeaderTextContainerView, "alpha", 0, 1)
414 .setStartDelay(.5f)
415 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500416 }
417
Evan Laird4bf21df2018-10-22 14:24:32 -0400418 private void updateBatteryRemainingText() {
419 if (!mShowBatteryPercentAndEstimate) {
420 return;
421 }
Jason Monkea54e8a2018-12-20 10:01:48 -0500422 mBatteryRemainingText.setText(mBatteryController.getEstimatedTimeRemainingString());
Evan Laird4bf21df2018-10-22 14:24:32 -0400423 }
424
Jason Monke5b770e2017-03-03 21:49:29 -0500425 public void setExpanded(boolean expanded) {
426 if (mExpanded == expanded) return;
427 mExpanded = expanded;
428 mHeaderQsPanel.setExpanded(expanded);
Jason Monke5b770e2017-03-03 21:49:29 -0500429 }
430
Rohan Shahd3cf7562018-02-23 11:12:28 -0800431 /**
432 * Animates the inner contents based on the given expansion details.
433 *
434 * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen)
435 * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f)
436 * @param panelTranslationY how much the panel has physically moved down vertically (required
437 * for keyguard animations only)
438 */
439 public void setExpansion(boolean isKeyguardShowing, float expansionFraction,
440 float panelTranslationY) {
441 final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction;
442 if (mStatusIconsAlphaAnimator != null) {
443 mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction);
Evan Laird95896952018-01-22 19:30:05 -0500444 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800445
446 if (isKeyguardShowing) {
447 // If the keyguard is showing, we want to offset the text so that it comes in at the
448 // same time as the panel as it slides down.
449 mHeaderTextContainerView.setTranslationY(panelTranslationY);
450 } else {
451 mHeaderTextContainerView.setTranslationY(0f);
452 }
453
454 if (mHeaderTextContainerAlphaAnimator != null) {
455 mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction);
456 }
457
458 // Check the original expansion fraction - we don't want to show the tooltip until the
459 // panel is pulled all the way out.
460 if (expansionFraction == 1f) {
461 // QS is fully expanded, bring in the tooltip.
462 showLongPressTooltip();
463 }
464 }
465
466 /** Returns the latest stored tooltip shown count from SharedPreferences. */
467 private int getStoredShownCount() {
468 return Prefs.getInt(
469 mContext,
470 Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
471 TOOLTIP_NOT_YET_SHOWN_COUNT);
Jason Monke5b770e2017-03-03 21:49:29 -0500472 }
473
Charles Hece2a7c02017-10-11 20:25:20 +0100474 public void disable(int state1, int state2, boolean animate) {
475 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
476 if (disabled == mQsDisabled) return;
477 mQsDisabled = disabled;
478 mHeaderQsPanel.setDisabledByPolicy(disabled);
Amin Shaikhf09450b2018-04-06 17:32:45 -0400479 mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
480 mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
481 updateResources();
Charles Hece2a7c02017-10-11 20:25:20 +0100482 }
483
484 @Override
485 public void onAttachedToWindow() {
Amin Shaikha59215a2018-04-23 08:52:38 -0400486 super.onAttachedToWindow();
Jason Monkea54e8a2018-12-20 10:01:48 -0500487 mStatusBarIconController.addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100488 requestApplyInsets();
Evan Laird4bf21df2018-10-22 14:24:32 -0400489 mContext.getContentResolver().registerContentObserver(
490 Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mPercentSettingObserver,
491 ActivityManager.getCurrentUser());
Adrian Roos13836052018-03-15 21:06:37 +0100492 }
493
494 @Override
495 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500496 DisplayCutout cutout = insets.getDisplayCutout();
Adrian Roos13836052018-03-15 21:06:37 +0100497 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500498 cutout, getDisplay());
Adrian Roos13836052018-03-15 21:06:37 +0100499 if (padding == null) {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400500 mSystemIconsView.setPaddingRelative(
501 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0,
502 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0);
Adrian Roos13836052018-03-15 21:06:37 +0100503 } else {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400504 mSystemIconsView.setPadding(padding.first, 0, padding.second, 0);
505
Adrian Roos13836052018-03-15 21:06:37 +0100506 }
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500507 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mSpace.getLayoutParams();
508 if (cutout != null) {
509 Rect topCutout = cutout.getBoundingRectTop();
510 if (topCutout.isEmpty()) {
511 mHasTopCutout = false;
512 lp.width = 0;
513 mSpace.setVisibility(View.GONE);
514 } else {
515 mHasTopCutout = true;
516 lp.width = topCutout.width();
517 mSpace.setVisibility(View.VISIBLE);
518 }
519 }
520 mSpace.setLayoutParams(lp);
521 // Decide whether to show BatteryMeterView
522 setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE);
Adrian Roos13836052018-03-15 21:06:37 +0100523 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100524 }
525
526 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500527 @VisibleForTesting
528 public void onDetachedFromWindow() {
529 setListening(false);
Jason Monkea54e8a2018-12-20 10:01:48 -0500530 mStatusBarIconController.removeIconGroup(mIconManager);
Evan Laird4bf21df2018-10-22 14:24:32 -0400531 mContext.getContentResolver().unregisterContentObserver(mPercentSettingObserver);
Jason Monke5b770e2017-03-03 21:49:29 -0500532 super.onDetachedFromWindow();
533 }
534
535 public void setListening(boolean listening) {
536 if (listening == mListening) {
537 return;
538 }
539 mHeaderQsPanel.setListening(listening);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500540 mPrivacyItemController.setListening(listening);
Jason Monke5b770e2017-03-03 21:49:29 -0500541 mListening = listening;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800542
543 if (listening) {
Beverlyb9826dd2018-04-12 15:02:45 -0400544 mZenController.addCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800545 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400546 mContext.registerReceiver(mRingerReceiver,
547 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Evan Laird4bf21df2018-10-22 14:24:32 -0400548 updateBatteryRemainingText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800549 } else {
Beverlyb9826dd2018-04-12 15:02:45 -0400550 mZenController.removeCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800551 mAlarmController.removeCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400552 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800553 }
Jason Monke5b770e2017-03-03 21:49:29 -0500554 }
555
Evan Laird95896952018-01-22 19:30:05 -0500556 @Override
557 public void onClick(View v) {
Amin Shaikh39bdc502018-05-15 23:43:34 -0400558 if (v == mClockView) {
Jason Monkea54e8a2018-12-20 10:01:48 -0500559 mActivityStarter.postStartActivityDismissingKeyguard(new Intent(
Evan Laird95896952018-01-22 19:30:05 -0500560 AlarmClock.ACTION_SHOW_ALARMS),0);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400561 } else if (v == mBatteryMeterView) {
Jason Monkea54e8a2018-12-20 10:01:48 -0500562 mActivityStarter.postStartActivityDismissingKeyguard(new Intent(
Amin Shaikh39bdc502018-05-15 23:43:34 -0400563 Intent.ACTION_POWER_USAGE_SUMMARY),0);
Fabian Kozynski12638242018-10-12 15:33:41 -0400564 } else if (v == mPrivacyChip) {
565 Handler mUiHandler = new Handler(Looper.getMainLooper());
566 mUiHandler.post(() -> {
567 Dialog mDialog = new OngoingPrivacyDialog(mContext,
568 mPrivacyChip.getBuilder()).createDialog();
569 mDialog.getWindow().setType(
570 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
571 SystemUIDialog.setShowForAllUsers(mDialog, true);
572 SystemUIDialog.registerDismissListener(mDialog);
573 SystemUIDialog.setWindowOnTop(mDialog);
574 mUiHandler.post(() -> mDialog.show());
575 mHost.collapsePanels();
576 });
Evan Laird95896952018-01-22 19:30:05 -0500577 }
578 }
579
Rohan Shahd3cf7562018-02-23 11:12:28 -0800580 @Override
581 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400582 mNextAlarm = nextAlarm;
583 updateStatusText();
584 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800585
Beverlyb9826dd2018-04-12 15:02:45 -0400586 @Override
587 public void onZenChanged(int zen) {
588 updateStatusText();
589
590 }
591
592 @Override
593 public void onConfigChanged(ZenModeConfig config) {
594 updateStatusText();
595 }
596
Amin Shaikh761c5662018-03-27 16:55:43 -0400597 private void updateTooltipShow() {
598 if (hasStatusText()) {
599 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800600 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400601 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800602 }
603 updateHeaderTextContainerAlphaAnimator();
604 }
605
Amin Shaikh761c5662018-03-27 16:55:43 -0400606 private boolean hasStatusText() {
607 return mNextAlarmTextView.getVisibility() == View.VISIBLE
608 || mRingerModeTextView.getVisibility() == View.VISIBLE;
609 }
610
Rohan Shahd3cf7562018-02-23 11:12:28 -0800611 /**
612 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
613 * the space).
614 */
615 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400616 // If we have status text to show, don't bother fading in the tooltip.
617 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800618 return;
619 }
620
621 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
622 mLongPressTooltipView.animate().cancel();
623 mLongPressTooltipView.setVisibility(View.VISIBLE);
624 mLongPressTooltipView.animate()
625 .alpha(1f)
626 .setDuration(FADE_ANIMATION_DURATION_MS)
627 .setListener(new AnimatorListenerAdapter() {
628 @Override
629 public void onAnimationEnd(Animator animation) {
630 mHandler.postDelayed(
631 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
632 }
633 })
634 .start();
635
636 // Increment and drop the shown count in prefs for the next time we're deciding to
637 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
638 // in prefs (say, from a long press).
639 if (getStoredShownCount() <= mShownCount) {
640 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
641 }
642 }
643 }
644
645 /**
646 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400647 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800648 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400649 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800650 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400651 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800652 mLongPressTooltipView.animate().cancel();
653 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
654 && mLongPressTooltipView.getAlpha() != 0f) {
655 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
656 mLongPressTooltipView.animate()
657 .alpha(0f)
658 .setDuration(FADE_ANIMATION_DURATION_MS)
659 .setListener(new AnimatorListenerAdapter() {
660 @Override
661 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800662 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800663 mLongPressTooltipView.setVisibility(View.INVISIBLE);
664
Amin Shaikh761c5662018-03-27 16:55:43 -0400665 if (shouldShowStatusText) {
666 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800667 }
668 }
669 })
670 .start();
671 } else {
672 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400673 if (shouldShowStatusText) {
674 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800675 }
676 }
677 }
678
679 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400680 * Fades in the updated status text. Note that if there's already a status showing, this will
Fabian Kozynski3f789332018-09-04 16:42:43 -0400681 * immediately fade it out and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800682 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400683 private void showStatus() {
684 mStatusContainer.setAlpha(0f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800685
Amin Shaikh761c5662018-03-27 16:55:43 -0400686 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800687 .alpha(1f)
688 .setDuration(FADE_ANIMATION_DURATION_MS)
689 .start();
690 }
691
Fabian Kozynski3f789332018-09-04 16:42:43 -0400692 /** Fades out the status text. */
Amin Shaikh761c5662018-03-27 16:55:43 -0400693 private void hideStatusText() {
Fabian Kozynski3f789332018-09-04 16:42:43 -0400694 mStatusContainer.animate()
695 .alpha(0f)
696 .setDuration(FADE_ANIMATION_DURATION_MS)
697 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800698 }
699
Jason Monke5b770e2017-03-03 21:49:29 -0500700 public void setQSPanel(final QSPanel qsPanel) {
701 mQsPanel = qsPanel;
702 setupHost(qsPanel.getHost());
703 }
704
705 public void setupHost(final QSTileHost host) {
706 mHost = host;
707 //host.setHeaderView(mExpandIndicator);
708 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
709 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500710
711 // Use SystemUI context to get battery meter colors, and let it use the default tint (white)
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000712 mBatteryMeterView.setColorsFromContext(mHost.getContext());
713 mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird4bf21df2018-10-22 14:24:32 -0400714
715 Rect tintArea = new Rect(0, 0, 0, 0);
716 int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
717 android.R.attr.colorForeground);
718 float intensity = getColorIntensity(colorForeground);
719 int fillColor = fillColorForIntensity(intensity, getContext());
720 mBatteryRemainingIcon.setColorsFromContext(mHost.getContext());
721 mBatteryRemainingIcon.onDarkChanged(tintArea, intensity, fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500722 }
723
724 public void setCallback(Callback qsPanelCallback) {
725 mHeaderQsPanel.setCallback(qsPanelCallback);
726 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800727
728 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
729 if (info == null) {
730 return "";
731 }
732 String skeleton = android.text.format.DateFormat
733 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
734 String pattern = android.text.format.DateFormat
735 .getBestDateTimePattern(Locale.getDefault(), skeleton);
736 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
737 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500738
739 public static float getColorIntensity(@ColorInt int color) {
740 return color == Color.WHITE ? 0 : 1;
741 }
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400742
743 public void setMargins(int sideMargins) {
744 for (int i = 0; i < getChildCount(); i++) {
745 View v = getChildAt(i);
Fabian Kozynskief124492018-11-02 11:02:11 -0400746 if (v == mSystemIconsView || v == mQuickQsStatusIcons || v == mHeaderQsPanel
747 || v == mPrivacyChip) {
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400748 continue;
749 }
750 RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams();
751 lp.leftMargin = sideMargins;
752 lp.rightMargin = sideMargins;
753 }
754 }
Evan Laird4bf21df2018-10-22 14:24:32 -0400755
756 private void updateShowPercent() {
757 final boolean systemSetting = 0 != Settings.System
758 .getIntForUser(getContext().getContentResolver(),
759 SHOW_BATTERY_PERCENT, 0, ActivityManager.getCurrentUser());
760
761 mShowBatteryPercentAndEstimate = systemSetting;
762
763 updateBatteryViews();
764 }
765
766 private void updateBatteryViews() {
767 if (mShowBatteryPercentAndEstimate) {
768 mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ON);
769 mBatteryRemainingIcon.setVisibility(View.VISIBLE);
770 mBatteryRemainingText.setVisibility(View.VISIBLE);
771 updateBatteryRemainingText();
772 } else {
773 mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_OFF);
774 mBatteryRemainingIcon.setVisibility(View.GONE);
775 mBatteryRemainingText.setVisibility(View.GONE);
776 }
777 }
778
779 private final class PercentSettingObserver extends ContentObserver {
780 PercentSettingObserver(Handler handler) {
781 super(handler);
782 }
783
784 @Override
785 public void onChange(boolean selfChange, Uri uri) {
786 super.onChange(selfChange, uri);
787 updateShowPercent();
788 }
789 }
Jason Monke5b770e2017-03-03 21:49:29 -0500790}