Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.qs; |
| 16 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 17 | import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 18 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame^] | 21 | import android.annotation.ColorInt; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 23 | import android.app.AlarmManager; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 24 | import android.content.Context; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 25 | import android.content.Intent; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 26 | import android.content.res.Configuration; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 27 | import android.graphics.Color; |
| 28 | import android.graphics.Rect; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 29 | import android.os.Handler; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 30 | import android.provider.AlarmClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 31 | import android.support.annotation.VisibleForTesting; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 32 | import android.text.TextUtils; |
| 33 | import android.text.format.DateUtils; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 34 | import android.util.AttributeSet; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 35 | import android.view.View; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 36 | import android.widget.RelativeLayout; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 37 | import android.widget.TextView; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 38 | |
| 39 | import com.android.settingslib.Utils; |
| 40 | import com.android.systemui.BatteryMeterView; |
| 41 | import com.android.systemui.Dependency; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 42 | import com.android.systemui.Prefs; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 43 | import com.android.systemui.R; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 44 | import com.android.systemui.R.id; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 45 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 46 | import com.android.systemui.plugins.ActivityStarter; |
| 47 | import com.android.systemui.qs.QSDetail.Callback; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 48 | import com.android.systemui.statusbar.CommandQueue; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
| 50 | import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 53 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 54 | |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 55 | import java.util.Locale; |
| 56 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 57 | /** |
| 58 | * View that contains the top-most bits of the screen (primarily the status bar with date, time, and |
| 59 | * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner |
| 60 | * contents. |
| 61 | */ |
| 62 | public class QuickStatusBarHeader extends RelativeLayout implements CommandQueue.Callbacks, |
| 63 | View.OnClickListener, NextAlarmController.NextAlarmChangeCallback { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 64 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 65 | /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */ |
| 66 | private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6; |
| 67 | private static final int FADE_ANIMATION_DURATION_MS = 300; |
| 68 | private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0; |
Rohan Shah | b6a915c | 2018-03-01 11:57:00 -0800 | [diff] [blame] | 69 | public static final int MAX_TOOLTIP_SHOWN_COUNT = 2; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 70 | |
| 71 | private final Handler mHandler = new Handler(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 72 | |
| 73 | private QSPanel mQsPanel; |
| 74 | |
| 75 | private boolean mExpanded; |
| 76 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 77 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 78 | |
| 79 | protected QuickQSPanel mHeaderQsPanel; |
| 80 | protected QSTileHost mHost; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 81 | private TintedIconManager mIconManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 82 | private TouchAnimator mStatusIconsAlphaAnimator; |
| 83 | private TouchAnimator mHeaderTextContainerAlphaAnimator; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 84 | |
| 85 | private View mQuickQsStatusIcons; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 86 | private View mDate; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 87 | private View mHeaderTextContainerView; |
| 88 | /** View corresponding to the next alarm info (including the icon). */ |
| 89 | private View mNextAlarmView; |
| 90 | /** Tooltip for educating users that they can long press on icons to see more details. */ |
| 91 | private View mLongPressTooltipView; |
| 92 | /** {@link TextView} containing the actual text indicating when the next alarm will go off. */ |
| 93 | private TextView mNextAlarmTextView; |
| 94 | |
| 95 | private NextAlarmController mAlarmController; |
| 96 | private String mNextAlarmText; |
| 97 | /** Counts how many times the long press tooltip has been shown to the user. */ |
| 98 | private int mShownCount; |
| 99 | |
| 100 | /** |
| 101 | * Runnable for automatically fading out the long press tooltip (as if it were animating away). |
| 102 | */ |
| 103 | private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 104 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 105 | public QuickStatusBarHeader(Context context, AttributeSet attrs) { |
| 106 | super(context, attrs); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 107 | |
| 108 | mAlarmController = Dependency.get(NextAlarmController.class); |
| 109 | mShownCount = getStoredShownCount(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | protected void onFinishInflate() { |
| 114 | super.onFinishInflate(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 115 | |
| 116 | mHeaderQsPanel = findViewById(R.id.quick_qs_panel); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 117 | mDate = findViewById(R.id.date); |
| 118 | mDate.setOnClickListener(this); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 119 | mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons); |
| 120 | mIconManager = new TintedIconManager(findViewById(R.id.statusIcons)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 121 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 122 | // Views corresponding to the header info section (e.g. tooltip and next alarm). |
| 123 | mHeaderTextContainerView = findViewById(R.id.header_text_container); |
| 124 | mLongPressTooltipView = findViewById(R.id.long_press_tooltip); |
| 125 | mNextAlarmView = findViewById(R.id.next_alarm); |
| 126 | mNextAlarmTextView = findViewById(R.id.next_alarm_text); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 127 | |
| 128 | updateResources(); |
| 129 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 130 | Rect tintArea = new Rect(0, 0, 0, 0); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 131 | int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame^] | 132 | float intensity = getColorIntensity(colorForeground); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 133 | int fillColor = fillColorForIntensity(intensity, getContext()); |
| 134 | |
| 135 | // Set light text on the header icons because they will always be on a black background |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 136 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 137 | applyDarkness(id.signal_cluster, tintArea, intensity, colorForeground); |
| 138 | |
| 139 | // Set the correct tint for the status icons so they contrast |
| 140 | mIconManager.setTint(fillColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 141 | |
| 142 | BatteryMeterView battery = findViewById(R.id.battery); |
| 143 | battery.setForceShowPercent(true); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 146 | private void applyDarkness(int id, Rect tintArea, float intensity, int color) { |
| 147 | View v = findViewById(id); |
| 148 | if (v instanceof DarkReceiver) { |
| 149 | ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); |
| 150 | } |
| 151 | } |
| 152 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 153 | private int fillColorForIntensity(float intensity, Context context) { |
| 154 | if (intensity == 0) { |
| 155 | return context.getColor(R.color.light_mode_icon_color_dual_tone_fill); |
| 156 | } |
| 157 | return context.getColor(R.color.dark_mode_icon_color_dual_tone_fill); |
| 158 | } |
| 159 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 160 | @Override |
| 161 | protected void onConfigurationChanged(Configuration newConfig) { |
| 162 | super.onConfigurationChanged(newConfig); |
| 163 | updateResources(); |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 168 | super.onRtlPropertiesChanged(layoutDirection); |
| 169 | updateResources(); |
| 170 | } |
| 171 | |
| 172 | private void updateResources() { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 173 | // Update height, especially due to landscape mode restricting space. |
| 174 | mHeaderTextContainerView.getLayoutParams().height = |
| 175 | mContext.getResources().getDimensionPixelSize(R.dimen.qs_header_tooltip_height); |
| 176 | mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams()); |
| 177 | |
| 178 | updateStatusIconAlphaAnimator(); |
| 179 | updateHeaderTextContainerAlphaAnimator(); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 182 | private void updateStatusIconAlphaAnimator() { |
| 183 | mStatusIconsAlphaAnimator = new TouchAnimator.Builder() |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 184 | .addFloat(mQuickQsStatusIcons, "alpha", 1, 0) |
| 185 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 188 | private void updateHeaderTextContainerAlphaAnimator() { |
| 189 | mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder() |
| 190 | .addFloat(mHeaderTextContainerView, "alpha", 0, 1) |
| 191 | .setStartDelay(.5f) |
| 192 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | public void setExpanded(boolean expanded) { |
| 196 | if (mExpanded == expanded) return; |
| 197 | mExpanded = expanded; |
| 198 | mHeaderQsPanel.setExpanded(expanded); |
| 199 | updateEverything(); |
| 200 | } |
| 201 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 202 | /** |
| 203 | * Animates the inner contents based on the given expansion details. |
| 204 | * |
| 205 | * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen) |
| 206 | * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f) |
| 207 | * @param panelTranslationY how much the panel has physically moved down vertically (required |
| 208 | * for keyguard animations only) |
| 209 | */ |
| 210 | public void setExpansion(boolean isKeyguardShowing, float expansionFraction, |
| 211 | float panelTranslationY) { |
| 212 | final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction; |
| 213 | if (mStatusIconsAlphaAnimator != null) { |
| 214 | mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 215 | } |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 216 | |
| 217 | if (isKeyguardShowing) { |
| 218 | // If the keyguard is showing, we want to offset the text so that it comes in at the |
| 219 | // same time as the panel as it slides down. |
| 220 | mHeaderTextContainerView.setTranslationY(panelTranslationY); |
| 221 | } else { |
| 222 | mHeaderTextContainerView.setTranslationY(0f); |
| 223 | } |
| 224 | |
| 225 | if (mHeaderTextContainerAlphaAnimator != null) { |
| 226 | mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction); |
| 227 | } |
| 228 | |
| 229 | // Check the original expansion fraction - we don't want to show the tooltip until the |
| 230 | // panel is pulled all the way out. |
| 231 | if (expansionFraction == 1f) { |
| 232 | // QS is fully expanded, bring in the tooltip. |
| 233 | showLongPressTooltip(); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** Returns the latest stored tooltip shown count from SharedPreferences. */ |
| 238 | private int getStoredShownCount() { |
| 239 | return Prefs.getInt( |
| 240 | mContext, |
| 241 | Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, |
| 242 | TOOLTIP_NOT_YET_SHOWN_COUNT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | @Override |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 246 | public void disable(int state1, int state2, boolean animate) { |
| 247 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 248 | if (disabled == mQsDisabled) return; |
| 249 | mQsDisabled = disabled; |
| 250 | mHeaderQsPanel.setDisabledByPolicy(disabled); |
Evan Laird | 19bf52c | 2018-01-24 19:54:58 -0500 | [diff] [blame] | 251 | final int rawHeight = (int) getResources().getDimension( |
| 252 | com.android.internal.R.dimen.quick_qs_total_height); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 253 | getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight; |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public void onAttachedToWindow() { |
| 258 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 259 | Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 263 | @VisibleForTesting |
| 264 | public void onDetachedFromWindow() { |
| 265 | setListening(false); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 266 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 267 | Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 268 | super.onDetachedFromWindow(); |
| 269 | } |
| 270 | |
| 271 | public void setListening(boolean listening) { |
| 272 | if (listening == mListening) { |
| 273 | return; |
| 274 | } |
| 275 | mHeaderQsPanel.setListening(listening); |
| 276 | mListening = listening; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 277 | |
| 278 | if (listening) { |
| 279 | mAlarmController.addCallback(this); |
| 280 | } else { |
| 281 | mAlarmController.removeCallback(this); |
| 282 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 285 | @Override |
| 286 | public void onClick(View v) { |
| 287 | if(v == mDate){ |
| 288 | Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent( |
| 289 | AlarmClock.ACTION_SHOW_ALARMS),0); |
| 290 | } |
| 291 | } |
| 292 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 293 | @Override |
| 294 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 295 | mNextAlarmText = nextAlarm != null ? formatNextAlarm(nextAlarm) : null; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 296 | if (mNextAlarmText != null) { |
| 297 | hideLongPressTooltip(true /* shouldFadeInAlarmText */); |
| 298 | } else { |
| 299 | hideAlarmText(); |
| 300 | } |
| 301 | updateHeaderTextContainerAlphaAnimator(); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying |
| 306 | * the space). |
| 307 | */ |
| 308 | public void showLongPressTooltip() { |
| 309 | // If we have alarm text to show, don't bother fading in the tooltip. |
| 310 | if (!TextUtils.isEmpty(mNextAlarmText)) { |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) { |
| 315 | mLongPressTooltipView.animate().cancel(); |
| 316 | mLongPressTooltipView.setVisibility(View.VISIBLE); |
| 317 | mLongPressTooltipView.animate() |
| 318 | .alpha(1f) |
| 319 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 320 | .setListener(new AnimatorListenerAdapter() { |
| 321 | @Override |
| 322 | public void onAnimationEnd(Animator animation) { |
| 323 | mHandler.postDelayed( |
| 324 | mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS); |
| 325 | } |
| 326 | }) |
| 327 | .start(); |
| 328 | |
| 329 | // Increment and drop the shown count in prefs for the next time we're deciding to |
| 330 | // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet |
| 331 | // in prefs (say, from a long press). |
| 332 | if (getStoredShownCount() <= mShownCount) { |
| 333 | Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Fades out the long press tooltip if it's partially visible - short circuits any running |
| 340 | * animation. Additionally has the ability to fade in the alarm info text. |
| 341 | * |
| 342 | * @param shouldShowAlarmText whether we should fade in the next alarm text |
| 343 | */ |
| 344 | private void hideLongPressTooltip(boolean shouldShowAlarmText) { |
| 345 | mLongPressTooltipView.animate().cancel(); |
| 346 | if (mLongPressTooltipView.getVisibility() == View.VISIBLE |
| 347 | && mLongPressTooltipView.getAlpha() != 0f) { |
| 348 | mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable); |
| 349 | mLongPressTooltipView.animate() |
| 350 | .alpha(0f) |
| 351 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 352 | .setListener(new AnimatorListenerAdapter() { |
| 353 | @Override |
| 354 | public void onAnimationEnd(Animator animation) { |
| 355 | mLongPressTooltipView.setVisibility(View.INVISIBLE); |
| 356 | |
| 357 | if (shouldShowAlarmText) { |
| 358 | showAlarmText(); |
| 359 | } |
| 360 | } |
| 361 | }) |
| 362 | .start(); |
| 363 | } else { |
| 364 | mLongPressTooltipView.setVisibility(View.INVISIBLE); |
| 365 | |
| 366 | if (shouldShowAlarmText) { |
| 367 | showAlarmText(); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Fades in the updated alarm text. Note that if there's already an alarm showing, this will |
| 374 | * immediately hide it and fade in the updated time. |
| 375 | */ |
| 376 | private void showAlarmText() { |
| 377 | mNextAlarmView.setAlpha(0f); |
| 378 | mNextAlarmView.setVisibility(View.VISIBLE); |
| 379 | mNextAlarmTextView.setText(mNextAlarmText); |
| 380 | |
| 381 | mNextAlarmView.animate() |
| 382 | .alpha(1f) |
| 383 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 384 | .start(); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Fades out and hides the next alarm text. This also resets the text contents to null in |
| 389 | * preparation for the next alarm update. |
| 390 | */ |
| 391 | private void hideAlarmText() { |
| 392 | if (mNextAlarmView.getVisibility() == View.VISIBLE) { |
| 393 | mNextAlarmView.animate() |
| 394 | .alpha(0f) |
| 395 | .setListener(new AnimatorListenerAdapter() { |
| 396 | @Override |
| 397 | public void onAnimationEnd(Animator animation) { |
| 398 | // Reset the alpha regardless of how the animation ends for the next |
| 399 | // time we show this view/want to animate it. |
| 400 | mNextAlarmView.setVisibility(View.INVISIBLE); |
| 401 | mNextAlarmView.setAlpha(1f); |
| 402 | mNextAlarmTextView.setText(null); |
| 403 | } |
| 404 | }) |
| 405 | .start(); |
| 406 | } else { |
| 407 | // Next alarm view is already hidden, only need to clear the text. |
| 408 | mNextAlarmTextView.setText(null); |
| 409 | } |
| 410 | } |
| 411 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 412 | public void updateEverything() { |
Jason Monk | 1fdde2d | 2017-03-08 09:39:21 -0500 | [diff] [blame] | 413 | post(() -> setClickable(false)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | public void setQSPanel(final QSPanel qsPanel) { |
| 417 | mQsPanel = qsPanel; |
| 418 | setupHost(qsPanel.getHost()); |
| 419 | } |
| 420 | |
| 421 | public void setupHost(final QSTileHost host) { |
| 422 | mHost = host; |
| 423 | //host.setHeaderView(mExpandIndicator); |
| 424 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
| 425 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 426 | |
| 427 | // Use SystemUI context to get battery meter colors, and let it use the default tint (white) |
| 428 | BatteryMeterView battery = findViewById(R.id.battery); |
| 429 | battery.setColorsFromContext(mHost.getContext()); |
| 430 | battery.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | public void setCallback(Callback qsPanelCallback) { |
| 434 | mHeaderQsPanel.setCallback(qsPanelCallback); |
| 435 | } |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 436 | |
| 437 | private String formatNextAlarm(AlarmManager.AlarmClockInfo info) { |
| 438 | if (info == null) { |
| 439 | return ""; |
| 440 | } |
| 441 | String skeleton = android.text.format.DateFormat |
| 442 | .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma"; |
| 443 | String pattern = android.text.format.DateFormat |
| 444 | .getBestDateTimePattern(Locale.getDefault(), skeleton); |
| 445 | return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString(); |
| 446 | } |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame^] | 447 | |
| 448 | public static float getColorIntensity(@ColorInt int color) { |
| 449 | return color == Color.WHITE ? 0 : 1; |
| 450 | } |
| 451 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 452 | } |