blob: 216fa78f1370dc48607c4bc920f8f279bdb46db3 [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;
Jason Monke5b770e2017-03-03 21:49:29 -050035import android.support.annotation.VisibleForTesting;
Rohan Shahd3cf7562018-02-23 11:12:28 -080036import android.text.format.DateUtils;
Jason Monke5b770e2017-03-03 21:49:29 -050037import android.util.AttributeSet;
Rohan Shaha160ab12018-03-09 15:47:36 -080038import android.util.Log;
Adrian Roos13836052018-03-15 21:06:37 +010039import android.util.Pair;
Jason Monk824ffff2017-04-11 15:49:06 -040040import android.view.View;
Adrian Roos13836052018-03-15 21:06:37 +010041import android.view.WindowInsets;
Amin Shaikh761c5662018-03-27 16:55:43 -040042import android.widget.ImageView;
Jason Monke5b770e2017-03-03 21:49:29 -050043import android.widget.RelativeLayout;
Rohan Shahd3cf7562018-02-23 11:12:28 -080044import android.widget.TextView;
Jason Monke5b770e2017-03-03 21:49:29 -050045
46import com.android.settingslib.Utils;
47import com.android.systemui.BatteryMeterView;
48import com.android.systemui.Dependency;
Rohan Shahd3cf7562018-02-23 11:12:28 -080049import com.android.systemui.Prefs;
Jason Monke5b770e2017-03-03 21:49:29 -050050import com.android.systemui.R;
Charles Hece2a7c02017-10-11 20:25:20 +010051import com.android.systemui.SysUiServiceProvider;
Jason Monke5b770e2017-03-03 21:49:29 -050052import com.android.systemui.plugins.ActivityStarter;
53import com.android.systemui.qs.QSDetail.Callback;
Charles Hece2a7c02017-10-11 20:25:20 +010054import com.android.systemui.statusbar.CommandQueue;
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 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;
Jason Monke5b770e2017-03-03 21:49:29 -050063
Lucas Dupin1f7374a2018-02-26 18:08:33 -080064import java.util.Locale;
65
Rohan Shahd3cf7562018-02-23 11:12:28 -080066/**
67 * View that contains the top-most bits of the screen (primarily the status bar with date, time, and
68 * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner
69 * contents.
70 */
Amin Shaikhf09450b2018-04-06 17:32:45 -040071public class QuickStatusBarHeader extends RelativeLayout implements
Rohan Shahd3cf7562018-02-23 11:12:28 -080072 View.OnClickListener, NextAlarmController.NextAlarmChangeCallback {
Rohan Shaha160ab12018-03-09 15:47:36 -080073 private static final String TAG = "QuickStatusBarHeader";
74 private static final boolean DEBUG = false;
Jason Monke5b770e2017-03-03 21:49:29 -050075
Rohan Shahd3cf7562018-02-23 11:12:28 -080076 /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */
77 private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6;
78 private static final int FADE_ANIMATION_DURATION_MS = 300;
79 private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0;
Rohan Shahb6a915c2018-03-01 11:57:00 -080080 public static final int MAX_TOOLTIP_SHOWN_COUNT = 2;
Rohan Shahd3cf7562018-02-23 11:12:28 -080081
82 private final Handler mHandler = new Handler();
Jason Monke5b770e2017-03-03 21:49:29 -050083
84 private QSPanel mQsPanel;
85
86 private boolean mExpanded;
87 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +010088 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -050089
90 protected QuickQSPanel mHeaderQsPanel;
91 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -050092 private TintedIconManager mIconManager;
Rohan Shahd3cf7562018-02-23 11:12:28 -080093 private TouchAnimator mStatusIconsAlphaAnimator;
94 private TouchAnimator mHeaderTextContainerAlphaAnimator;
Evan Laird95896952018-01-22 19:30:05 -050095
Rohan Shahcc3d1d82018-03-30 21:24:17 +000096 private View mSystemIconsView;
Evan Laird95896952018-01-22 19:30:05 -050097 private View mQuickQsStatusIcons;
Evan Laird4ea2a492018-01-22 11:29:12 -050098 private View mDate;
Rohan Shahd3cf7562018-02-23 11:12:28 -080099 private View mHeaderTextContainerView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400100 /** View containing the next alarm and ringer mode info. */
101 private View mStatusContainer;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800102 /** Tooltip for educating users that they can long press on icons to see more details. */
103 private View mLongPressTooltipView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400104
105 private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
106 private AlarmManager.AlarmClockInfo mNextAlarm;
107
108 private ImageView mNextAlarmIcon;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800109 /** {@link TextView} containing the actual text indicating when the next alarm will go off. */
110 private TextView mNextAlarmTextView;
Amin Shaikh761c5662018-03-27 16:55:43 -0400111 private View mStatusSeparator;
112 private ImageView mRingerModeIcon;
113 private TextView mRingerModeTextView;
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000114 private BatteryMeterView mBatteryMeterView;
115 private Clock mClockView;
116 private DateView mDateView;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800117
118 private NextAlarmController mAlarmController;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800119 /** Counts how many times the long press tooltip has been shown to the user. */
120 private int mShownCount;
121
Amin Shaikh761c5662018-03-27 16:55:43 -0400122 private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() {
123 @Override
124 public void onReceive(Context context, Intent intent) {
125 mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1);
126 updateStatusText();
127 }
128 };
129
Rohan Shahd3cf7562018-02-23 11:12:28 -0800130 /**
131 * Runnable for automatically fading out the long press tooltip (as if it were animating away).
132 */
133 private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false);
Evan Laird4ea2a492018-01-22 11:29:12 -0500134
Jason Monke5b770e2017-03-03 21:49:29 -0500135 public QuickStatusBarHeader(Context context, AttributeSet attrs) {
136 super(context, attrs);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800137 mAlarmController = Dependency.get(NextAlarmController.class);
138 mShownCount = getStoredShownCount();
Jason Monke5b770e2017-03-03 21:49:29 -0500139 }
140
141 @Override
142 protected void onFinishInflate() {
143 super.onFinishInflate();
Jason Monke5b770e2017-03-03 21:49:29 -0500144
145 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Evan Laird4ea2a492018-01-22 11:29:12 -0500146 mDate = findViewById(R.id.date);
147 mDate.setOnClickListener(this);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000148 mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons);
Evan Laird95896952018-01-22 19:30:05 -0500149 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
150 mIconManager = new TintedIconManager(findViewById(R.id.statusIcons));
Jason Monke5b770e2017-03-03 21:49:29 -0500151
Rohan Shahd3cf7562018-02-23 11:12:28 -0800152 // Views corresponding to the header info section (e.g. tooltip and next alarm).
153 mHeaderTextContainerView = findViewById(R.id.header_text_container);
154 mLongPressTooltipView = findViewById(R.id.long_press_tooltip);
Amin Shaikh761c5662018-03-27 16:55:43 -0400155 mStatusContainer = findViewById(R.id.status_container);
156 mStatusSeparator = findViewById(R.id.status_separator);
157 mNextAlarmIcon = findViewById(R.id.next_alarm_icon);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800158 mNextAlarmTextView = findViewById(R.id.next_alarm_text);
Amin Shaikh761c5662018-03-27 16:55:43 -0400159 mRingerModeIcon = findViewById(R.id.ringer_mode_icon);
160 mRingerModeTextView = findViewById(R.id.ringer_mode_text);
Jason Monke5b770e2017-03-03 21:49:29 -0500161
162 updateResources();
163
Jason Monk824ffff2017-04-11 15:49:06 -0400164 Rect tintArea = new Rect(0, 0, 0, 0);
Evan Laird95896952018-01-22 19:30:05 -0500165 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
Amin Shaikh0e003312018-03-08 11:39:01 -0500166 float intensity = getColorIntensity(colorForeground);
Evan Laird95896952018-01-22 19:30:05 -0500167 int fillColor = fillColorForIntensity(intensity, getContext());
168
169 // Set light text on the header icons because they will always be on a black background
Evan Laird39254d42018-01-18 16:05:30 -0500170 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -0500171
172 // Set the correct tint for the status icons so they contrast
173 mIconManager.setTint(fillColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500174
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000175 mBatteryMeterView = findViewById(R.id.battery);
176 mBatteryMeterView.setForceShowPercent(true);
177 mClockView = findViewById(R.id.clock);
178 mDateView = findViewById(R.id.date);
Jason Monke5b770e2017-03-03 21:49:29 -0500179 }
180
Amin Shaikh761c5662018-03-27 16:55:43 -0400181 private void updateStatusText() {
182 boolean ringerVisible = false;
183 if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
184 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate);
Amin Shaikhe4d25a92018-03-30 15:30:29 -0400185 mRingerModeTextView.setText(R.string.qs_status_phone_vibrate);
Amin Shaikh761c5662018-03-27 16:55:43 -0400186 ringerVisible = true;
187 } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
188 mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent);
Amin Shaikhe4d25a92018-03-30 15:30:29 -0400189 mRingerModeTextView.setText(R.string.qs_status_phone_muted);
Amin Shaikh761c5662018-03-27 16:55:43 -0400190 ringerVisible = true;
191 }
192 mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
193 mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE);
194
195 boolean alarmVisible = false;
196 if (mNextAlarm != null) {
197 alarmVisible = true;
198 mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm));
199 }
200 mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
201 mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE);
202 mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE : View.GONE);
203 updateTooltipShow();
204 }
205
206
Jason Monk824ffff2017-04-11 15:49:06 -0400207 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
208 View v = findViewById(id);
209 if (v instanceof DarkReceiver) {
210 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
211 }
212 }
213
Evan Laird95896952018-01-22 19:30:05 -0500214 private int fillColorForIntensity(float intensity, Context context) {
215 if (intensity == 0) {
Amin Shaikh9cac3382018-04-11 17:10:07 -0400216 return context.getColor(R.color.light_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500217 }
Amin Shaikh9cac3382018-04-11 17:10:07 -0400218 return context.getColor(R.color.dark_mode_icon_color_single_tone);
Evan Laird95896952018-01-22 19:30:05 -0500219 }
220
Jason Monke5b770e2017-03-03 21:49:29 -0500221 @Override
222 protected void onConfigurationChanged(Configuration newConfig) {
223 super.onConfigurationChanged(newConfig);
224 updateResources();
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000225
226 // Update color schemes in landscape to use wallpaperTextColor
227 boolean shouldUseWallpaperTextColor =
228 newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
229 mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor);
230 mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor);
231 mDateView.useWallpaperTextColor(shouldUseWallpaperTextColor);
Jason Monke5b770e2017-03-03 21:49:29 -0500232 }
233
234 @Override
235 public void onRtlPropertiesChanged(int layoutDirection) {
236 super.onRtlPropertiesChanged(layoutDirection);
237 updateResources();
238 }
239
240 private void updateResources() {
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000241 Resources resources = mContext.getResources();
242
243 // Update height for a few views, especially due to landscape mode restricting space.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800244 mHeaderTextContainerView.getLayoutParams().height =
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000245 resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800246 mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams());
247
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000248 mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize(
249 com.android.internal.R.dimen.quick_qs_offset_height);
250 mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams());
251
Amin Shaikhf09450b2018-04-06 17:32:45 -0400252 getLayoutParams().height = resources.getDimensionPixelSize(mQsDisabled
253 ? com.android.internal.R.dimen.quick_qs_offset_height
254 : com.android.internal.R.dimen.quick_qs_total_height);
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000255 setLayoutParams(getLayoutParams());
256
Rohan Shahd3cf7562018-02-23 11:12:28 -0800257 updateStatusIconAlphaAnimator();
258 updateHeaderTextContainerAlphaAnimator();
Evan Laird95896952018-01-22 19:30:05 -0500259 }
260
Rohan Shahd3cf7562018-02-23 11:12:28 -0800261 private void updateStatusIconAlphaAnimator() {
262 mStatusIconsAlphaAnimator = new TouchAnimator.Builder()
Evan Laird95896952018-01-22 19:30:05 -0500263 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
264 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500265 }
266
Rohan Shahd3cf7562018-02-23 11:12:28 -0800267 private void updateHeaderTextContainerAlphaAnimator() {
268 mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder()
269 .addFloat(mHeaderTextContainerView, "alpha", 0, 1)
270 .setStartDelay(.5f)
271 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500272 }
273
274 public void setExpanded(boolean expanded) {
275 if (mExpanded == expanded) return;
276 mExpanded = expanded;
277 mHeaderQsPanel.setExpanded(expanded);
278 updateEverything();
279 }
280
Rohan Shahd3cf7562018-02-23 11:12:28 -0800281 /**
282 * Animates the inner contents based on the given expansion details.
283 *
284 * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen)
285 * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f)
286 * @param panelTranslationY how much the panel has physically moved down vertically (required
287 * for keyguard animations only)
288 */
289 public void setExpansion(boolean isKeyguardShowing, float expansionFraction,
290 float panelTranslationY) {
291 final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction;
292 if (mStatusIconsAlphaAnimator != null) {
293 mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction);
Evan Laird95896952018-01-22 19:30:05 -0500294 }
Rohan Shahd3cf7562018-02-23 11:12:28 -0800295
296 if (isKeyguardShowing) {
297 // If the keyguard is showing, we want to offset the text so that it comes in at the
298 // same time as the panel as it slides down.
299 mHeaderTextContainerView.setTranslationY(panelTranslationY);
300 } else {
301 mHeaderTextContainerView.setTranslationY(0f);
302 }
303
304 if (mHeaderTextContainerAlphaAnimator != null) {
305 mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction);
306 }
307
308 // Check the original expansion fraction - we don't want to show the tooltip until the
309 // panel is pulled all the way out.
310 if (expansionFraction == 1f) {
311 // QS is fully expanded, bring in the tooltip.
312 showLongPressTooltip();
313 }
314 }
315
316 /** Returns the latest stored tooltip shown count from SharedPreferences. */
317 private int getStoredShownCount() {
318 return Prefs.getInt(
319 mContext,
320 Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT,
321 TOOLTIP_NOT_YET_SHOWN_COUNT);
Jason Monke5b770e2017-03-03 21:49:29 -0500322 }
323
Charles Hece2a7c02017-10-11 20:25:20 +0100324 public void disable(int state1, int state2, boolean animate) {
325 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
326 if (disabled == mQsDisabled) return;
327 mQsDisabled = disabled;
328 mHeaderQsPanel.setDisabledByPolicy(disabled);
Amin Shaikhf09450b2018-04-06 17:32:45 -0400329 mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
330 mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE);
331 updateResources();
Charles Hece2a7c02017-10-11 20:25:20 +0100332 }
333
334 @Override
335 public void onAttachedToWindow() {
Evan Laird95896952018-01-22 19:30:05 -0500336 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Adrian Roos13836052018-03-15 21:06:37 +0100337 requestApplyInsets();
338 }
339
340 @Override
341 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
342 Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins(
343 insets.getDisplayCutout(), getDisplay());
344 if (padding == null) {
345 setPadding(0, 0, 0, 0);
346 } else {
347 setPadding(padding.first, 0, padding.second, 0);
348 }
349 return super.onApplyWindowInsets(insets);
Charles Hece2a7c02017-10-11 20:25:20 +0100350 }
351
352 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500353 @VisibleForTesting
354 public void onDetachedFromWindow() {
355 setListening(false);
Evan Laird95896952018-01-22 19:30:05 -0500356 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Jason Monke5b770e2017-03-03 21:49:29 -0500357 super.onDetachedFromWindow();
358 }
359
360 public void setListening(boolean listening) {
361 if (listening == mListening) {
362 return;
363 }
364 mHeaderQsPanel.setListening(listening);
365 mListening = listening;
Rohan Shahd3cf7562018-02-23 11:12:28 -0800366
367 if (listening) {
368 mAlarmController.addCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400369 mContext.registerReceiver(mRingerReceiver,
370 new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION));
Rohan Shahd3cf7562018-02-23 11:12:28 -0800371 } else {
372 mAlarmController.removeCallback(this);
Amin Shaikh761c5662018-03-27 16:55:43 -0400373 mContext.unregisterReceiver(mRingerReceiver);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800374 }
Jason Monke5b770e2017-03-03 21:49:29 -0500375 }
376
Evan Laird95896952018-01-22 19:30:05 -0500377 @Override
378 public void onClick(View v) {
379 if(v == mDate){
380 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
381 AlarmClock.ACTION_SHOW_ALARMS),0);
382 }
383 }
384
Rohan Shahd3cf7562018-02-23 11:12:28 -0800385 @Override
386 public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
Amin Shaikh761c5662018-03-27 16:55:43 -0400387 mNextAlarm = nextAlarm;
388 updateStatusText();
389 }
Rohan Shaha160ab12018-03-09 15:47:36 -0800390
Amin Shaikh761c5662018-03-27 16:55:43 -0400391 private void updateTooltipShow() {
392 if (hasStatusText()) {
393 hideLongPressTooltip(true /* shouldShowStatusText */);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800394 } else {
Amin Shaikh761c5662018-03-27 16:55:43 -0400395 hideStatusText();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800396 }
397 updateHeaderTextContainerAlphaAnimator();
398 }
399
Amin Shaikh761c5662018-03-27 16:55:43 -0400400 private boolean hasStatusText() {
401 return mNextAlarmTextView.getVisibility() == View.VISIBLE
402 || mRingerModeTextView.getVisibility() == View.VISIBLE;
403 }
404
Rohan Shahd3cf7562018-02-23 11:12:28 -0800405 /**
406 * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying
407 * the space).
408 */
409 public void showLongPressTooltip() {
Amin Shaikh761c5662018-03-27 16:55:43 -0400410 // If we have status text to show, don't bother fading in the tooltip.
411 if (hasStatusText()) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800412 return;
413 }
414
415 if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) {
416 mLongPressTooltipView.animate().cancel();
417 mLongPressTooltipView.setVisibility(View.VISIBLE);
418 mLongPressTooltipView.animate()
419 .alpha(1f)
420 .setDuration(FADE_ANIMATION_DURATION_MS)
421 .setListener(new AnimatorListenerAdapter() {
422 @Override
423 public void onAnimationEnd(Animator animation) {
424 mHandler.postDelayed(
425 mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS);
426 }
427 })
428 .start();
429
430 // Increment and drop the shown count in prefs for the next time we're deciding to
431 // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet
432 // in prefs (say, from a long press).
433 if (getStoredShownCount() <= mShownCount) {
434 Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount);
435 }
436 }
437 }
438
439 /**
440 * Fades out the long press tooltip if it's partially visible - short circuits any running
Amin Shaikh761c5662018-03-27 16:55:43 -0400441 * animation. Additionally has the ability to fade in the status info text.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800442 *
Amin Shaikh761c5662018-03-27 16:55:43 -0400443 * @param shouldShowStatusText whether we should fade in the status text
Rohan Shahd3cf7562018-02-23 11:12:28 -0800444 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400445 private void hideLongPressTooltip(boolean shouldShowStatusText) {
Rohan Shahd3cf7562018-02-23 11:12:28 -0800446 mLongPressTooltipView.animate().cancel();
447 if (mLongPressTooltipView.getVisibility() == View.VISIBLE
448 && mLongPressTooltipView.getAlpha() != 0f) {
449 mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable);
450 mLongPressTooltipView.animate()
451 .alpha(0f)
452 .setDuration(FADE_ANIMATION_DURATION_MS)
453 .setListener(new AnimatorListenerAdapter() {
454 @Override
455 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800456 if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip");
Rohan Shahd3cf7562018-02-23 11:12:28 -0800457 mLongPressTooltipView.setVisibility(View.INVISIBLE);
458
Amin Shaikh761c5662018-03-27 16:55:43 -0400459 if (shouldShowStatusText) {
460 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800461 }
462 }
463 })
464 .start();
465 } else {
466 mLongPressTooltipView.setVisibility(View.INVISIBLE);
Amin Shaikh761c5662018-03-27 16:55:43 -0400467 if (shouldShowStatusText) {
468 showStatus();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800469 }
470 }
471 }
472
473 /**
Amin Shaikh761c5662018-03-27 16:55:43 -0400474 * Fades in the updated status text. Note that if there's already a status showing, this will
475 * immediately hide it and fade in the updated status.
Rohan Shahd3cf7562018-02-23 11:12:28 -0800476 */
Amin Shaikh761c5662018-03-27 16:55:43 -0400477 private void showStatus() {
478 mStatusContainer.setAlpha(0f);
479 mStatusContainer.setVisibility(View.VISIBLE);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800480
Rohan Shaha160ab12018-03-09 15:47:36 -0800481 // Animate the alarm back in. Make sure to clear the animator listener for the animation!
Amin Shaikh761c5662018-03-27 16:55:43 -0400482 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800483 .alpha(1f)
484 .setDuration(FADE_ANIMATION_DURATION_MS)
Rohan Shaha160ab12018-03-09 15:47:36 -0800485 .setListener(null)
Rohan Shahd3cf7562018-02-23 11:12:28 -0800486 .start();
487 }
488
Amin Shaikh761c5662018-03-27 16:55:43 -0400489 /** Fades out and hides the status text. */
490 private void hideStatusText() {
491 if (mStatusContainer.getVisibility() == View.VISIBLE) {
492 mStatusContainer.animate()
Rohan Shahd3cf7562018-02-23 11:12:28 -0800493 .alpha(0f)
494 .setListener(new AnimatorListenerAdapter() {
495 @Override
496 public void onAnimationEnd(Animator animation) {
Rohan Shaha160ab12018-03-09 15:47:36 -0800497 if (DEBUG) Log.d(TAG, "hideAlarmText: Hid alarm text");
498
Rohan Shahd3cf7562018-02-23 11:12:28 -0800499 // Reset the alpha regardless of how the animation ends for the next
500 // time we show this view/want to animate it.
Amin Shaikh761c5662018-03-27 16:55:43 -0400501 mStatusContainer.setVisibility(View.INVISIBLE);
502 mStatusContainer.setAlpha(1f);
Rohan Shahd3cf7562018-02-23 11:12:28 -0800503 }
504 })
505 .start();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800506 }
507 }
508
Jason Monke5b770e2017-03-03 21:49:29 -0500509 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500510 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500511 }
512
513 public void setQSPanel(final QSPanel qsPanel) {
514 mQsPanel = qsPanel;
515 setupHost(qsPanel.getHost());
516 }
517
518 public void setupHost(final QSTileHost host) {
519 mHost = host;
520 //host.setHeaderView(mExpandIndicator);
521 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
522 mHeaderQsPanel.setHost(host, null /* No customization in header */);
Evan Lairdef160f22018-01-29 14:08:45 -0500523
524 // Use SystemUI context to get battery meter colors, and let it use the default tint (white)
Rohan Shahcc3d1d82018-03-30 21:24:17 +0000525 mBatteryMeterView.setColorsFromContext(mHost.getContext());
526 mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Jason Monke5b770e2017-03-03 21:49:29 -0500527 }
528
529 public void setCallback(Callback qsPanelCallback) {
530 mHeaderQsPanel.setCallback(qsPanelCallback);
531 }
Lucas Dupin1f7374a2018-02-26 18:08:33 -0800532
533 private String formatNextAlarm(AlarmManager.AlarmClockInfo info) {
534 if (info == null) {
535 return "";
536 }
537 String skeleton = android.text.format.DateFormat
538 .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma";
539 String pattern = android.text.format.DateFormat
540 .getBestDateTimePattern(Locale.getDefault(), skeleton);
541 return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString();
542 }
Amin Shaikh0e003312018-03-08 11:39:01 -0500543
544 public static float getColorIntensity(@ColorInt int color) {
545 return color == Color.WHITE ? 0 : 1;
546 }
547
Jason Monke5b770e2017-03-03 21:49:29 -0500548}