blob: d1913dfddb11431b3f0ca1a51ca6618ce5f0775e [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() {
Evan Laird95896952018-01-22 19:30:05 -0500369 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100370 requestApplyInsets();
371 }
372
373 @Override
374 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
375 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
376 insets.getDisplayCutout(), getDisplay());
377 if (padding == null) {
378 setPadding(0, 0, 0, 0);
379 } else {
380 setPadding(padding.first, 0, padding.second, 0);
381 }
382 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100383 }
384
385 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500386 @VisibleForTesting
387 public void onDetachedFromWindow() {
388 setListening(false);
Evan Laird95896952018-01-22 19:30:05 -0500389 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Jason Monke5b770e2017-03-03 21:49:29 -0500390 super.onDetachedFromWindow();
391 }
392
393 public void setListening(boolean listening) {
394 if (listening == mListening) {
395 return;
396 }
397 mHeaderQsPanel.setListening(listening);
398 mListening = listening;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800399
400 if (listening) {
Beverlyb9826dd2018-04-12 15:02:45 -0400401 mZenController.addCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800402 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400403 mContext.registerReceiver(mRingerReceiver,
404 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Rohan Shahd3cf7562018-02-23 11:12:28 -0800405 } else {
Beverlyb9826dd2018-04-12 15:02:45 -0400406 mZenController.removeCallback(this);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800407 mAlarmController.removeCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400408 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800409 }
Jason Monke5b770e2017-03-03 21:49:29 -0500410 }
411
Evan Laird95896952018-01-22 19:30:05 -0500412 @Override
413 public void onClick(View v) {
414 if(v == mDate){
415 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
416 AlarmClock.ACTION_SHOW_ALARMS),0);
417 }
418 }
419
Rohan Shahd3cf7562018-02-23 11:12:28 -0800420 @Override
421 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400422 mNextAlarm = nextAlarm;
423 updateStatusText();
424 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800425
Beverlyb9826dd2018-04-12 15:02:45 -0400426 @Override
427 public void onZenChanged(int zen) {
428 updateStatusText();
429
430 }
431
432 @Override
433 public void onConfigChanged(ZenModeConfig config) {
434 updateStatusText();
435 }
436
Amin Shaikh761c5662018-03-27 16:55:43 -0400437 private void updateTooltipShow() {
438 if (hasStatusText()) {
439 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800440 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400441 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800442 }
443 updateHeaderTextContainerAlphaAnimator();
444 }
445
Amin Shaikh761c5662018-03-27 16:55:43 -0400446 private boolean hasStatusText() {
447 return mNextAlarmTextView.getVisibility() == View.VISIBLE
448 || mRingerModeTextView.getVisibility() == View.VISIBLE;
449 }
450
Rohan Shahd3cf7562018-02-23 11:12:28 -0800451 /**
452 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
453 * the space).
454 */
455 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400456 // If we have status text to show, don't bother fading in the tooltip.
457 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800458 return;
459 }
460
461 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
462 mLongPressTooltipView.animate().cancel();
463 mLongPressTooltipView.setVisibility(View.VISIBLE);
464 mLongPressTooltipView.animate()
465 .alpha(1f)
466 .setDuration(FADE_ANIMATION_DURATION_MS)
467 .setListener(new AnimatorListenerAdapter() {
468 @Override
469 public void onAnimationEnd(Animator animation) {
470 mHandler.postDelayed(
471 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
472 }
473 })
474 .start();
475
476 // Increment and drop the shown count in prefs for the next time we're deciding to
477 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
478 // in prefs (say, from a long press).
479 if (getStoredShownCount() <= mShownCount) {
480 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
481 }
482 }
483 }
484
485 /**
486 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400487 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800488 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400489 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800490 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400491 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800492 mLongPressTooltipView.animate().cancel();
493 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
494 && mLongPressTooltipView.getAlpha() != 0f) {
495 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
496 mLongPressTooltipView.animate()
497 .alpha(0f)
498 .setDuration(FADE_ANIMATION_DURATION_MS)
499 .setListener(new AnimatorListenerAdapter() {
500 @Override
501 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800502 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800503 mLongPressTooltipView.setVisibility(View.INVISIBLE);
504
Amin Shaikh761c5662018-03-27 16:55:43 -0400505 if (shouldShowStatusText) {
506 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800507 }
508 }
509 })
510 .start();
511 } else {
512 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400513 if (shouldShowStatusText) {
514 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800515 }
516 }
517 }
518
519 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400520 * Fades in the updated status text. Note that if there's already a status showing, this will
521 * immediately hide it and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800522 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400523 private void showStatus() {
524 mStatusContainer.setAlpha(0f);
525 mStatusContainer.setVisibility(View.VISIBLE);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800526
Rohan Shaha160ab12018-03-09 15:47:36 -0800527 // Animate the alarm back in. Make sure to clear the animator listener for the animation!
Amin Shaikh761c5662018-03-27 16:55:43 -0400528 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800529 .alpha(1f)
530 .setDuration(FADE_ANIMATION_DURATION_MS)
Rohan Shaha160ab12018-03-09 15:47:36 -0800531 .setListener(null)
Rohan Shahd3cf7562018-02-23 11:12:28 -0800532 .start();
533 }
534
Amin Shaikh761c5662018-03-27 16:55:43 -0400535 /** Fades out and hides the status text. */
536 private void hideStatusText() {
537 if (mStatusContainer.getVisibility() == View.VISIBLE) {
538 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800539 .alpha(0f)
540 .setListener(new AnimatorListenerAdapter() {
541 @Override
542 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800543 if (DEBUG) Log.d(TAG, "hideAlarmText: Hid alarm text");
544
Rohan Shahd3cf7562018-02-23 11:12:28 -0800545 // Reset the alpha regardless of how the animation ends for the next
546 // time we show this view/want to animate it.
Amin Shaikh761c5662018-03-27 16:55:43 -0400547 mStatusContainer.setVisibility(View.INVISIBLE);
548 mStatusContainer.setAlpha(1f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800549 }
550 })
551 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800552 }
553 }
554
Jason Monke5b770e2017-03-03 21:49:29 -0500555 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500556 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500557 }
558
559 public void setQSPanel(final QSPanel qsPanel) {
560 mQsPanel = qsPanel;
561 setupHost(qsPanel.getHost());
562 }
563
564 public void setupHost(final QSTileHost host) {
565 mHost = host;
566 //host.setHeaderView(mExpandIndicator);
567 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
568 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500569
570 // Use SystemUI context to get battery meter colors, and let it use the default tint (white)
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000571 mBatteryMeterView.setColorsFromContext(mHost.getContext());
572 mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Jason Monke5b770e2017-03-03 21:49:29 -0500573 }
574
575 public void setCallback(Callback qsPanelCallback) {
576 mHeaderQsPanel.setCallback(qsPanelCallback);
577 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800578
579 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
580 if (info == null) {
581 return "";
582 }
583 String skeleton = android.text.format.DateFormat
584 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
585 String pattern = android.text.format.DateFormat
586 .getBestDateTimePattern(Locale.getDefault(), skeleton);
587 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
588 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500589
590 public static float getColorIntensity(@ColorInt int color) {
591 return color == Color.WHITE ? 0 : 1;
592 }
Jason Monke5b770e2017-03-03 21:49:29 -0500593}