blob: 427f638b0d30c291b45b00dee2ce9f4e4167c513 [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
Rohan Shahd3cf7562018-02-23 11:12:28 -080020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
Amin Shaikh0e003312018-03-08 11:39:01 -050022import android.annotation.ColorInt;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080023import android.app.ActivityManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080024import android.app.AlarmManager;
Fabian Kozynski12638242018-10-12 15:33:41 -040025import android.app.Dialog;
Amin Shaikh761c5662018-03-27 16:55:43 -040026import android.content.BroadcastReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050027import android.content.Context;
Evan Laird4ea2a492018-01-22 11:29:12 -050028import android.content.Intent;
Amin Shaikh761c5662018-03-27 16:55:43 -040029import android.content.IntentFilter;
Jason Monke5b770e2017-03-03 21:49:29 -050030import android.content.res.Configuration;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000031import android.content.res.Resources;
Evan Laird4bf21df2018-10-22 14:24:32 -040032import android.database.ContentObserver;
Jason Monke5b770e2017-03-03 21:49:29 -050033import android.graphics.Color;
34import android.graphics.Rect;
Amin Shaikh761c5662018-03-27 16:55:43 -040035import android.media.AudioManager;
Evan Laird4bf21df2018-10-22 14:24:32 -040036import android.net.Uri;
Rohan Shahd3cf7562018-02-23 11:12:28 -080037import android.os.Handler;
Fabian Kozynski12638242018-10-12 15:33:41 -040038import android.os.Looper;
Evan Laird4ea2a492018-01-22 11:29:12 -050039import android.provider.AlarmClock;
Evan Laird4bf21df2018-10-22 14:24:32 -040040import android.provider.Settings;
Beverlyb9826dd2018-04-12 15:02:45 -040041import android.service.notification.ZenModeConfig;
Rohan Shahd3cf7562018-02-23 11:12:28 -080042import android.text.format.DateUtils;
Jason Monke5b770e2017-03-03 21:49:29 -050043import android.util.AttributeSet;
Rohan Shaha160ab12018-03-09 15:47:36 -080044import android.util.Log;
Adrian Roos13836052018-03-15 21:06:37 +010045import android.util.Pair;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050046import android.view.DisplayCutout;
Jason Monk824ffff2017-04-11 15:49:06 -040047import android.view.View;
Adrian Roos13836052018-03-15 21:06:37 +010048import android.view.WindowInsets;
Fabian Kozynski12638242018-10-12 15:33:41 -040049import android.view.WindowManager;
Beverlyff2df9b2018-10-10 16:54:10 -040050import android.widget.FrameLayout;
Amin Shaikh761c5662018-03-27 16:55:43 -040051import android.widget.ImageView;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050052import android.widget.LinearLayout;
Jason Monke5b770e2017-03-03 21:49:29 -050053import android.widget.RelativeLayout;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050054import android.widget.Space;
Rohan Shahd3cf7562018-02-23 11:12:28 -080055import android.widget.TextView;
Jason Monke5b770e2017-03-03 21:49:29 -050056
Beverlyff2df9b2018-10-10 16:54:10 -040057import androidx.annotation.VisibleForTesting;
58
Jason Monke5b770e2017-03-03 21:49:29 -050059import com.android.settingslib.Utils;
60import com.android.systemui.BatteryMeterView;
61import com.android.systemui.Dependency;
Rohan Shahd3cf7562018-02-23 11:12:28 -080062import com.android.systemui.Prefs;
Jason Monke5b770e2017-03-03 21:49:29 -050063import com.android.systemui.R;
64import com.android.systemui.plugins.ActivityStarter;
Fabian Kozynski12638242018-10-12 15:33:41 -040065import com.android.systemui.privacy.OngoingPrivacyChip;
66import com.android.systemui.privacy.OngoingPrivacyDialog;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050067import com.android.systemui.privacy.PrivacyItem;
68import com.android.systemui.privacy.PrivacyItemController;
Jason Monke5b770e2017-03-03 21:49:29 -050069import com.android.systemui.qs.QSDetail.Callback;
Adrian Roos13836052018-03-15 21:06:37 +010070import com.android.systemui.statusbar.phone.PhoneStatusBarView;
Evan Laird95896952018-01-22 19:30:05 -050071import com.android.systemui.statusbar.phone.StatusBarIconController;
72import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Evan Laird20b87bf2018-04-12 09:54:11 -040073import com.android.systemui.statusbar.phone.StatusIconContainer;
Fabian Kozynski12638242018-10-12 15:33:41 -040074import com.android.systemui.statusbar.phone.SystemUIDialog;
Evan Laird4bf21df2018-10-22 14:24:32 -040075import com.android.systemui.statusbar.policy.BatteryController;
Beverlyff2df9b2018-10-10 16:54:10 -040076import com.android.systemui.statusbar.policy.Clock;
Evan Laird39254d42018-01-18 16:05:30 -050077import com.android.systemui.statusbar.policy.DarkIconDispatcher;
Jason Monk824ffff2017-04-11 15:49:06 -040078import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000079import com.android.systemui.statusbar.policy.DateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080080import com.android.systemui.statusbar.policy.NextAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -040081import com.android.systemui.statusbar.policy.ZenModeController;
Jason Monke5b770e2017-03-03 21:49:29 -050082
Fabian Kozynski8d06c712018-11-07 10:33:02 -050083import java.util.List;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080084import java.util.Locale;
Beverlyb9826dd2018-04-12 15:02:45 -040085import java.util.Objects;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080086
Rohan Shahd3cf7562018-02-23 11:12:28 -080087/**
88 * View that contains the top-most bits of the screen (primarily the status bar with date, time, and
89 * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner
90 * contents.
91 */
Amin Shaikhf09450b2018-04-06 17:32:45 -040092public class QuickStatusBarHeader extends RelativeLayout implements
Beverlyb9826dd2018-04-12 15:02:45 -040093 View.OnClickListener, NextAlarmController.NextAlarmChangeCallback,
94 ZenModeController.Callback {
Rohan Shaha160ab12018-03-09 15:47:36 -080095 private static final String TAG = "QuickStatusBarHeader";
96 private static final boolean DEBUG = false;
Jason Monke5b770e2017-03-03 21:49:29 -050097
Rohan Shahd3cf7562018-02-23 11:12:28 -080098 /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */
99 private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6;
100 private static final int FADE_ANIMATION_DURATION_MS = 300;
101 private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0;
Rohan Shahb6a915c2018-03-01 11:57:00 -0800102 public static final int MAX_TOOLTIP_SHOWN_COUNT = 2;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800103
104 private final Handler mHandler = new Handler();
Jason Monke5b770e2017-03-03 21:49:29 -0500105
106 private QSPanel mQsPanel;
107
108 private boolean mExpanded;
109 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +0100110 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -0500111
112 protected QuickQSPanel mHeaderQsPanel;
113 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -0500114 private TintedIconManager mIconManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800115 private TouchAnimator mStatusIconsAlphaAnimator;
116 private TouchAnimator mHeaderTextContainerAlphaAnimator;
Evan Laird95896952018-01-22 19:30:05 -0500117
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000118 private View mSystemIconsView;
Evan Laird95896952018-01-22 19:30:05 -0500119 private View mQuickQsStatusIcons;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800120 private View mHeaderTextContainerView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400121 /** View containing the next alarm and ringer mode info. */
122 private View mStatusContainer;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800123 /** Tooltip for educating users that they can long press on icons to see more details. */
124 private View mLongPressTooltipView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400125
126 private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
127 private AlarmManager.AlarmClockInfo mNextAlarm;
128
129 private ImageView mNextAlarmIcon;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800130 /** {@link TextView} containing the actual text indicating when the next alarm will go off. */
131 private TextView mNextAlarmTextView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400132 private View mStatusSeparator;
133 private ImageView mRingerModeIcon;
134 private TextView mRingerModeTextView;
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000135 private BatteryMeterView mBatteryMeterView;
136 private Clock mClockView;
137 private DateView mDateView;
Fabian Kozynski12638242018-10-12 15:33:41 -0400138 private OngoingPrivacyChip mPrivacyChip;
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500139 private Space mSpace;
Evan Laird4bf21df2018-10-22 14:24:32 -0400140 private BatteryMeterView mBatteryRemainingIcon;
141 private TextView mBatteryRemainingText;
142 private boolean mShowBatteryPercentAndEstimate;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800143
144 private NextAlarmController mAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -0400145 private ZenModeController mZenController;
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500146 private PrivacyItemController mPrivacyItemController;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800147 /** Counts how many times the long press tooltip has been shown to the user. */
148 private int mShownCount;
149
Amin Shaikh761c5662018-03-27 16:55:43 -0400150 private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() {
151 @Override
152 public void onReceive(Context context, Intent intent) {
153 mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1);
154 updateStatusText();
155 }
156 };
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500157 private boolean mHasTopCutout = false;
Amin Shaikh761c5662018-03-27 16:55:43 -0400158
Evan Laird4bf21df2018-10-22 14:24:32 -0400159 private final PercentSettingObserver mPercentSettingObserver =
160 new PercentSettingObserver(new Handler(mContext.getMainLooper()));
161
Rohan Shahd3cf7562018-02-23 11:12:28 -0800162 /**
163 * Runnable for automatically fading out the long press tooltip (as if it were animating away).
164 */
165 private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false);
Evan Laird4ea2a492018-01-22 11:29:12 -0500166
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500167 private PrivacyItemController.Callback mPICCallback = new PrivacyItemController.Callback() {
168 @Override
169 public void privacyChanged(List<PrivacyItem> privacyItems) {
170 mPrivacyChip.setPrivacyList(privacyItems);
171 setChipVisibility(!privacyItems.isEmpty());
172 }
173 };
174
Jason Monke5b770e2017-03-03 21:49:29 -0500175 public QuickStatusBarHeader(Context context, AttributeSet attrs) {
176 super(context, attrs);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800177 mAlarmController = Dependency.get(NextAlarmController.class);
Beverlyb9826dd2018-04-12 15:02:45 -0400178 mZenController = Dependency.get(ZenModeController.class);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500179 mPrivacyItemController = new PrivacyItemController(context, mPICCallback);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800180 mShownCount = getStoredShownCount();
Jason Monke5b770e2017-03-03 21:49:29 -0500181 }
182
183 @Override
184 protected void onFinishInflate() {
185 super.onFinishInflate();
Jason Monke5b770e2017-03-03 21:49:29 -0500186
187 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000188 mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons);
Evan Laird95896952018-01-22 19:30:05 -0500189 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
Evan Laird20b87bf2018-04-12 09:54:11 -0400190 StatusIconContainer iconContainer = findViewById(R.id.statusIcons);
191 iconContainer.setShouldRestrictIcons(false);
192 mIconManager = new TintedIconManager(iconContainer);
Jason Monke5b770e2017-03-03 21:49:29 -0500193
Rohan Shahd3cf7562018-02-23 11:12:28 -0800194 // Views corresponding to the header info section (e.g. tooltip and next alarm).
195 mHeaderTextContainerView = findViewById(R.id.header_text_container);
196 mLongPressTooltipView = findViewById(R.id.long_press_tooltip);
Amin Shaikh761c5662018-03-27 16:55:43 -0400197 mStatusContainer = findViewById(R.id.status_container);
198 mStatusSeparator = findViewById(R.id.status_separator);
199 mNextAlarmIcon = findViewById(R.id.next_alarm_icon);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800200 mNextAlarmTextView = findViewById(R.id.next_alarm_text);
Amin Shaikh761c5662018-03-27 16:55:43 -0400201 mRingerModeIcon = findViewById(R.id.ringer_mode_icon);
202 mRingerModeTextView = findViewById(R.id.ringer_mode_text);
Jason Monke5b770e2017-03-03 21:49:29 -0500203
204 updateResources();
205
Jason Monk824ffff2017-04-11 15:49:06 -0400206 Rect tintArea = new Rect(0, 0, 0, 0);
Jason Changb4e879d2018-04-11 11:17:58 +0800207 int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
208 android.R.attr.colorForeground);
Amin Shaikh0e003312018-03-08 11:39:01 -0500209 float intensity = getColorIntensity(colorForeground);
Evan Laird95896952018-01-22 19:30:05 -0500210 int fillColor = fillColorForIntensity(intensity, getContext());
211
212 // Set light text on the header icons because they will always be on a black background
Evan Laird39254d42018-01-18 16:05:30 -0500213 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -0500214
215 // Set the correct tint for the status icons so they contrast
216 mIconManager.setTint(fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500217
Evan Laird4bf21df2018-10-22 14:24:32 -0400218 mShowBatteryPercentAndEstimate = mContext.getResources().getBoolean(
219 com.android.internal.R.bool.config_battery_percentage_setting_available);
220
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000221 mBatteryMeterView = findViewById(R.id.battery);
Evan Laird4bf21df2018-10-22 14:24:32 -0400222 mBatteryMeterView.setPercentShowMode(mShowBatteryPercentAndEstimate
223 ? BatteryMeterView.MODE_ON : BatteryMeterView.MODE_OFF);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400224 mBatteryMeterView.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000225 mClockView = findViewById(R.id.clock);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400226 mClockView.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000227 mDateView = findViewById(R.id.date);
Fabian Kozynski12638242018-10-12 15:33:41 -0400228 mPrivacyChip = findViewById(R.id.privacy_chip);
229 mPrivacyChip.setOnClickListener(this);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500230 mSpace = findViewById(R.id.space);
Evan Laird4bf21df2018-10-22 14:24:32 -0400231
232 // Tint for the battery icons are handled in setupHost()
233 mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon);
234 mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_OFF);
235
236 mBatteryRemainingText = findViewById(R.id.batteryRemainingText);
237 mBatteryRemainingText.setTextColor(fillColor);
238
239 updateShowPercent();
Jason Monke5b770e2017-03-03 21:49:29 -0500240 }
241
Amin Shaikh761c5662018-03-27 16:55:43 -0400242 private void updateStatusText() {
Beverlyb9826dd2018-04-12 15:02:45 -0400243 boolean changed = updateRingerStatus() || updateAlarmStatus();
244
245 if (changed) {
246 boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
247 boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
248 mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE
249 : View.GONE);
250 updateTooltipShow();
251 }
252 }
253
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500254 private void setChipVisibility(boolean chipVisible) {
255 mBatteryMeterView.setVisibility(View.VISIBLE);
256 if (chipVisible) {
257 mPrivacyChip.setVisibility(View.VISIBLE);
258 if (mHasTopCutout) mBatteryMeterView.setVisibility(View.GONE);
259 } else {
260 mPrivacyChip.setVisibility(View.GONE);
261 }
262 }
263
Beverlyb9826dd2018-04-12 15:02:45 -0400264 private boolean updateRingerStatus() {
265 boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
266 CharSequence originalRingerText = mRingerModeTextView.getText();
267
Amin Shaikh761c5662018-03-27 16:55:43 -0400268 boolean ringerVisible = false;
Beverlyb9826dd2018-04-12 15:02:45 -0400269 if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(),
Beverlyff2df9b2018-10-10 16:54:10 -0400270 mZenController.getConsolidatedPolicy())) {
Beverlyb9826dd2018-04-12 15:02:45 -0400271 if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
272 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate);
273 mRingerModeTextView.setText(R.string.qs_status_phone_vibrate);
274 ringerVisible = true;
275 } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
276 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent);
277 mRingerModeTextView.setText(R.string.qs_status_phone_muted);
278 ringerVisible = true;
279 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400280 }
281 mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
282 mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
283
Beverlyb9826dd2018-04-12 15:02:45 -0400284 return isOriginalVisible != ringerVisible ||
285 !Objects.equals(originalRingerText, mRingerModeTextView.getText());
286 }
287
288 private boolean updateAlarmStatus() {
289 boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
290 CharSequence originalAlarmText = mNextAlarmTextView.getText();
291
Amin Shaikh761c5662018-03-27 16:55:43 -0400292 boolean alarmVisible = false;
293 if (mNextAlarm != null) {
294 alarmVisible = true;
295 mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm));
296 }
297 mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
298 mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400299
Beverlyb9826dd2018-04-12 15:02:45 -0400300 return isOriginalVisible != alarmVisible ||
301 !Objects.equals(originalAlarmText, mNextAlarmTextView.getText());
302 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400303
Jason Monk824ffff2017-04-11 15:49:06 -0400304 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
305 View v = findViewById(id);
306 if (v instanceof DarkReceiver) {
307 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
308 }
309 }
310
Evan Laird95896952018-01-22 19:30:05 -0500311 private int fillColorForIntensity(float intensity, Context context) {
312 if (intensity == 0) {
Amin Shaikh9cac3382018-04-11 17:10:07 -0400313 return context.getColor(R.color.light_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500314 }
Amin Shaikh9cac3382018-04-11 17:10:07 -0400315 return context.getColor(R.color.dark_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500316 }
317
Jason Monke5b770e2017-03-03 21:49:29 -0500318 @Override
319 protected void onConfigurationChanged(Configuration newConfig) {
320 super.onConfigurationChanged(newConfig);
321 updateResources();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000322
323 // Update color schemes in landscape to use wallpaperTextColor
324 boolean shouldUseWallpaperTextColor =
325 newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
326 mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor);
327 mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500328 }
329
Fabian Kozynskief124492018-11-02 11:02:11 -0400330
331
Jason Monke5b770e2017-03-03 21:49:29 -0500332 @Override
333 public void onRtlPropertiesChanged(int layoutDirection) {
334 super.onRtlPropertiesChanged(layoutDirection);
335 updateResources();
336 }
337
Evan Laird84b98952018-07-02 17:43:59 -0400338 /**
339 * The height of QQS should always be the status bar height + 128dp. This is normally easy, but
340 * when there is a notch involved the status bar can remain a fixed pixel size.
341 */
342 private void updateMinimumHeight() {
343 int sbHeight = mContext.getResources().getDimensionPixelSize(
344 com.android.internal.R.dimen.status_bar_height);
345 int qqsHeight = mContext.getResources().getDimensionPixelSize(
346 R.dimen.qs_quick_header_panel_height);
347
348 setMinimumHeight(sbHeight + qqsHeight);
349 }
350
Jason Monke5b770e2017-03-03 21:49:29 -0500351 private void updateResources() {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000352 Resources resources = mContext.getResources();
Evan Laird84b98952018-07-02 17:43:59 -0400353 updateMinimumHeight();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000354
355 // Update height for a few views, especially due to landscape mode restricting space.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800356 mHeaderTextContainerView.getLayoutParams().height =
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000357 resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800358 mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams());
359
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000360 mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize(
361 com.android.internal.R.dimen.quick_qs_offset_height);
362 mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
363
Evan Laird84b98952018-07-02 17:43:59 -0400364 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
365 if (mQsDisabled) {
366 lp.height = resources.getDimensionPixelSize(
367 com.android.internal.R.dimen.quick_qs_offset_height);
368 } else {
369 lp.height = Math.max(getMinimumHeight(),
370 resources.getDimensionPixelSize(
Evan Lairdbf3794a2018-07-17 15:55:40 -0400371 com.android.internal.R.dimen.quick_qs_total_height));
Evan Laird84b98952018-07-02 17:43:59 -0400372 }
373
374 setLayoutParams(lp);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000375
Fabian Kozynskief124492018-11-02 11:02:11 -0400376 if (mPrivacyChip != null) {
377 MarginLayoutParams lm = (MarginLayoutParams) mPrivacyChip.getLayoutParams();
378 int sideMargins = lm.leftMargin;
379 int topBottomMargins = resources.getDimensionPixelSize(
380 R.dimen.ongoing_appops_top_chip_margin);
381 lm.setMargins(sideMargins, topBottomMargins, sideMargins, topBottomMargins);
382 mPrivacyChip.setLayoutParams(lm);
383 }
384
Rohan Shahd3cf7562018-02-23 11:12:28 -0800385 updateStatusIconAlphaAnimator();
386 updateHeaderTextContainerAlphaAnimator();
Evan Laird95896952018-01-22 19:30:05 -0500387 }
388
Rohan Shahd3cf7562018-02-23 11:12:28 -0800389 private void updateStatusIconAlphaAnimator() {
390 mStatusIconsAlphaAnimator = new TouchAnimator.Builder()
Evan Laird95896952018-01-22 19:30:05 -0500391 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
392 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500393 }
394
Rohan Shahd3cf7562018-02-23 11:12:28 -0800395 private void updateHeaderTextContainerAlphaAnimator() {
396 mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder()
397 .addFloat(mHeaderTextContainerView, "alpha", 0, 1)
398 .setStartDelay(.5f)
399 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500400 }
401
Evan Laird4bf21df2018-10-22 14:24:32 -0400402 private void updateBatteryRemainingText() {
403 if (!mShowBatteryPercentAndEstimate) {
404 return;
405 }
406 mBatteryRemainingText.setText(
407 Dependency.get(BatteryController.class).getEstimatedTimeRemainingString());
408 }
409
Jason Monke5b770e2017-03-03 21:49:29 -0500410 public void setExpanded(boolean expanded) {
411 if (mExpanded == expanded) return;
412 mExpanded = expanded;
413 mHeaderQsPanel.setExpanded(expanded);
414 updateEverything();
415 }
416
Rohan Shahd3cf7562018-02-23 11:12:28 -0800417 /**
418 * Animates the inner contents based on the given expansion details.
419 *
420 * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen)
421 * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f)
422 * @param panelTranslationY how much the panel has physically moved down vertically (required
423 * for keyguard animations only)
424 */
425 public void setExpansion(boolean isKeyguardShowing, float expansionFraction,
426 float panelTranslationY) {
427 final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction;
428 if (mStatusIconsAlphaAnimator != null) {
429 mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction);
Evan Laird95896952018-01-22 19:30:05 -0500430 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800431
432 if (isKeyguardShowing) {
433 // If the keyguard is showing, we want to offset the text so that it comes in at the
434 // same time as the panel as it slides down.
435 mHeaderTextContainerView.setTranslationY(panelTranslationY);
436 } else {
437 mHeaderTextContainerView.setTranslationY(0f);
438 }
439
440 if (mHeaderTextContainerAlphaAnimator != null) {
441 mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction);
442 }
443
444 // Check the original expansion fraction - we don't want to show the tooltip until the
445 // panel is pulled all the way out.
446 if (expansionFraction == 1f) {
447 // QS is fully expanded, bring in the tooltip.
448 showLongPressTooltip();
449 }
450 }
451
452 /** Returns the latest stored tooltip shown count from SharedPreferences. */
453 private int getStoredShownCount() {
454 return Prefs.getInt(
455 mContext,
456 Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
457 TOOLTIP_NOT_YET_SHOWN_COUNT);
Jason Monke5b770e2017-03-03 21:49:29 -0500458 }
459
Charles Hece2a7c02017-10-11 20:25:20 +0100460 public void disable(int state1, int state2, boolean animate) {
461 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
462 if (disabled == mQsDisabled) return;
463 mQsDisabled = disabled;
464 mHeaderQsPanel.setDisabledByPolicy(disabled);
Amin Shaikhf09450b2018-04-06 17:32:45 -0400465 mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
466 mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
467 updateResources();
Charles Hece2a7c02017-10-11 20:25:20 +0100468 }
469
470 @Override
471 public void onAttachedToWindow() {
Amin Shaikha59215a2018-04-23 08:52:38 -0400472 super.onAttachedToWindow();
Evan Laird95896952018-01-22 19:30:05 -0500473 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100474 requestApplyInsets();
Evan Laird4bf21df2018-10-22 14:24:32 -0400475 mContext.getContentResolver().registerContentObserver(
476 Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mPercentSettingObserver,
477 ActivityManager.getCurrentUser());
Adrian Roos13836052018-03-15 21:06:37 +0100478 }
479
480 @Override
481 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500482 DisplayCutout cutout = insets.getDisplayCutout();
Adrian Roos13836052018-03-15 21:06:37 +0100483 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500484 cutout, getDisplay());
Adrian Roos13836052018-03-15 21:06:37 +0100485 if (padding == null) {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400486 mSystemIconsView.setPaddingRelative(
487 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0,
488 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0);
Adrian Roos13836052018-03-15 21:06:37 +0100489 } else {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400490 mSystemIconsView.setPadding(padding.first, 0, padding.second, 0);
491
Adrian Roos13836052018-03-15 21:06:37 +0100492 }
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500493 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mSpace.getLayoutParams();
494 if (cutout != null) {
495 Rect topCutout = cutout.getBoundingRectTop();
496 if (topCutout.isEmpty()) {
497 mHasTopCutout = false;
498 lp.width = 0;
499 mSpace.setVisibility(View.GONE);
500 } else {
501 mHasTopCutout = true;
502 lp.width = topCutout.width();
503 mSpace.setVisibility(View.VISIBLE);
504 }
505 }
506 mSpace.setLayoutParams(lp);
507 // Decide whether to show BatteryMeterView
508 setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE);
Adrian Roos13836052018-03-15 21:06:37 +0100509 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100510 }
511
512 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500513 @VisibleForTesting
514 public void onDetachedFromWindow() {
515 setListening(false);
Evan Laird95896952018-01-22 19:30:05 -0500516 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Evan Laird4bf21df2018-10-22 14:24:32 -0400517 mContext.getContentResolver().unregisterContentObserver(mPercentSettingObserver);
Jason Monke5b770e2017-03-03 21:49:29 -0500518 super.onDetachedFromWindow();
519 }
520
521 public void setListening(boolean listening) {
522 if (listening == mListening) {
523 return;
524 }
525 mHeaderQsPanel.setListening(listening);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500526 mPrivacyItemController.setListening(listening);
Jason Monke5b770e2017-03-03 21:49:29 -0500527 mListening = listening;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800528
529 if (listening) {
Beverlyb9826dd2018-04-12 15:02:45 -0400530 mZenController.addCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800531 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400532 mContext.registerReceiver(mRingerReceiver,
533 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Evan Laird4bf21df2018-10-22 14:24:32 -0400534 updateBatteryRemainingText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800535 } else {
Beverlyb9826dd2018-04-12 15:02:45 -0400536 mZenController.removeCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800537 mAlarmController.removeCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400538 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800539 }
Jason Monke5b770e2017-03-03 21:49:29 -0500540 }
541
Evan Laird95896952018-01-22 19:30:05 -0500542 @Override
543 public void onClick(View v) {
Amin Shaikh39bdc502018-05-15 23:43:34 -0400544 if (v == mClockView) {
Evan Laird95896952018-01-22 19:30:05 -0500545 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
546 AlarmClock.ACTION_SHOW_ALARMS),0);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400547 } else if (v == mBatteryMeterView) {
548 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
549 Intent.ACTION_POWER_USAGE_SUMMARY),0);
Fabian Kozynski12638242018-10-12 15:33:41 -0400550 } else if (v == mPrivacyChip) {
551 Handler mUiHandler = new Handler(Looper.getMainLooper());
552 mUiHandler.post(() -> {
553 Dialog mDialog = new OngoingPrivacyDialog(mContext,
554 mPrivacyChip.getBuilder()).createDialog();
555 mDialog.getWindow().setType(
556 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
557 SystemUIDialog.setShowForAllUsers(mDialog, true);
558 SystemUIDialog.registerDismissListener(mDialog);
559 SystemUIDialog.setWindowOnTop(mDialog);
560 mUiHandler.post(() -> mDialog.show());
561 mHost.collapsePanels();
562 });
Evan Laird95896952018-01-22 19:30:05 -0500563 }
564 }
565
Rohan Shahd3cf7562018-02-23 11:12:28 -0800566 @Override
567 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400568 mNextAlarm = nextAlarm;
569 updateStatusText();
570 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800571
Beverlyb9826dd2018-04-12 15:02:45 -0400572 @Override
573 public void onZenChanged(int zen) {
574 updateStatusText();
575
576 }
577
578 @Override
579 public void onConfigChanged(ZenModeConfig config) {
580 updateStatusText();
581 }
582
Amin Shaikh761c5662018-03-27 16:55:43 -0400583 private void updateTooltipShow() {
584 if (hasStatusText()) {
585 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800586 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400587 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800588 }
589 updateHeaderTextContainerAlphaAnimator();
590 }
591
Amin Shaikh761c5662018-03-27 16:55:43 -0400592 private boolean hasStatusText() {
593 return mNextAlarmTextView.getVisibility() == View.VISIBLE
594 || mRingerModeTextView.getVisibility() == View.VISIBLE;
595 }
596
Rohan Shahd3cf7562018-02-23 11:12:28 -0800597 /**
598 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
599 * the space).
600 */
601 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400602 // If we have status text to show, don't bother fading in the tooltip.
603 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800604 return;
605 }
606
607 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
608 mLongPressTooltipView.animate().cancel();
609 mLongPressTooltipView.setVisibility(View.VISIBLE);
610 mLongPressTooltipView.animate()
611 .alpha(1f)
612 .setDuration(FADE_ANIMATION_DURATION_MS)
613 .setListener(new AnimatorListenerAdapter() {
614 @Override
615 public void onAnimationEnd(Animator animation) {
616 mHandler.postDelayed(
617 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
618 }
619 })
620 .start();
621
622 // Increment and drop the shown count in prefs for the next time we're deciding to
623 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
624 // in prefs (say, from a long press).
625 if (getStoredShownCount() <= mShownCount) {
626 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
627 }
628 }
629 }
630
631 /**
632 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400633 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800634 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400635 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800636 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400637 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800638 mLongPressTooltipView.animate().cancel();
639 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
640 && mLongPressTooltipView.getAlpha() != 0f) {
641 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
642 mLongPressTooltipView.animate()
643 .alpha(0f)
644 .setDuration(FADE_ANIMATION_DURATION_MS)
645 .setListener(new AnimatorListenerAdapter() {
646 @Override
647 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800648 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800649 mLongPressTooltipView.setVisibility(View.INVISIBLE);
650
Amin Shaikh761c5662018-03-27 16:55:43 -0400651 if (shouldShowStatusText) {
652 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800653 }
654 }
655 })
656 .start();
657 } else {
658 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400659 if (shouldShowStatusText) {
660 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800661 }
662 }
663 }
664
665 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400666 * Fades in the updated status text. Note that if there's already a status showing, this will
Fabian Kozynski3f789332018-09-04 16:42:43 -0400667 * immediately fade it out and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800668 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400669 private void showStatus() {
670 mStatusContainer.setAlpha(0f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800671
Amin Shaikh761c5662018-03-27 16:55:43 -0400672 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800673 .alpha(1f)
674 .setDuration(FADE_ANIMATION_DURATION_MS)
675 .start();
676 }
677
Fabian Kozynski3f789332018-09-04 16:42:43 -0400678 /** Fades out the status text. */
Amin Shaikh761c5662018-03-27 16:55:43 -0400679 private void hideStatusText() {
Fabian Kozynski3f789332018-09-04 16:42:43 -0400680 mStatusContainer.animate()
681 .alpha(0f)
682 .setDuration(FADE_ANIMATION_DURATION_MS)
683 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800684 }
685
Jason Monke5b770e2017-03-03 21:49:29 -0500686 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500687 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500688 }
689
690 public void setQSPanel(final QSPanel qsPanel) {
691 mQsPanel = qsPanel;
692 setupHost(qsPanel.getHost());
693 }
694
695 public void setupHost(final QSTileHost host) {
696 mHost = host;
697 //host.setHeaderView(mExpandIndicator);
698 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
699 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500700
701 // Use SystemUI context to get battery meter colors, and let it use the default tint (white)
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000702 mBatteryMeterView.setColorsFromContext(mHost.getContext());
703 mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird4bf21df2018-10-22 14:24:32 -0400704
705 Rect tintArea = new Rect(0, 0, 0, 0);
706 int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
707 android.R.attr.colorForeground);
708 float intensity = getColorIntensity(colorForeground);
709 int fillColor = fillColorForIntensity(intensity, getContext());
710 mBatteryRemainingIcon.setColorsFromContext(mHost.getContext());
711 mBatteryRemainingIcon.onDarkChanged(tintArea, intensity, fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500712 }
713
714 public void setCallback(Callback qsPanelCallback) {
715 mHeaderQsPanel.setCallback(qsPanelCallback);
716 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800717
718 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
719 if (info == null) {
720 return "";
721 }
722 String skeleton = android.text.format.DateFormat
723 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
724 String pattern = android.text.format.DateFormat
725 .getBestDateTimePattern(Locale.getDefault(), skeleton);
726 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
727 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500728
729 public static float getColorIntensity(@ColorInt int color) {
730 return color == Color.WHITE ? 0 : 1;
731 }
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400732
733 public void setMargins(int sideMargins) {
734 for (int i = 0; i < getChildCount(); i++) {
735 View v = getChildAt(i);
Fabian Kozynskief124492018-11-02 11:02:11 -0400736 if (v == mSystemIconsView || v == mQuickQsStatusIcons || v == mHeaderQsPanel
737 || v == mPrivacyChip) {
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400738 continue;
739 }
740 RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams();
741 lp.leftMargin = sideMargins;
742 lp.rightMargin = sideMargins;
743 }
744 }
Evan Laird4bf21df2018-10-22 14:24:32 -0400745
746 private void updateShowPercent() {
747 final boolean systemSetting = 0 != Settings.System
748 .getIntForUser(getContext().getContentResolver(),
749 SHOW_BATTERY_PERCENT, 0, ActivityManager.getCurrentUser());
750
751 mShowBatteryPercentAndEstimate = systemSetting;
752
753 updateBatteryViews();
754 }
755
756 private void updateBatteryViews() {
757 if (mShowBatteryPercentAndEstimate) {
758 mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ON);
759 mBatteryRemainingIcon.setVisibility(View.VISIBLE);
760 mBatteryRemainingText.setVisibility(View.VISIBLE);
761 updateBatteryRemainingText();
762 } else {
763 mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_OFF);
764 mBatteryRemainingIcon.setVisibility(View.GONE);
765 mBatteryRemainingText.setVisibility(View.GONE);
766 }
767 }
768
769 private final class PercentSettingObserver extends ContentObserver {
770 PercentSettingObserver(Handler handler) {
771 super(handler);
772 }
773
774 @Override
775 public void onChange(boolean selfChange, Uri uri) {
776 super.onChange(selfChange, uri);
777 updateShowPercent();
778 }
779 }
Jason Monke5b770e2017-03-03 21:49:29 -0500780}