blob: b502a952471d63e8ec43151f4f232e1e17f9905e [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;
Charles Hece2a7c02017-10-11 20:25:20 +010018
Jason Monkea54e8a2018-12-20 10:01:48 -050019import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
20
Rohan Shahd3cf7562018-02-23 11:12:28 -080021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Amin Shaikh0e003312018-03-08 11:39:01 -050023import android.annotation.ColorInt;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080024import android.app.ActivityManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080025import android.app.AlarmManager;
Fabian Kozynski12638242018-10-12 15:33:41 -040026import android.app.Dialog;
Amin Shaikh761c5662018-03-27 16:55:43 -040027import android.content.BroadcastReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050028import android.content.Context;
Evan Laird4ea2a492018-01-22 11:29:12 -050029import android.content.Intent;
Amin Shaikh761c5662018-03-27 16:55:43 -040030import android.content.IntentFilter;
Jason Monke5b770e2017-03-03 21:49:29 -050031import android.content.res.Configuration;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000032import android.content.res.Resources;
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;
Rohan Shahd3cf7562018-02-23 11:12:28 -080036import android.os.Handler;
Fabian Kozynski12638242018-10-12 15:33:41 -040037import android.os.Looper;
Evan Laird4ea2a492018-01-22 11:29:12 -050038import android.provider.AlarmClock;
Beverlyb9826dd2018-04-12 15:02:45 -040039import android.service.notification.ZenModeConfig;
Rohan Shahd3cf7562018-02-23 11:12:28 -080040import android.text.format.DateUtils;
Jason Monke5b770e2017-03-03 21:49:29 -050041import android.util.AttributeSet;
Rohan Shaha160ab12018-03-09 15:47:36 -080042import android.util.Log;
Adrian Roos13836052018-03-15 21:06:37 +010043import android.util.Pair;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050044import android.view.DisplayCutout;
Jason Monk824ffff2017-04-11 15:49:06 -040045import android.view.View;
Adrian Roos13836052018-03-15 21:06:37 +010046import android.view.WindowInsets;
Beverlyff2df9b2018-10-10 16:54:10 -040047import android.widget.FrameLayout;
Amin Shaikh761c5662018-03-27 16:55:43 -040048import android.widget.ImageView;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050049import android.widget.LinearLayout;
Jason Monke5b770e2017-03-03 21:49:29 -050050import android.widget.RelativeLayout;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050051import android.widget.Space;
Rohan Shahd3cf7562018-02-23 11:12:28 -080052import android.widget.TextView;
Jason Monke5b770e2017-03-03 21:49:29 -050053
Beverlyff2df9b2018-10-10 16:54:10 -040054import androidx.annotation.VisibleForTesting;
55
Jason Monke5b770e2017-03-03 21:49:29 -050056import com.android.settingslib.Utils;
57import com.android.systemui.BatteryMeterView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080058import com.android.systemui.Prefs;
Jason Monke5b770e2017-03-03 21:49:29 -050059import com.android.systemui.R;
60import com.android.systemui.plugins.ActivityStarter;
Beverly1be62f42018-12-19 17:17:48 -050061import com.android.systemui.plugins.DarkIconDispatcher;
62import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
Fabian Kozynski12638242018-10-12 15:33:41 -040063import com.android.systemui.privacy.OngoingPrivacyChip;
64import com.android.systemui.privacy.OngoingPrivacyDialog;
Fabian Kozynskiafd50022019-02-05 09:41:42 -050065import com.android.systemui.privacy.PrivacyDialogBuilder;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050066import com.android.systemui.privacy.PrivacyItem;
67import com.android.systemui.privacy.PrivacyItemController;
Jason Monke5b770e2017-03-03 21:49:29 -050068import com.android.systemui.qs.QSDetail.Callback;
Adrian Roos13836052018-03-15 21:06:37 +010069import com.android.systemui.statusbar.phone.PhoneStatusBarView;
Evan Laird95896952018-01-22 19:30:05 -050070import com.android.systemui.statusbar.phone.StatusBarIconController;
71import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Evan Laird20b87bf2018-04-12 09:54:11 -040072import com.android.systemui.statusbar.phone.StatusIconContainer;
Fabian Kozynski12638242018-10-12 15:33:41 -040073import com.android.systemui.statusbar.phone.SystemUIDialog;
Beverlyff2df9b2018-10-10 16:54:10 -040074import com.android.systemui.statusbar.policy.Clock;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000075import com.android.systemui.statusbar.policy.DateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080076import com.android.systemui.statusbar.policy.NextAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -040077import com.android.systemui.statusbar.policy.ZenModeController;
Jason Monke5b770e2017-03-03 21:49:29 -050078
Evan Lairdf435fd22019-02-15 13:35:45 -050079import java.util.ArrayList;
Fabian Kozynski8d06c712018-11-07 10:33:02 -050080import java.util.List;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080081import java.util.Locale;
Beverlyb9826dd2018-04-12 15:02:45 -040082import java.util.Objects;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080083
Jason Monkea54e8a2018-12-20 10:01:48 -050084import javax.inject.Inject;
85import javax.inject.Named;
86
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 Monkea54e8a2018-12-20 10:01:48 -0500105 private final NextAlarmController mAlarmController;
106 private final ZenModeController mZenController;
107 private final StatusBarIconController mStatusBarIconController;
108 private final ActivityStarter mActivityStarter;
Jason Monke5b770e2017-03-03 21:49:29 -0500109
110 private QSPanel mQsPanel;
111
112 private boolean mExpanded;
113 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +0100114 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -0500115
Fabian Kozynski4e76d1f2019-02-25 16:30:04 -0500116 private QSCarrierGroup mCarrierGroup;
Jason Monke5b770e2017-03-03 21:49:29 -0500117 protected QuickQSPanel mHeaderQsPanel;
118 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -0500119 private TintedIconManager mIconManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800120 private TouchAnimator mStatusIconsAlphaAnimator;
121 private TouchAnimator mHeaderTextContainerAlphaAnimator;
Fabian Kozynski216812e2019-02-01 13:49:00 -0500122 private TouchAnimator mPrivacyChipAlphaAnimator;
Evan Laird95896952018-01-22 19:30:05 -0500123
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000124 private View mSystemIconsView;
Evan Laird95896952018-01-22 19:30:05 -0500125 private View mQuickQsStatusIcons;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800126 private View mHeaderTextContainerView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400127 /** View containing the next alarm and ringer mode info. */
128 private View mStatusContainer;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800129 /** Tooltip for educating users that they can long press on icons to see more details. */
130 private View mLongPressTooltipView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400131
132 private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
133 private AlarmManager.AlarmClockInfo mNextAlarm;
134
135 private ImageView mNextAlarmIcon;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800136 /** {@link TextView} containing the actual text indicating when the next alarm will go off. */
137 private TextView mNextAlarmTextView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400138 private View mStatusSeparator;
139 private ImageView mRingerModeIcon;
140 private TextView mRingerModeTextView;
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000141 private Clock mClockView;
142 private DateView mDateView;
Fabian Kozynski12638242018-10-12 15:33:41 -0400143 private OngoingPrivacyChip mPrivacyChip;
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500144 private Space mSpace;
Evan Laird4bf21df2018-10-22 14:24:32 -0400145 private BatteryMeterView mBatteryRemainingIcon;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800146
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500147 private PrivacyItemController mPrivacyItemController;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800148 /** Counts how many times the long press tooltip has been shown to the user. */
149 private int mShownCount;
150
Amin Shaikh761c5662018-03-27 16:55:43 -0400151 private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() {
152 @Override
153 public void onReceive(Context context, Intent intent) {
154 mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1);
155 updateStatusText();
156 }
157 };
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500158 private boolean mHasTopCutout = false;
Amin Shaikh761c5662018-03-27 16:55:43 -0400159
Rohan Shahd3cf7562018-02-23 11:12:28 -0800160 /**
161 * Runnable for automatically fading out the long press tooltip (as if it were animating away).
162 */
163 private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false);
Evan Laird4ea2a492018-01-22 11:29:12 -0500164
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500165 private PrivacyItemController.Callback mPICCallback = new PrivacyItemController.Callback() {
166 @Override
167 public void privacyChanged(List<PrivacyItem> privacyItems) {
168 mPrivacyChip.setPrivacyList(privacyItems);
169 setChipVisibility(!privacyItems.isEmpty());
170 }
171 };
172
Jason Monkea54e8a2018-12-20 10:01:48 -0500173 @Inject
174 public QuickStatusBarHeader(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs,
175 NextAlarmController nextAlarmController, ZenModeController zenModeController,
Evan Laird85ee4a32019-03-06 18:09:20 -0500176 StatusBarIconController statusBarIconController,
Fabian Kozynski04f83eb2019-01-22 10:38:40 -0500177 ActivityStarter activityStarter, PrivacyItemController privacyItemController) {
Jason Monke5b770e2017-03-03 21:49:29 -0500178 super(context, attrs);
Jason Monkea54e8a2018-12-20 10:01:48 -0500179 mAlarmController = nextAlarmController;
180 mZenController = zenModeController;
Jason Monkea54e8a2018-12-20 10:01:48 -0500181 mStatusBarIconController = statusBarIconController;
182 mActivityStarter = activityStarter;
Fabian Kozynski04f83eb2019-01-22 10:38:40 -0500183 mPrivacyItemController = privacyItemController;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800184 mShownCount = getStoredShownCount();
Jason Monke5b770e2017-03-03 21:49:29 -0500185 }
186
187 @Override
188 protected void onFinishInflate() {
189 super.onFinishInflate();
Jason Monke5b770e2017-03-03 21:49:29 -0500190
191 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000192 mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons);
Evan Laird95896952018-01-22 19:30:05 -0500193 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
Evan Laird20b87bf2018-04-12 09:54:11 -0400194 StatusIconContainer iconContainer = findViewById(R.id.statusIcons);
Evan Lairdf435fd22019-02-15 13:35:45 -0500195 // Ignore privacy icons because they show in the space above QQS
196 iconContainer.addIgnoredSlots(getIgnoredIconSlots());
Evan Laird20b87bf2018-04-12 09:54:11 -0400197 iconContainer.setShouldRestrictIcons(false);
198 mIconManager = new TintedIconManager(iconContainer);
Jason Monke5b770e2017-03-03 21:49:29 -0500199
Rohan Shahd3cf7562018-02-23 11:12:28 -0800200 // Views corresponding to the header info section (e.g. tooltip and next alarm).
201 mHeaderTextContainerView = findViewById(R.id.header_text_container);
202 mLongPressTooltipView = findViewById(R.id.long_press_tooltip);
Amin Shaikh761c5662018-03-27 16:55:43 -0400203 mStatusContainer = findViewById(R.id.status_container);
204 mStatusSeparator = findViewById(R.id.status_separator);
205 mNextAlarmIcon = findViewById(R.id.next_alarm_icon);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800206 mNextAlarmTextView = findViewById(R.id.next_alarm_text);
Amin Shaikh761c5662018-03-27 16:55:43 -0400207 mRingerModeIcon = findViewById(R.id.ringer_mode_icon);
208 mRingerModeTextView = findViewById(R.id.ringer_mode_text);
Fabian Kozynski216812e2019-02-01 13:49:00 -0500209 mPrivacyChip = findViewById(R.id.privacy_chip);
210 mPrivacyChip.setOnClickListener(this);
Fabian Kozynski4e76d1f2019-02-25 16:30:04 -0500211 mCarrierGroup = findViewById(R.id.carrier_group);
Jason Monke5b770e2017-03-03 21:49:29 -0500212
213 updateResources();
214
Jason Monk824ffff2017-04-11 15:49:06 -0400215 Rect tintArea = new Rect(0, 0, 0, 0);
Jason Changb4e879d2018-04-11 11:17:58 +0800216 int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
217 android.R.attr.colorForeground);
Amin Shaikh0e003312018-03-08 11:39:01 -0500218 float intensity = getColorIntensity(colorForeground);
Evan Laird95896952018-01-22 19:30:05 -0500219 int fillColor = fillColorForIntensity(intensity, getContext());
220
221 // Set light text on the header icons because they will always be on a black background
Evan Laird39254d42018-01-18 16:05:30 -0500222 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -0500223
224 // Set the correct tint for the status icons so they contrast
225 mIconManager.setTint(fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500226
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000227 mClockView = findViewById(R.id.clock);
Amin Shaikh39bdc502018-05-15 23:43:34 -0400228 mClockView.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000229 mDateView = findViewById(R.id.date);
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);
Evan Laird698839b2018-12-05 15:49:12 -0500234 // Don't need to worry about tuner settings for this icon
235 mBatteryRemainingIcon.setIgnoreTunerUpdates(true);
Evan Laird85ee4a32019-03-06 18:09:20 -0500236 // QS will always show the estimate, and BatteryMeterView handles the case where
237 // it's unavailable or charging
238 mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE);
Jason Monke5b770e2017-03-03 21:49:29 -0500239 }
240
Evan Lairdf435fd22019-02-15 13:35:45 -0500241 private List<String> getIgnoredIconSlots() {
242 ArrayList<String> ignored = new ArrayList<>();
243 ignored.add(mContext.getResources().getString(
244 com.android.internal.R.string.status_bar_camera));
245 ignored.add(mContext.getResources().getString(
246 com.android.internal.R.string.status_bar_microphone));
247 ignored.add(mContext.getResources().getString(
248 com.android.internal.R.string.status_bar_location));
249
250 return ignored;
251 }
252
Amin Shaikh761c5662018-03-27 16:55:43 -0400253 private void updateStatusText() {
Beverlyb9826dd2018-04-12 15:02:45 -0400254 boolean changed = updateRingerStatus() || updateAlarmStatus();
255
256 if (changed) {
257 boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
258 boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
259 mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE
260 : View.GONE);
261 updateTooltipShow();
262 }
263 }
264
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500265 private void setChipVisibility(boolean chipVisible) {
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500266 if (chipVisible) {
267 mPrivacyChip.setVisibility(View.VISIBLE);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500268 } else {
269 mPrivacyChip.setVisibility(View.GONE);
270 }
271 }
272
Beverlyb9826dd2018-04-12 15:02:45 -0400273 private boolean updateRingerStatus() {
274 boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
275 CharSequence originalRingerText = mRingerModeTextView.getText();
276
Amin Shaikh761c5662018-03-27 16:55:43 -0400277 boolean ringerVisible = false;
Beverlyb9826dd2018-04-12 15:02:45 -0400278 if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(),
Beverlyff2df9b2018-10-10 16:54:10 -0400279 mZenController.getConsolidatedPolicy())) {
Beverlyb9826dd2018-04-12 15:02:45 -0400280 if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
281 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate);
282 mRingerModeTextView.setText(R.string.qs_status_phone_vibrate);
283 ringerVisible = true;
284 } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
285 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent);
286 mRingerModeTextView.setText(R.string.qs_status_phone_muted);
287 ringerVisible = true;
288 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400289 }
290 mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
291 mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
292
Beverlyb9826dd2018-04-12 15:02:45 -0400293 return isOriginalVisible != ringerVisible ||
294 !Objects.equals(originalRingerText, mRingerModeTextView.getText());
295 }
296
297 private boolean updateAlarmStatus() {
298 boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
299 CharSequence originalAlarmText = mNextAlarmTextView.getText();
300
Amin Shaikh761c5662018-03-27 16:55:43 -0400301 boolean alarmVisible = false;
302 if (mNextAlarm != null) {
303 alarmVisible = true;
304 mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm));
305 }
306 mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
307 mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400308
Beverlyb9826dd2018-04-12 15:02:45 -0400309 return isOriginalVisible != alarmVisible ||
310 !Objects.equals(originalAlarmText, mNextAlarmTextView.getText());
311 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400312
Jason Monk824ffff2017-04-11 15:49:06 -0400313 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
314 View v = findViewById(id);
315 if (v instanceof DarkReceiver) {
316 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
317 }
318 }
319
Evan Laird95896952018-01-22 19:30:05 -0500320 private int fillColorForIntensity(float intensity, Context context) {
321 if (intensity == 0) {
Amin Shaikh9cac3382018-04-11 17:10:07 -0400322 return context.getColor(R.color.light_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500323 }
Amin Shaikh9cac3382018-04-11 17:10:07 -0400324 return context.getColor(R.color.dark_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500325 }
326
Jason Monke5b770e2017-03-03 21:49:29 -0500327 @Override
328 protected void onConfigurationChanged(Configuration newConfig) {
329 super.onConfigurationChanged(newConfig);
330 updateResources();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000331
332 // Update color schemes in landscape to use wallpaperTextColor
333 boolean shouldUseWallpaperTextColor =
334 newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000335 mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500336 }
337
Fabian Kozynskief124492018-11-02 11:02:11 -0400338
339
Jason Monke5b770e2017-03-03 21:49:29 -0500340 @Override
341 public void onRtlPropertiesChanged(int layoutDirection) {
342 super.onRtlPropertiesChanged(layoutDirection);
343 updateResources();
344 }
345
Evan Laird84b98952018-07-02 17:43:59 -0400346 /**
347 * The height of QQS should always be the status bar height + 128dp. This is normally easy, but
348 * when there is a notch involved the status bar can remain a fixed pixel size.
349 */
350 private void updateMinimumHeight() {
351 int sbHeight = mContext.getResources().getDimensionPixelSize(
352 com.android.internal.R.dimen.status_bar_height);
353 int qqsHeight = mContext.getResources().getDimensionPixelSize(
354 R.dimen.qs_quick_header_panel_height);
355
356 setMinimumHeight(sbHeight + qqsHeight);
357 }
358
Jason Monke5b770e2017-03-03 21:49:29 -0500359 private void updateResources() {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000360 Resources resources = mContext.getResources();
Evan Laird84b98952018-07-02 17:43:59 -0400361 updateMinimumHeight();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000362
363 // Update height for a few views, especially due to landscape mode restricting space.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800364 mHeaderTextContainerView.getLayoutParams().height =
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000365 resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800366 mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams());
367
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000368 mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize(
369 com.android.internal.R.dimen.quick_qs_offset_height);
370 mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
371
Evan Laird84b98952018-07-02 17:43:59 -0400372 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
373 if (mQsDisabled) {
374 lp.height = resources.getDimensionPixelSize(
375 com.android.internal.R.dimen.quick_qs_offset_height);
376 } else {
377 lp.height = Math.max(getMinimumHeight(),
378 resources.getDimensionPixelSize(
Evan Lairdbf3794a2018-07-17 15:55:40 -0400379 com.android.internal.R.dimen.quick_qs_total_height));
Evan Laird84b98952018-07-02 17:43:59 -0400380 }
381
382 setLayoutParams(lp);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000383
Rohan Shahd3cf7562018-02-23 11:12:28 -0800384 updateStatusIconAlphaAnimator();
385 updateHeaderTextContainerAlphaAnimator();
Fabian Kozynski216812e2019-02-01 13:49:00 -0500386 updatePrivacyChipAlphaAnimator();
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
Fabian Kozynski216812e2019-02-01 13:49:00 -0500402 private void updatePrivacyChipAlphaAnimator() {
403 mPrivacyChipAlphaAnimator = new TouchAnimator.Builder()
404 .addFloat(mPrivacyChip, "alpha", 1, 0, 1)
405 .build();
406 }
407
Jason Monke5b770e2017-03-03 21:49:29 -0500408 public void setExpanded(boolean expanded) {
409 if (mExpanded == expanded) return;
410 mExpanded = expanded;
411 mHeaderQsPanel.setExpanded(expanded);
Fabian Kozynskif3a77012019-01-09 15:37:30 +0000412 updateEverything();
Jason Monke5b770e2017-03-03 21:49:29 -0500413 }
414
Rohan Shahd3cf7562018-02-23 11:12:28 -0800415 /**
416 * Animates the inner contents based on the given expansion details.
417 *
418 * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen)
419 * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f)
420 * @param panelTranslationY how much the panel has physically moved down vertically (required
421 * for keyguard animations only)
422 */
423 public void setExpansion(boolean isKeyguardShowing, float expansionFraction,
424 float panelTranslationY) {
425 final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction;
426 if (mStatusIconsAlphaAnimator != null) {
427 mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction);
Evan Laird95896952018-01-22 19:30:05 -0500428 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800429
430 if (isKeyguardShowing) {
431 // If the keyguard is showing, we want to offset the text so that it comes in at the
432 // same time as the panel as it slides down.
433 mHeaderTextContainerView.setTranslationY(panelTranslationY);
434 } else {
435 mHeaderTextContainerView.setTranslationY(0f);
436 }
437
438 if (mHeaderTextContainerAlphaAnimator != null) {
439 mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction);
440 }
Fabian Kozynski216812e2019-02-01 13:49:00 -0500441 if (mPrivacyChipAlphaAnimator != null) {
442 mPrivacyChip.setExpanded(expansionFraction > 0.5);
443 mPrivacyChipAlphaAnimator.setPosition(keyguardExpansionFraction);
444 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800445
446 // Check the original expansion fraction - we don't want to show the tooltip until the
447 // panel is pulled all the way out.
448 if (expansionFraction == 1f) {
449 // QS is fully expanded, bring in the tooltip.
450 showLongPressTooltip();
451 }
452 }
453
454 /** Returns the latest stored tooltip shown count from SharedPreferences. */
455 private int getStoredShownCount() {
456 return Prefs.getInt(
457 mContext,
458 Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
459 TOOLTIP_NOT_YET_SHOWN_COUNT);
Jason Monke5b770e2017-03-03 21:49:29 -0500460 }
461
Charles Hece2a7c02017-10-11 20:25:20 +0100462 public void disable(int state1, int state2, boolean animate) {
463 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
464 if (disabled == mQsDisabled) return;
465 mQsDisabled = disabled;
466 mHeaderQsPanel.setDisabledByPolicy(disabled);
Amin Shaikhf09450b2018-04-06 17:32:45 -0400467 mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
468 mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
469 updateResources();
Charles Hece2a7c02017-10-11 20:25:20 +0100470 }
471
472 @Override
473 public void onAttachedToWindow() {
Amin Shaikha59215a2018-04-23 08:52:38 -0400474 super.onAttachedToWindow();
Jason Monkea54e8a2018-12-20 10:01:48 -0500475 mStatusBarIconController.addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100476 requestApplyInsets();
477 }
478
479 @Override
480 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500481 DisplayCutout cutout = insets.getDisplayCutout();
Adrian Roos13836052018-03-15 21:06:37 +0100482 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500483 cutout, getDisplay());
Adrian Roos13836052018-03-15 21:06:37 +0100484 if (padding == null) {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400485 mSystemIconsView.setPaddingRelative(
486 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0,
487 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0);
Adrian Roos13836052018-03-15 21:06:37 +0100488 } else {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400489 mSystemIconsView.setPadding(padding.first, 0, padding.second, 0);
490
Adrian Roos13836052018-03-15 21:06:37 +0100491 }
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500492 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mSpace.getLayoutParams();
493 if (cutout != null) {
494 Rect topCutout = cutout.getBoundingRectTop();
495 if (topCutout.isEmpty()) {
496 mHasTopCutout = false;
497 lp.width = 0;
498 mSpace.setVisibility(View.GONE);
499 } else {
500 mHasTopCutout = true;
501 lp.width = topCutout.width();
502 mSpace.setVisibility(View.VISIBLE);
503 }
504 }
505 mSpace.setLayoutParams(lp);
Fabian Kozynski8d06c712018-11-07 10:33:02 -0500506 setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE);
Adrian Roos13836052018-03-15 21:06:37 +0100507 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100508 }
509
510 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500511 @VisibleForTesting
512 public void onDetachedFromWindow() {
513 setListening(false);
Jason Monkea54e8a2018-12-20 10:01:48 -0500514 mStatusBarIconController.removeIconGroup(mIconManager);
Jason Monke5b770e2017-03-03 21:49:29 -0500515 super.onDetachedFromWindow();
516 }
517
518 public void setListening(boolean listening) {
519 if (listening == mListening) {
520 return;
521 }
522 mHeaderQsPanel.setListening(listening);
523 mListening = listening;
Fabian Kozynski4e76d1f2019-02-25 16:30:04 -0500524 mCarrierGroup.setListening(mListening);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800525
526 if (listening) {
Beverlyb9826dd2018-04-12 15:02:45 -0400527 mZenController.addCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800528 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400529 mContext.registerReceiver(mRingerReceiver,
530 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Fabian Kozynski04f83eb2019-01-22 10:38:40 -0500531 mPrivacyItemController.addCallback(mPICCallback);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800532 } else {
Beverlyb9826dd2018-04-12 15:02:45 -0400533 mZenController.removeCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800534 mAlarmController.removeCallback(this);
Fabian Kozynski04f83eb2019-01-22 10:38:40 -0500535 mPrivacyItemController.removeCallback(mPICCallback);
Amin Shaikh761c5662018-03-27 16:55:43 -0400536 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800537 }
Jason Monke5b770e2017-03-03 21:49:29 -0500538 }
539
Evan Laird95896952018-01-22 19:30:05 -0500540 @Override
541 public void onClick(View v) {
Amin Shaikh39bdc502018-05-15 23:43:34 -0400542 if (v == mClockView) {
Jason Monkea54e8a2018-12-20 10:01:48 -0500543 mActivityStarter.postStartActivityDismissingKeyguard(new Intent(
Evan Laird95896952018-01-22 19:30:05 -0500544 AlarmClock.ACTION_SHOW_ALARMS),0);
Fabian Kozynski12638242018-10-12 15:33:41 -0400545 } else if (v == mPrivacyChip) {
Fabian Kozynskiafd50022019-02-05 09:41:42 -0500546 // Makes sure that the builder is grabbed as soon as the chip is pressed
547 PrivacyDialogBuilder builder = mPrivacyChip.getBuilder();
548 if (builder.getAppsAndTypes().size() == 0) return;
Fabian Kozynski12638242018-10-12 15:33:41 -0400549 Handler mUiHandler = new Handler(Looper.getMainLooper());
550 mUiHandler.post(() -> {
Fabian Kozynskiafd50022019-02-05 09:41:42 -0500551 Dialog mDialog = new OngoingPrivacyDialog(mContext, builder).createDialog();
Fabian Kozynski8f3660e2019-02-11 11:02:11 -0500552 SystemUIDialog.setShowForAllUsers(mDialog, false);
Fabian Kozynski12638242018-10-12 15:33:41 -0400553 SystemUIDialog.registerDismissListener(mDialog);
554 SystemUIDialog.setWindowOnTop(mDialog);
Fabian Kozynski8f3660e2019-02-11 11:02:11 -0500555 mActivityStarter.postQSRunnableDismissingKeyguard(() -> mDialog.show());
Fabian Kozynski12638242018-10-12 15:33:41 -0400556 mHost.collapsePanels();
557 });
Evan Laird95896952018-01-22 19:30:05 -0500558 }
559 }
560
Rohan Shahd3cf7562018-02-23 11:12:28 -0800561 @Override
562 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400563 mNextAlarm = nextAlarm;
564 updateStatusText();
565 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800566
Beverlyb9826dd2018-04-12 15:02:45 -0400567 @Override
568 public void onZenChanged(int zen) {
569 updateStatusText();
570
571 }
572
573 @Override
574 public void onConfigChanged(ZenModeConfig config) {
575 updateStatusText();
576 }
577
Amin Shaikh761c5662018-03-27 16:55:43 -0400578 private void updateTooltipShow() {
579 if (hasStatusText()) {
580 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800581 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400582 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800583 }
584 updateHeaderTextContainerAlphaAnimator();
585 }
586
Amin Shaikh761c5662018-03-27 16:55:43 -0400587 private boolean hasStatusText() {
588 return mNextAlarmTextView.getVisibility() == View.VISIBLE
589 || mRingerModeTextView.getVisibility() == View.VISIBLE;
590 }
591
Rohan Shahd3cf7562018-02-23 11:12:28 -0800592 /**
593 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
594 * the space).
595 */
596 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400597 // If we have status text to show, don't bother fading in the tooltip.
598 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800599 return;
600 }
601
602 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
603 mLongPressTooltipView.animate().cancel();
604 mLongPressTooltipView.setVisibility(View.VISIBLE);
605 mLongPressTooltipView.animate()
606 .alpha(1f)
607 .setDuration(FADE_ANIMATION_DURATION_MS)
608 .setListener(new AnimatorListenerAdapter() {
609 @Override
610 public void onAnimationEnd(Animator animation) {
611 mHandler.postDelayed(
612 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
613 }
614 })
615 .start();
616
617 // Increment and drop the shown count in prefs for the next time we're deciding to
618 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
619 // in prefs (say, from a long press).
620 if (getStoredShownCount() <= mShownCount) {
621 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
622 }
623 }
624 }
625
626 /**
627 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400628 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800629 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400630 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800631 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400632 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800633 mLongPressTooltipView.animate().cancel();
634 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
635 && mLongPressTooltipView.getAlpha() != 0f) {
636 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
637 mLongPressTooltipView.animate()
638 .alpha(0f)
639 .setDuration(FADE_ANIMATION_DURATION_MS)
640 .setListener(new AnimatorListenerAdapter() {
641 @Override
642 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800643 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800644 mLongPressTooltipView.setVisibility(View.INVISIBLE);
645
Amin Shaikh761c5662018-03-27 16:55:43 -0400646 if (shouldShowStatusText) {
647 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800648 }
649 }
650 })
651 .start();
652 } else {
653 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400654 if (shouldShowStatusText) {
655 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800656 }
657 }
658 }
659
660 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400661 * Fades in the updated status text. Note that if there's already a status showing, this will
Fabian Kozynski3f789332018-09-04 16:42:43 -0400662 * immediately fade it out and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800663 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400664 private void showStatus() {
665 mStatusContainer.setAlpha(0f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800666
Amin Shaikh761c5662018-03-27 16:55:43 -0400667 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800668 .alpha(1f)
669 .setDuration(FADE_ANIMATION_DURATION_MS)
670 .start();
671 }
672
Fabian Kozynski3f789332018-09-04 16:42:43 -0400673 /** Fades out the status text. */
Amin Shaikh761c5662018-03-27 16:55:43 -0400674 private void hideStatusText() {
Fabian Kozynski3f789332018-09-04 16:42:43 -0400675 mStatusContainer.animate()
676 .alpha(0f)
677 .setDuration(FADE_ANIMATION_DURATION_MS)
678 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800679 }
680
Fabian Kozynskif3a77012019-01-09 15:37:30 +0000681 public void updateEverything() {
Fabian Kozynski9a15b7c2019-01-10 11:13:27 -0500682 post(() -> setClickable(!mExpanded));
Fabian Kozynskif3a77012019-01-09 15:37:30 +0000683 }
684
Jason Monke5b770e2017-03-03 21:49:29 -0500685 public void setQSPanel(final QSPanel qsPanel) {
686 mQsPanel = qsPanel;
687 setupHost(qsPanel.getHost());
688 }
689
690 public void setupHost(final QSTileHost host) {
691 mHost = host;
692 //host.setHeaderView(mExpandIndicator);
693 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
694 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500695
Evan Laird4bf21df2018-10-22 14:24:32 -0400696
697 Rect tintArea = new Rect(0, 0, 0, 0);
698 int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
699 android.R.attr.colorForeground);
700 float intensity = getColorIntensity(colorForeground);
701 int fillColor = fillColorForIntensity(intensity, getContext());
702 mBatteryRemainingIcon.setColorsFromContext(mHost.getContext());
703 mBatteryRemainingIcon.onDarkChanged(tintArea, intensity, fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500704 }
705
706 public void setCallback(Callback qsPanelCallback) {
707 mHeaderQsPanel.setCallback(qsPanelCallback);
708 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800709
710 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
711 if (info == null) {
712 return "";
713 }
714 String skeleton = android.text.format.DateFormat
715 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
716 String pattern = android.text.format.DateFormat
717 .getBestDateTimePattern(Locale.getDefault(), skeleton);
718 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
719 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500720
721 public static float getColorIntensity(@ColorInt int color) {
722 return color == Color.WHITE ? 0 : 1;
723 }
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400724
725 public void setMargins(int sideMargins) {
726 for (int i = 0; i < getChildCount(); i++) {
727 View v = getChildAt(i);
Fabian Kozynskief124492018-11-02 11:02:11 -0400728 if (v == mSystemIconsView || v == mQuickQsStatusIcons || v == mHeaderQsPanel
729 || v == mPrivacyChip) {
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400730 continue;
731 }
732 RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams();
733 lp.leftMargin = sideMargins;
734 lp.rightMargin = sideMargins;
735 }
736 }
Jason Monke5b770e2017-03-03 21:49:29 -0500737}