blob: 2dcb72362b0a38924a08470e740ed4b87d3a340e [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;
Jason Monke5b770e2017-03-03 21:49:29 -050044import android.widget.RelativeLayout;
Rohan Shahd3cf7562018-02-23 11:12:28 -080045import android.widget.TextView;
Jason Monke5b770e2017-03-03 21:49:29 -050046
47import com.android.settingslib.Utils;
48import com.android.systemui.BatteryMeterView;
49import com.android.systemui.Dependency;
Rohan Shahd3cf7562018-02-23 11:12:28 -080050import com.android.systemui.Prefs;
Jason Monke5b770e2017-03-03 21:49:29 -050051import com.android.systemui.R;
52import com.android.systemui.plugins.ActivityStarter;
53import com.android.systemui.qs.QSDetail.Callback;
Adrian Roos13836052018-03-15 21:06:37 +010054import com.android.systemui.statusbar.phone.PhoneStatusBarView;
Evan Laird95896952018-01-22 19:30:05 -050055import com.android.systemui.statusbar.phone.StatusBarIconController;
56import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000057import com.android.systemui.statusbar.policy.Clock;
Evan Laird20b87bf2018-04-12 09:54:11 -040058import com.android.systemui.statusbar.phone.StatusIconContainer;
Evan Laird39254d42018-01-18 16:05:30 -050059import com.android.systemui.statusbar.policy.DarkIconDispatcher;
Jason Monk824ffff2017-04-11 15:49:06 -040060import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Rohan Shahcc3d1d82018-03-30 21:24:17 +000061import com.android.systemui.statusbar.policy.DateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -080062import com.android.systemui.statusbar.policy.NextAlarmController;
Beverlyb9826dd2018-04-12 15:02:45 -040063import com.android.systemui.statusbar.policy.ZenModeController;
Jason Monke5b770e2017-03-03 21:49:29 -050064
Lucas Dupin1f7374a2018-02-26 18:08:33 -080065import java.util.Locale;
Beverlyb9826dd2018-04-12 15:02:45 -040066import java.util.Objects;
Lucas Dupin1f7374a2018-02-26 18:08:33 -080067
Rohan Shahd3cf7562018-02-23 11:12:28 -080068/**
69 * View that contains the top-most bits of the screen (primarily the status bar with date, time, and
70 * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner
71 * contents.
72 */
Amin Shaikhf09450b2018-04-06 17:32:45 -040073public class QuickStatusBarHeader extends RelativeLayout implements
Beverlyb9826dd2018-04-12 15:02:45 -040074 View.OnClickListener, NextAlarmController.NextAlarmChangeCallback,
75 ZenModeController.Callback {
Rohan Shaha160ab12018-03-09 15:47:36 -080076 private static final String TAG = "QuickStatusBarHeader";
77 private static final boolean DEBUG = false;
Jason Monke5b770e2017-03-03 21:49:29 -050078
Rohan Shahd3cf7562018-02-23 11:12:28 -080079 /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */
80 private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6;
81 private static final int FADE_ANIMATION_DURATION_MS = 300;
82 private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0;
Rohan Shahb6a915c2018-03-01 11:57:00 -080083 public static final int MAX_TOOLTIP_SHOWN_COUNT = 2;
Rohan Shahd3cf7562018-02-23 11:12:28 -080084
85 private final Handler mHandler = new Handler();
Jason Monke5b770e2017-03-03 21:49:29 -050086
87 private QSPanel mQsPanel;
88
89 private boolean mExpanded;
90 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +010091 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -050092
93 protected QuickQSPanel mHeaderQsPanel;
94 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -050095 private TintedIconManager mIconManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080096 private TouchAnimator mStatusIconsAlphaAnimator;
97 private TouchAnimator mHeaderTextContainerAlphaAnimator;
Evan Laird95896952018-01-22 19:30:05 -050098
Rohan Shahcc3d1d82018-03-30 21:24:17 +000099 private View mSystemIconsView;
Evan Laird95896952018-01-22 19:30:05 -0500100 private View mQuickQsStatusIcons;
Evan Laird4ea2a492018-01-22 11:29:12 -0500101 private View mDate;
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);
Evan Laird4ea2a492018-01-22 11:29:12 -0500151 mDate = findViewById(R.id.date);
152 mDate.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000153 mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons);
Evan Laird95896952018-01-22 19:30:05 -0500154 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
Evan Laird20b87bf2018-04-12 09:54:11 -0400155 StatusIconContainer iconContainer = findViewById(R.id.statusIcons);
156 iconContainer.setShouldRestrictIcons(false);
157 mIconManager = new TintedIconManager(iconContainer);
Jason Monke5b770e2017-03-03 21:49:29 -0500158
Rohan Shahd3cf7562018-02-23 11:12:28 -0800159 // Views corresponding to the header info section (e.g. tooltip and next alarm).
160 mHeaderTextContainerView = findViewById(R.id.header_text_container);
161 mLongPressTooltipView = findViewById(R.id.long_press_tooltip);
Amin Shaikh761c5662018-03-27 16:55:43 -0400162 mStatusContainer = findViewById(R.id.status_container);
163 mStatusSeparator = findViewById(R.id.status_separator);
164 mNextAlarmIcon = findViewById(R.id.next_alarm_icon);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800165 mNextAlarmTextView = findViewById(R.id.next_alarm_text);
Amin Shaikh761c5662018-03-27 16:55:43 -0400166 mRingerModeIcon = findViewById(R.id.ringer_mode_icon);
167 mRingerModeTextView = findViewById(R.id.ringer_mode_text);
Jason Monke5b770e2017-03-03 21:49:29 -0500168
169 updateResources();
170
Jason Monk824ffff2017-04-11 15:49:06 -0400171 Rect tintArea = new Rect(0, 0, 0, 0);
Evan Laird95896952018-01-22 19:30:05 -0500172 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
Amin Shaikh0e003312018-03-08 11:39:01 -0500173 float intensity = getColorIntensity(colorForeground);
Evan Laird95896952018-01-22 19:30:05 -0500174 int fillColor = fillColorForIntensity(intensity, getContext());
175
176 // Set light text on the header icons because they will always be on a black background
Evan Laird39254d42018-01-18 16:05:30 -0500177 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -0500178
179 // Set the correct tint for the status icons so they contrast
180 mIconManager.setTint(fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500181
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000182 mBatteryMeterView = findViewById(R.id.battery);
183 mBatteryMeterView.setForceShowPercent(true);
184 mClockView = findViewById(R.id.clock);
185 mDateView = findViewById(R.id.date);
Jason Monke5b770e2017-03-03 21:49:29 -0500186 }
187
Amin Shaikh761c5662018-03-27 16:55:43 -0400188 private void updateStatusText() {
Beverlyb9826dd2018-04-12 15:02:45 -0400189 boolean changed = updateRingerStatus() || updateAlarmStatus();
190
191 if (changed) {
192 boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
193 boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
194 mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE
195 : View.GONE);
196 updateTooltipShow();
197 }
198 }
199
200 private boolean updateRingerStatus() {
201 boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE;
202 CharSequence originalRingerText = mRingerModeTextView.getText();
203
Amin Shaikh761c5662018-03-27 16:55:43 -0400204 boolean ringerVisible = false;
Beverlyb9826dd2018-04-12 15:02:45 -0400205 if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(),
206 mZenController.getConfig())) {
207 if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
208 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate);
209 mRingerModeTextView.setText(R.string.qs_status_phone_vibrate);
210 ringerVisible = true;
211 } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
212 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent);
213 mRingerModeTextView.setText(R.string.qs_status_phone_muted);
214 ringerVisible = true;
215 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400216 }
217 mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
218 mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
219
Beverlyb9826dd2018-04-12 15:02:45 -0400220 return isOriginalVisible != ringerVisible ||
221 !Objects.equals(originalRingerText, mRingerModeTextView.getText());
222 }
223
224 private boolean updateAlarmStatus() {
225 boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE;
226 CharSequence originalAlarmText = mNextAlarmTextView.getText();
227
Amin Shaikh761c5662018-03-27 16:55:43 -0400228 boolean alarmVisible = false;
229 if (mNextAlarm != null) {
230 alarmVisible = true;
231 mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm));
232 }
233 mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
234 mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400235
Beverlyb9826dd2018-04-12 15:02:45 -0400236 return isOriginalVisible != alarmVisible ||
237 !Objects.equals(originalAlarmText, mNextAlarmTextView.getText());
238 }
Amin Shaikh761c5662018-03-27 16:55:43 -0400239
Jason Monk824ffff2017-04-11 15:49:06 -0400240 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
241 View v = findViewById(id);
242 if (v instanceof DarkReceiver) {
243 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
244 }
245 }
246
Evan Laird95896952018-01-22 19:30:05 -0500247 private int fillColorForIntensity(float intensity, Context context) {
248 if (intensity == 0) {
Amin Shaikh9cac3382018-04-11 17:10:07 -0400249 return context.getColor(R.color.light_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500250 }
Amin Shaikh9cac3382018-04-11 17:10:07 -0400251 return context.getColor(R.color.dark_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500252 }
253
Jason Monke5b770e2017-03-03 21:49:29 -0500254 @Override
255 protected void onConfigurationChanged(Configuration newConfig) {
256 super.onConfigurationChanged(newConfig);
257 updateResources();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000258
259 // Update color schemes in landscape to use wallpaperTextColor
260 boolean shouldUseWallpaperTextColor =
261 newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
262 mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor);
263 mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor);
264 mDateView.useWallpaperTextColor(shouldUseWallpaperTextColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500265 }
266
267 @Override
268 public void onRtlPropertiesChanged(int layoutDirection) {
269 super.onRtlPropertiesChanged(layoutDirection);
270 updateResources();
271 }
272
273 private void updateResources() {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000274 Resources resources = mContext.getResources();
275
276 // Update height for a few views, especially due to landscape mode restricting space.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800277 mHeaderTextContainerView.getLayoutParams().height =
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000278 resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800279 mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams());
280
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000281 mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize(
282 com.android.internal.R.dimen.quick_qs_offset_height);
283 mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
284
Amin Shaikhf09450b2018-04-06 17:32:45 -0400285 getLayoutParams().height = resources.getDimensionPixelSize(mQsDisabled
286 ? com.android.internal.R.dimen.quick_qs_offset_height
287 : com.android.internal.R.dimen.quick_qs_total_height);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000288 setLayoutParams(getLayoutParams());
289
Rohan Shahd3cf7562018-02-23 11:12:28 -0800290 updateStatusIconAlphaAnimator();
291 updateHeaderTextContainerAlphaAnimator();
Evan Laird95896952018-01-22 19:30:05 -0500292 }
293
Rohan Shahd3cf7562018-02-23 11:12:28 -0800294 private void updateStatusIconAlphaAnimator() {
295 mStatusIconsAlphaAnimator = new TouchAnimator.Builder()
Evan Laird95896952018-01-22 19:30:05 -0500296 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
297 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500298 }
299
Rohan Shahd3cf7562018-02-23 11:12:28 -0800300 private void updateHeaderTextContainerAlphaAnimator() {
301 mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder()
302 .addFloat(mHeaderTextContainerView, "alpha", 0, 1)
303 .setStartDelay(.5f)
304 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500305 }
306
307 public void setExpanded(boolean expanded) {
308 if (mExpanded == expanded) return;
309 mExpanded = expanded;
310 mHeaderQsPanel.setExpanded(expanded);
311 updateEverything();
312 }
313
Rohan Shahd3cf7562018-02-23 11:12:28 -0800314 /**
315 * Animates the inner contents based on the given expansion details.
316 *
317 * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen)
318 * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f)
319 * @param panelTranslationY how much the panel has physically moved down vertically (required
320 * for keyguard animations only)
321 */
322 public void setExpansion(boolean isKeyguardShowing, float expansionFraction,
323 float panelTranslationY) {
324 final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction;
325 if (mStatusIconsAlphaAnimator != null) {
326 mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction);
Evan Laird95896952018-01-22 19:30:05 -0500327 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800328
329 if (isKeyguardShowing) {
330 // If the keyguard is showing, we want to offset the text so that it comes in at the
331 // same time as the panel as it slides down.
332 mHeaderTextContainerView.setTranslationY(panelTranslationY);
333 } else {
334 mHeaderTextContainerView.setTranslationY(0f);
335 }
336
337 if (mHeaderTextContainerAlphaAnimator != null) {
338 mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction);
339 }
340
341 // Check the original expansion fraction - we don't want to show the tooltip until the
342 // panel is pulled all the way out.
343 if (expansionFraction == 1f) {
344 // QS is fully expanded, bring in the tooltip.
345 showLongPressTooltip();
346 }
347 }
348
349 /** Returns the latest stored tooltip shown count from SharedPreferences. */
350 private int getStoredShownCount() {
351 return Prefs.getInt(
352 mContext,
353 Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
354 TOOLTIP_NOT_YET_SHOWN_COUNT);
Jason Monke5b770e2017-03-03 21:49:29 -0500355 }
356
Charles Hece2a7c02017-10-11 20:25:20 +0100357 public void disable(int state1, int state2, boolean animate) {
358 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
359 if (disabled == mQsDisabled) return;
360 mQsDisabled = disabled;
361 mHeaderQsPanel.setDisabledByPolicy(disabled);
Amin Shaikhf09450b2018-04-06 17:32:45 -0400362 mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
363 mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
364 updateResources();
Charles Hece2a7c02017-10-11 20:25:20 +0100365 }
366
367 @Override
368 public void onAttachedToWindow() {
Amin Shaikha59215a2018-04-23 08:52:38 -0400369 super.onAttachedToWindow();
Evan Laird95896952018-01-22 19:30:05 -0500370 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100371 requestApplyInsets();
372 }
373
374 @Override
375 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
376 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
377 insets.getDisplayCutout(), getDisplay());
378 if (padding == null) {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400379 mSystemIconsView.setPaddingRelative(
380 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0,
381 getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0);
Adrian Roos13836052018-03-15 21:06:37 +0100382 } else {
Amin Shaikh7d86b042018-04-16 16:00:12 -0400383 mSystemIconsView.setPadding(padding.first, 0, padding.second, 0);
384
Adrian Roos13836052018-03-15 21:06:37 +0100385 }
386 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100387 }
388
389 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500390 @VisibleForTesting
391 public void onDetachedFromWindow() {
392 setListening(false);
Evan Laird95896952018-01-22 19:30:05 -0500393 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Jason Monke5b770e2017-03-03 21:49:29 -0500394 super.onDetachedFromWindow();
395 }
396
397 public void setListening(boolean listening) {
398 if (listening == mListening) {
399 return;
400 }
401 mHeaderQsPanel.setListening(listening);
402 mListening = listening;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800403
404 if (listening) {
Beverlyb9826dd2018-04-12 15:02:45 -0400405 mZenController.addCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800406 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400407 mContext.registerReceiver(mRingerReceiver,
408 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Rohan Shahd3cf7562018-02-23 11:12:28 -0800409 } else {
Beverlyb9826dd2018-04-12 15:02:45 -0400410 mZenController.removeCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800411 mAlarmController.removeCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400412 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800413 }
Jason Monke5b770e2017-03-03 21:49:29 -0500414 }
415
Evan Laird95896952018-01-22 19:30:05 -0500416 @Override
417 public void onClick(View v) {
418 if(v == mDate){
419 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
420 AlarmClock.ACTION_SHOW_ALARMS),0);
421 }
422 }
423
Rohan Shahd3cf7562018-02-23 11:12:28 -0800424 @Override
425 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400426 mNextAlarm = nextAlarm;
427 updateStatusText();
428 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800429
Beverlyb9826dd2018-04-12 15:02:45 -0400430 @Override
431 public void onZenChanged(int zen) {
432 updateStatusText();
433
434 }
435
436 @Override
437 public void onConfigChanged(ZenModeConfig config) {
438 updateStatusText();
439 }
440
Amin Shaikh761c5662018-03-27 16:55:43 -0400441 private void updateTooltipShow() {
442 if (hasStatusText()) {
443 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800444 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400445 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800446 }
447 updateHeaderTextContainerAlphaAnimator();
448 }
449
Amin Shaikh761c5662018-03-27 16:55:43 -0400450 private boolean hasStatusText() {
451 return mNextAlarmTextView.getVisibility() == View.VISIBLE
452 || mRingerModeTextView.getVisibility() == View.VISIBLE;
453 }
454
Rohan Shahd3cf7562018-02-23 11:12:28 -0800455 /**
456 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
457 * the space).
458 */
459 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400460 // If we have status text to show, don't bother fading in the tooltip.
461 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800462 return;
463 }
464
465 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
466 mLongPressTooltipView.animate().cancel();
467 mLongPressTooltipView.setVisibility(View.VISIBLE);
468 mLongPressTooltipView.animate()
469 .alpha(1f)
470 .setDuration(FADE_ANIMATION_DURATION_MS)
471 .setListener(new AnimatorListenerAdapter() {
472 @Override
473 public void onAnimationEnd(Animator animation) {
474 mHandler.postDelayed(
475 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
476 }
477 })
478 .start();
479
480 // Increment and drop the shown count in prefs for the next time we're deciding to
481 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
482 // in prefs (say, from a long press).
483 if (getStoredShownCount() <= mShownCount) {
484 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
485 }
486 }
487 }
488
489 /**
490 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400491 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800492 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400493 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800494 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400495 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800496 mLongPressTooltipView.animate().cancel();
497 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
498 && mLongPressTooltipView.getAlpha() != 0f) {
499 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
500 mLongPressTooltipView.animate()
501 .alpha(0f)
502 .setDuration(FADE_ANIMATION_DURATION_MS)
503 .setListener(new AnimatorListenerAdapter() {
504 @Override
505 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800506 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800507 mLongPressTooltipView.setVisibility(View.INVISIBLE);
508
Amin Shaikh761c5662018-03-27 16:55:43 -0400509 if (shouldShowStatusText) {
510 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800511 }
512 }
513 })
514 .start();
515 } else {
516 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400517 if (shouldShowStatusText) {
518 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800519 }
520 }
521 }
522
523 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400524 * Fades in the updated status text. Note that if there's already a status showing, this will
525 * immediately hide it and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800526 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400527 private void showStatus() {
528 mStatusContainer.setAlpha(0f);
529 mStatusContainer.setVisibility(View.VISIBLE);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800530
Rohan Shaha160ab12018-03-09 15:47:36 -0800531 // Animate the alarm back in. Make sure to clear the animator listener for the animation!
Amin Shaikh761c5662018-03-27 16:55:43 -0400532 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800533 .alpha(1f)
534 .setDuration(FADE_ANIMATION_DURATION_MS)
Rohan Shaha160ab12018-03-09 15:47:36 -0800535 .setListener(null)
Rohan Shahd3cf7562018-02-23 11:12:28 -0800536 .start();
537 }
538
Amin Shaikh761c5662018-03-27 16:55:43 -0400539 /** Fades out and hides the status text. */
540 private void hideStatusText() {
541 if (mStatusContainer.getVisibility() == View.VISIBLE) {
542 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800543 .alpha(0f)
544 .setListener(new AnimatorListenerAdapter() {
545 @Override
546 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800547 if (DEBUG) Log.d(TAG, "hideAlarmText: Hid alarm text");
548
Rohan Shahd3cf7562018-02-23 11:12:28 -0800549 // Reset the alpha regardless of how the animation ends for the next
550 // time we show this view/want to animate it.
Amin Shaikh761c5662018-03-27 16:55:43 -0400551 mStatusContainer.setVisibility(View.INVISIBLE);
552 mStatusContainer.setAlpha(1f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800553 }
554 })
555 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800556 }
557 }
558
Jason Monke5b770e2017-03-03 21:49:29 -0500559 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500560 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500561 }
562
563 public void setQSPanel(final QSPanel qsPanel) {
564 mQsPanel = qsPanel;
565 setupHost(qsPanel.getHost());
566 }
567
568 public void setupHost(final QSTileHost host) {
569 mHost = host;
570 //host.setHeaderView(mExpandIndicator);
571 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
572 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500573
574 // Use SystemUI context to get battery meter colors, and let it use the default tint (white)
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000575 mBatteryMeterView.setColorsFromContext(mHost.getContext());
576 mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Jason Monke5b770e2017-03-03 21:49:29 -0500577 }
578
579 public void setCallback(Callback qsPanelCallback) {
580 mHeaderQsPanel.setCallback(qsPanelCallback);
581 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800582
583 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
584 if (info == null) {
585 return "";
586 }
587 String skeleton = android.text.format.DateFormat
588 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
589 String pattern = android.text.format.DateFormat
590 .getBestDateTimePattern(Locale.getDefault(), skeleton);
591 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
592 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500593
594 public static float getColorIntensity(@ColorInt int color) {
595 return color == Color.WHITE ? 0 : 1;
596 }
Jason Monke5b770e2017-03-03 21:49:29 -0500597}