blob: ad2efbd3ed6909f2db1ebedd2756fd58fb8031ec [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
Rohan Shahd3cf7562018-02-23 11:12:28 -080019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Amin Shaikh0e003312018-03-08 11:39:01 -050021import android.annotation.ColorInt;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080022import android.app.ActivityManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080023import android.app.AlarmManager;
Amin Shaikh761c5662018-03-27 16:55:43 -040024import android.content.BroadcastReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050025import android.content.Context;
Evan Laird4ea2a492018-01-22 11:29:12 -050026import android.content.Intent;
Amin Shaikh761c5662018-03-27 16:55:43 -040027import android.content.IntentFilter;
Jason Monke5b770e2017-03-03 21:49:29 -050028import android.content.res.Configuration;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000029import android.content.res.Resources;
Jason Monke5b770e2017-03-03 21:49:29 -050030import android.graphics.Color;
31import android.graphics.Rect;
Amin Shaikh761c5662018-03-27 16:55:43 -040032import android.media.AudioManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080033import android.os.Handler;
Evan Laird4ea2a492018-01-22 11:29:12 -050034import android.provider.AlarmClock;
Beverlyb9826dd2018-04-12 15:02:45 -040035import android.service.notification.ZenModeConfig;
Jason Monke5b770e2017-03-03 21:49:29 -050036import android.support.annotation.VisibleForTesting;
Rohan Shahd3cf7562018-02-23 11:12:28 -080037import android.text.format.DateUtils;
Jason Monke5b770e2017-03-03 21:49:29 -050038import android.util.AttributeSet;
Rohan Shaha160ab12018-03-09 15:47:36 -080039import android.util.Log;
Adrian Roos13836052018-03-15 21:06:37 +010040import android.util.Pair;
Jason Monk824ffff2017-04-11 15:49:06 -040041import android.view.View;
Adrian Roos13836052018-03-15 21:06:37 +010042import android.view.WindowInsets;
Amin Shaikh761c5662018-03-27 16:55:43 -040043import android.widget.ImageView;
Amin Shaikh50d2d1e2018-04-25 14:48:13 -040044import android.widget.LinearLayout;
Jason Monke5b770e2017-03-03 21:49:29 -050045import android.widget.RelativeLayout;
Rohan Shahd3cf7562018-02-23 11:12:28 -080046import android.widget.TextView;
Jason Monke5b770e2017-03-03 21:49:29 -050047
48import com.android.settingslib.Utils;
49import com.android.systemui.BatteryMeterView;
50import com.android.systemui.Dependency;
Rohan Shahd3cf7562018-02-23 11:12:28 -080051import com.android.systemui.Prefs;
Jason Monke5b770e2017-03-03 21:49:29 -050052import com.android.systemui.R;
53import com.android.systemui.plugins.ActivityStarter;
54import com.android.systemui.qs.QSDetail.Callback;
Adrian Roos13836052018-03-15 21:06:37 +010055import com.android.systemui.statusbar.phone.PhoneStatusBarView;
Evan Laird95896952018-01-22 19:30:05 -050056import com.android.systemui.statusbar.phone.StatusBarIconController;
57import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000058import com.android.systemui.statusbar.policy.Clock;
Evan Laird20b87bf2018-04-12 09:54:11 -040059import com.android.systemui.statusbar.phone.StatusIconContainer;
Evan Laird39254d42018-01-18 16:05:30 -050060import com.android.systemui.statusbar.policy.DarkIconDispatcher;
Jason Monk824ffff2017-04-11 15:49:06 -040061import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000062import com.android.systemui.statusbar.policy.DateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080063import com.android.systemui.statusbar.policy.NextAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -040064import com.android.systemui.statusbar.policy.ZenModeController;
Jason Monke5b770e2017-03-03 21:49:29 -050065
Lucas Dupin1f7374a2018-02-26 18:08:33 -080066import java.util.Locale;
Beverlyb9826dd2018-04-12 15:02:45 -040067import java.util.Objects;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080068
Rohan Shahd3cf7562018-02-23 11:12:28 -080069/**
70 * View that contains the top-most bits of the screen (primarily the status bar with date, time, and
71 * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner
72 * contents.
73 */
Amin Shaikhf09450b2018-04-06 17:32:45 -040074public class QuickStatusBarHeader extends RelativeLayout implements
Beverlyb9826dd2018-04-12 15:02:45 -040075 View.OnClickListener, NextAlarmController.NextAlarmChangeCallback,
76 ZenModeController.Callback {
Rohan Shaha160ab12018-03-09 15:47:36 -080077 private static final String TAG = "QuickStatusBarHeader";
78 private static final boolean DEBUG = false;
Jason Monke5b770e2017-03-03 21:49:29 -050079
Rohan Shahd3cf7562018-02-23 11:12:28 -080080 /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */
81 private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6;
82 private static final int FADE_ANIMATION_DURATION_MS = 300;
83 private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0;
Rohan Shahb6a915c2018-03-01 11:57:00 -080084 public static final int MAX_TOOLTIP_SHOWN_COUNT = 2;
Rohan Shahd3cf7562018-02-23 11:12:28 -080085
86 private final Handler mHandler = new Handler();
Jason Monke5b770e2017-03-03 21:49:29 -050087
88 private QSPanel mQsPanel;
89
90 private boolean mExpanded;
91 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +010092 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -050093
94 protected QuickQSPanel mHeaderQsPanel;
95 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -050096 private TintedIconManager mIconManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080097 private TouchAnimator mStatusIconsAlphaAnimator;
98 private TouchAnimator mHeaderTextContainerAlphaAnimator;
Evan Laird95896952018-01-22 19:30:05 -050099
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000100 private View mSystemIconsView;
Evan Laird95896952018-01-22 19:30:05 -0500101 private View mQuickQsStatusIcons;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800102 private View mHeaderTextContainerView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400103 /** View containing the next alarm and ringer mode info. */
104 private View mStatusContainer;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800105 /** Tooltip for educating users that they can long press on icons to see more details. */
106 private View mLongPressTooltipView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400107
108 private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
109 private AlarmManager.AlarmClockInfo mNextAlarm;
110
111 private ImageView mNextAlarmIcon;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800112 /** {@link TextView} containing the actual text indicating when the next alarm will go off. */
113 private TextView mNextAlarmTextView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400114 private View mStatusSeparator;
115 private ImageView mRingerModeIcon;
116 private TextView mRingerModeTextView;
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000117 private BatteryMeterView mBatteryMeterView;
118 private Clock mClockView;
119 private DateView mDateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800120
121 private NextAlarmController mAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -0400122 private ZenModeController mZenController;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800123 /** Counts how many times the long press tooltip has been shown to the user. */
124 private int mShownCount;
125
Amin Shaikh761c5662018-03-27 16:55:43 -0400126 private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() {
127 @Override
128 public void onReceive(Context context, Intent intent) {
129 mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1);
130 updateStatusText();
131 }
132 };
133
Rohan Shahd3cf7562018-02-23 11:12:28 -0800134 /**
135 * Runnable for automatically fading out the long press tooltip (as if it were animating away).
136 */
137 private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false);
Evan Laird4ea2a492018-01-22 11:29:12 -0500138
Jason Monke5b770e2017-03-03 21:49:29 -0500139 public QuickStatusBarHeader(Context context, AttributeSet attrs) {
140 super(context, attrs);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800141 mAlarmController = Dependency.get(NextAlarmController.class);
Beverlyb9826dd2018-04-12 15:02:45 -0400142 mZenController = Dependency.get(ZenModeController.class);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800143 mShownCount = getStoredShownCount();
Jason Monke5b770e2017-03-03 21:49:29 -0500144 }
145
146 @Override
147 protected void onFinishInflate() {
148 super.onFinishInflate();
Jason Monke5b770e2017-03-03 21:49:29 -0500149
150 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000151 mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons);
Evan Laird95896952018-01-22 19:30:05 -0500152 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
Evan Laird20b87bf2018-04-12 09:54:11 -0400153 StatusIconContainer iconContainer = findViewById(R.id.statusIcons);
154 iconContainer.setShouldRestrictIcons(false);
155 mIconManager = new TintedIconManager(iconContainer);
Jason Monke5b770e2017-03-03 21:49:29 -0500156
Rohan Shahd3cf7562018-02-23 11:12:28 -0800157 // Views corresponding to the header info section (e.g. tooltip and next alarm).
158 mHeaderTextContainerView = findViewById(R.id.header_text_container);
159 mLongPressTooltipView = findViewById(R.id.long_press_tooltip);
Amin Shaikh761c5662018-03-27 16:55:43 -0400160 mStatusContainer = findViewById(R.id.status_container);
161 mStatusSeparator = findViewById(R.id.status_separator);
162 mNextAlarmIcon = findViewById(R.id.next_alarm_icon);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800163 mNextAlarmTextView = findViewById(R.id.next_alarm_text);
Amin Shaikh761c5662018-03-27 16:55:43 -0400164 mRingerModeIcon = findViewById(R.id.ringer_mode_icon);
165 mRingerModeTextView = findViewById(R.id.ringer_mode_text);
Jason Monke5b770e2017-03-03 21:49:29 -0500166
167 updateResources();
168
Jason Monk824ffff2017-04-11 15:49:06 -0400169 Rect tintArea = new Rect(0, 0, 0, 0);
Evan Laird95896952018-01-22 19:30:05 -0500170 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
Amin Shaikh0e003312018-03-08 11:39:01 -0500171 float intensity = getColorIntensity(colorForeground);
Evan Laird95896952018-01-22 19:30:05 -0500172 int fillColor = fillColorForIntensity(intensity, getContext());
173
174 // Set light text on the header icons because they will always be on a black background
Evan Laird39254d42018-01-18 16:05:30 -0500175 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -0500176
177 // Set the correct tint for the status icons so they contrast
178 mIconManager.setTint(fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500179
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000180 mBatteryMeterView = findViewById(R.id.battery);
181 mBatteryMeterView.setForceShowPercent(true);
182 mClockView = findViewById(R.id.clock);
183 mDateView = findViewById(R.id.date);
Rohan Shahbb662cc2018-04-06 17:57:00 -0700184 mDateView.setOnClickListener(this);
Jason Monke5b770e2017-03-03 21:49:29 -0500185 }
186
Amin Shaikh761c5662018-03-27 16:55:43 -0400187 private void updateStatusText() {
Beverlyb9826dd2018-04-12 15:02:45 -0400188 boolean changed = updateRingerStatus() || updateAlarmStatus();
189
190 if (changed) {
191 boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
192 boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
193 mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE
194 : View.GONE);
195 updateTooltipShow();
196 }
197 }
198
199 private boolean updateRingerStatus() {
200 boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
201 CharSequence originalRingerText = mRingerModeTextView.getText();
202
Amin Shaikh761c5662018-03-27 16:55:43 -0400203 boolean ringerVisible = false;
Beverlyb9826dd2018-04-12 15:02:45 -0400204 if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(),
205 mZenController.getConfig())) {
206 if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
207 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate);
208 mRingerModeTextView.setText(R.string.qs_status_phone_vibrate);
209 ringerVisible = true;
210 } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
211 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent);
212 mRingerModeTextView.setText(R.string.qs_status_phone_muted);
213 ringerVisible = true;
214 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400215 }
216 mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
217 mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
218
Beverlyb9826dd2018-04-12 15:02:45 -0400219 return isOriginalVisible != ringerVisible ||
220 !Objects.equals(originalRingerText, mRingerModeTextView.getText());
221 }
222
223 private boolean updateAlarmStatus() {
224 boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
225 CharSequence originalAlarmText = mNextAlarmTextView.getText();
226
Amin Shaikh761c5662018-03-27 16:55:43 -0400227 boolean alarmVisible = false;
228 if (mNextAlarm != null) {
229 alarmVisible = true;
230 mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm));
231 }
232 mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
233 mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400234
Beverlyb9826dd2018-04-12 15:02:45 -0400235 return isOriginalVisible != alarmVisible ||
236 !Objects.equals(originalAlarmText, mNextAlarmTextView.getText());
237 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400238
Jason Monk824ffff2017-04-11 15:49:06 -0400239 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
240 View v = findViewById(id);
241 if (v instanceof DarkReceiver) {
242 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
243 }
244 }
245
Evan Laird95896952018-01-22 19:30:05 -0500246 private int fillColorForIntensity(float intensity, Context context) {
247 if (intensity == 0) {
Amin Shaikh9cac3382018-04-11 17:10:07 -0400248 return context.getColor(R.color.light_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500249 }
Amin Shaikh9cac3382018-04-11 17:10:07 -0400250 return context.getColor(R.color.dark_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500251 }
252
Jason Monke5b770e2017-03-03 21:49:29 -0500253 @Override
254 protected void onConfigurationChanged(Configuration newConfig) {
255 super.onConfigurationChanged(newConfig);
256 updateResources();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000257
258 // Update color schemes in landscape to use wallpaperTextColor
259 boolean shouldUseWallpaperTextColor =
260 newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
261 mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor);
262 mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500263 }
264
265 @Override
266 public void onRtlPropertiesChanged(int layoutDirection) {
267 super.onRtlPropertiesChanged(layoutDirection);
268 updateResources();
269 }
270
271 private void updateResources() {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000272 Resources resources = mContext.getResources();
273
274 // Update height for a few views, especially due to landscape mode restricting space.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800275 mHeaderTextContainerView.getLayoutParams().height =
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000276 resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800277 mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams());
278
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000279 mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize(
280 com.android.internal.R.dimen.quick_qs_offset_height);
281 mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
282
Amin Shaikhf09450b2018-04-06 17:32:45 -0400283 getLayoutParams().height = resources.getDimensionPixelSize(mQsDisabled
284 ? com.android.internal.R.dimen.quick_qs_offset_height
285 : com.android.internal.R.dimen.quick_qs_total_height);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000286 setLayoutParams(getLayoutParams());
287
Rohan Shahd3cf7562018-02-23 11:12:28 -0800288 updateStatusIconAlphaAnimator();
289 updateHeaderTextContainerAlphaAnimator();
Evan Laird95896952018-01-22 19:30:05 -0500290 }
291
Rohan Shahd3cf7562018-02-23 11:12:28 -0800292 private void updateStatusIconAlphaAnimator() {
293 mStatusIconsAlphaAnimator = new TouchAnimator.Builder()
Evan Laird95896952018-01-22 19:30:05 -0500294 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
295 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500296 }
297
Rohan Shahd3cf7562018-02-23 11:12:28 -0800298 private void updateHeaderTextContainerAlphaAnimator() {
299 mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder()
300 .addFloat(mHeaderTextContainerView, "alpha", 0, 1)
301 .setStartDelay(.5f)
302 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500303 }
304
305 public void setExpanded(boolean expanded) {
306 if (mExpanded == expanded) return;
307 mExpanded = expanded;
308 mHeaderQsPanel.setExpanded(expanded);
309 updateEverything();
310 }
311
Rohan Shahd3cf7562018-02-23 11:12:28 -0800312 /**
313 * Animates the inner contents based on the given expansion details.
314 *
315 * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen)
316 * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f)
317 * @param panelTranslationY how much the panel has physically moved down vertically (required
318 * for keyguard animations only)
319 */
320 public void setExpansion(boolean isKeyguardShowing, float expansionFraction,
321 float panelTranslationY) {
322 final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction;
323 if (mStatusIconsAlphaAnimator != null) {
324 mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction);
Evan Laird95896952018-01-22 19:30:05 -0500325 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800326
327 if (isKeyguardShowing) {
328 // If the keyguard is showing, we want to offset the text so that it comes in at the
329 // same time as the panel as it slides down.
330 mHeaderTextContainerView.setTranslationY(panelTranslationY);
331 } else {
332 mHeaderTextContainerView.setTranslationY(0f);
333 }
334
335 if (mHeaderTextContainerAlphaAnimator != null) {
336 mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction);
337 }
338
339 // Check the original expansion fraction - we don't want to show the tooltip until the
340 // panel is pulled all the way out.
341 if (expansionFraction == 1f) {
342 // QS is fully expanded, bring in the tooltip.
343 showLongPressTooltip();
344 }
345 }
346
347 /** Returns the latest stored tooltip shown count from SharedPreferences. */
348 private int getStoredShownCount() {
349 return Prefs.getInt(
350 mContext,
351 Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
352 TOOLTIP_NOT_YET_SHOWN_COUNT);
Jason Monke5b770e2017-03-03 21:49:29 -0500353 }
354
Charles Hece2a7c02017-10-11 20:25:20 +0100355 public void disable(int state1, int state2, boolean animate) {
356 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
357 if (disabled == mQsDisabled) return;
358 mQsDisabled = disabled;
359 mHeaderQsPanel.setDisabledByPolicy(disabled);
Amin Shaikhf09450b2018-04-06 17:32:45 -0400360 mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
361 mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
362 updateResources();
Charles Hece2a7c02017-10-11 20:25:20 +0100363 }
364
365 @Override
366 public void onAttachedToWindow() {
Amin Shaikha59215a2018-04-23 08:52:38 -0400367 super.onAttachedToWindow();
Evan Laird95896952018-01-22 19:30:05 -0500368 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100369 requestApplyInsets();
370 }
371
372 @Override
373 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
374 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
375 insets.getDisplayCutout(), getDisplay());
376 if (padding == null) {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400377 mSystemIconsView.setPaddingRelative(
378 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0,
379 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0);
Adrian Roos13836052018-03-15 21:06:37 +0100380 } else {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400381 mSystemIconsView.setPadding(padding.first, 0, padding.second, 0);
382
Adrian Roos13836052018-03-15 21:06:37 +0100383 }
384 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100385 }
386
387 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500388 @VisibleForTesting
389 public void onDetachedFromWindow() {
390 setListening(false);
Evan Laird95896952018-01-22 19:30:05 -0500391 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Jason Monke5b770e2017-03-03 21:49:29 -0500392 super.onDetachedFromWindow();
393 }
394
395 public void setListening(boolean listening) {
396 if (listening == mListening) {
397 return;
398 }
399 mHeaderQsPanel.setListening(listening);
400 mListening = listening;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800401
402 if (listening) {
Beverlyb9826dd2018-04-12 15:02:45 -0400403 mZenController.addCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800404 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400405 mContext.registerReceiver(mRingerReceiver,
406 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Rohan Shahd3cf7562018-02-23 11:12:28 -0800407 } else {
Beverlyb9826dd2018-04-12 15:02:45 -0400408 mZenController.removeCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800409 mAlarmController.removeCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400410 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800411 }
Jason Monke5b770e2017-03-03 21:49:29 -0500412 }
413
Evan Laird95896952018-01-22 19:30:05 -0500414 @Override
415 public void onClick(View v) {
Rohan Shahbb662cc2018-04-06 17:57:00 -0700416 if(v == mDateView){
Evan Laird95896952018-01-22 19:30:05 -0500417 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
418 AlarmClock.ACTION_SHOW_ALARMS),0);
419 }
420 }
421
Rohan Shahd3cf7562018-02-23 11:12:28 -0800422 @Override
423 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400424 mNextAlarm = nextAlarm;
425 updateStatusText();
426 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800427
Beverlyb9826dd2018-04-12 15:02:45 -0400428 @Override
429 public void onZenChanged(int zen) {
430 updateStatusText();
431
432 }
433
434 @Override
435 public void onConfigChanged(ZenModeConfig config) {
436 updateStatusText();
437 }
438
Amin Shaikh761c5662018-03-27 16:55:43 -0400439 private void updateTooltipShow() {
440 if (hasStatusText()) {
441 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800442 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400443 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800444 }
445 updateHeaderTextContainerAlphaAnimator();
446 }
447
Amin Shaikh761c5662018-03-27 16:55:43 -0400448 private boolean hasStatusText() {
449 return mNextAlarmTextView.getVisibility() == View.VISIBLE
450 || mRingerModeTextView.getVisibility() == View.VISIBLE;
451 }
452
Rohan Shahd3cf7562018-02-23 11:12:28 -0800453 /**
454 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
455 * the space).
456 */
457 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400458 // If we have status text to show, don't bother fading in the tooltip.
459 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800460 return;
461 }
462
463 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
464 mLongPressTooltipView.animate().cancel();
465 mLongPressTooltipView.setVisibility(View.VISIBLE);
466 mLongPressTooltipView.animate()
467 .alpha(1f)
468 .setDuration(FADE_ANIMATION_DURATION_MS)
469 .setListener(new AnimatorListenerAdapter() {
470 @Override
471 public void onAnimationEnd(Animator animation) {
472 mHandler.postDelayed(
473 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
474 }
475 })
476 .start();
477
478 // Increment and drop the shown count in prefs for the next time we're deciding to
479 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
480 // in prefs (say, from a long press).
481 if (getStoredShownCount() <= mShownCount) {
482 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
483 }
484 }
485 }
486
487 /**
488 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400489 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800490 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400491 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800492 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400493 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800494 mLongPressTooltipView.animate().cancel();
495 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
496 && mLongPressTooltipView.getAlpha() != 0f) {
497 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
498 mLongPressTooltipView.animate()
499 .alpha(0f)
500 .setDuration(FADE_ANIMATION_DURATION_MS)
501 .setListener(new AnimatorListenerAdapter() {
502 @Override
503 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800504 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800505 mLongPressTooltipView.setVisibility(View.INVISIBLE);
506
Amin Shaikh761c5662018-03-27 16:55:43 -0400507 if (shouldShowStatusText) {
508 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800509 }
510 }
511 })
512 .start();
513 } else {
514 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400515 if (shouldShowStatusText) {
516 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800517 }
518 }
519 }
520
521 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400522 * Fades in the updated status text. Note that if there's already a status showing, this will
523 * immediately hide it and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800524 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400525 private void showStatus() {
526 mStatusContainer.setAlpha(0f);
527 mStatusContainer.setVisibility(View.VISIBLE);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800528
Rohan Shaha160ab12018-03-09 15:47:36 -0800529 // Animate the alarm back in. Make sure to clear the animator listener for the animation!
Amin Shaikh761c5662018-03-27 16:55:43 -0400530 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800531 .alpha(1f)
532 .setDuration(FADE_ANIMATION_DURATION_MS)
Rohan Shaha160ab12018-03-09 15:47:36 -0800533 .setListener(null)
Rohan Shahd3cf7562018-02-23 11:12:28 -0800534 .start();
535 }
536
Amin Shaikh761c5662018-03-27 16:55:43 -0400537 /** Fades out and hides the status text. */
538 private void hideStatusText() {
539 if (mStatusContainer.getVisibility() == View.VISIBLE) {
540 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800541 .alpha(0f)
542 .setListener(new AnimatorListenerAdapter() {
543 @Override
544 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800545 if (DEBUG) Log.d(TAG, "hideAlarmText: Hid alarm text");
546
Rohan Shahd3cf7562018-02-23 11:12:28 -0800547 // Reset the alpha regardless of how the animation ends for the next
548 // time we show this view/want to animate it.
Amin Shaikh761c5662018-03-27 16:55:43 -0400549 mStatusContainer.setVisibility(View.INVISIBLE);
550 mStatusContainer.setAlpha(1f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800551 }
552 })
553 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800554 }
555 }
556
Jason Monke5b770e2017-03-03 21:49:29 -0500557 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500558 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500559 }
560
561 public void setQSPanel(final QSPanel qsPanel) {
562 mQsPanel = qsPanel;
563 setupHost(qsPanel.getHost());
564 }
565
566 public void setupHost(final QSTileHost host) {
567 mHost = host;
568 //host.setHeaderView(mExpandIndicator);
569 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
570 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500571
572 // Use SystemUI context to get battery meter colors, and let it use the default tint (white)
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000573 mBatteryMeterView.setColorsFromContext(mHost.getContext());
574 mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Jason Monke5b770e2017-03-03 21:49:29 -0500575 }
576
577 public void setCallback(Callback qsPanelCallback) {
578 mHeaderQsPanel.setCallback(qsPanelCallback);
579 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800580
581 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
582 if (info == null) {
583 return "";
584 }
585 String skeleton = android.text.format.DateFormat
586 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
587 String pattern = android.text.format.DateFormat
588 .getBestDateTimePattern(Locale.getDefault(), skeleton);
589 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
590 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500591
592 public static float getColorIntensity(@ColorInt int color) {
593 return color == Color.WHITE ? 0 : 1;
594 }
Amin Shaikh50d2d1e2018-04-25 14:48:13 -0400595
596 public void setMargins(int sideMargins) {
597 for (int i = 0; i < getChildCount(); i++) {
598 View v = getChildAt(i);
599 if (v == mSystemIconsView || v == mQuickQsStatusIcons || v == mHeaderQsPanel) {
600 continue;
601 }
602 RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams();
603 lp.leftMargin = sideMargins;
604 lp.rightMargin = sideMargins;
605 }
606 }
Jason Monke5b770e2017-03-03 21:49:29 -0500607}