Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ValueAnimator; |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 22 | import android.annotation.IntDef; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 23 | import android.app.AlarmManager; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 24 | import android.content.Context; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 27 | import android.os.Handler; |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 28 | import android.os.Trace; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Lucas Dupin | a0bf851 | 2017-05-24 17:04:47 -0700 | [diff] [blame] | 30 | import android.util.MathUtils; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 31 | import android.view.View; |
| 32 | import android.view.ViewTreeObserver; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 33 | import android.view.animation.DecelerateInterpolator; |
| 34 | import android.view.animation.Interpolator; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 35 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 36 | import com.android.internal.annotations.VisibleForTesting; |
Lucas Dupin | e2292a9 | 2017-07-06 14:35:30 -0700 | [diff] [blame] | 37 | import com.android.internal.colorextraction.ColorExtractor; |
| 38 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
| 39 | import com.android.internal.colorextraction.ColorExtractor.OnColorsChangedListener; |
Lucas Dupin | 9324aa9 | 2017-07-26 20:29:38 -0700 | [diff] [blame] | 40 | import com.android.internal.graphics.ColorUtils; |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 41 | import com.android.internal.util.function.TriConsumer; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 42 | import com.android.keyguard.KeyguardUpdateMonitor; |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 43 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Lucas Dupin | 314d41f | 2017-05-08 15:52:58 -0700 | [diff] [blame] | 44 | import com.android.systemui.Dependency; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 45 | import com.android.systemui.Dumpable; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 46 | import com.android.systemui.R; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 47 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 48 | import com.android.systemui.statusbar.ScrimView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 49 | import com.android.systemui.statusbar.notification.stack.ViewState; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 50 | import com.android.systemui.util.AlarmTimeout; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 51 | import com.android.systemui.util.wakelock.DelayedWakeLock; |
| 52 | import com.android.systemui.util.wakelock.WakeLock; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 53 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 54 | import java.io.FileDescriptor; |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 55 | import java.io.PrintWriter; |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 56 | import java.lang.annotation.Retention; |
| 57 | import java.lang.annotation.RetentionPolicy; |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 58 | import java.util.function.Consumer; |
| 59 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 60 | /** |
| 61 | * Controls both the scrim behind the notifications and in front of the notifications (when a |
| 62 | * security method gets shown). |
| 63 | */ |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 64 | public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnColorsChangedListener, |
| 65 | Dumpable { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 66 | |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 67 | static final String TAG = "ScrimController"; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 68 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 69 | |
Lucas Dupin | 4749f1b | 2018-04-04 15:09:06 -0700 | [diff] [blame] | 70 | /** |
| 71 | * General scrim animation duration. |
| 72 | */ |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 73 | public static final long ANIMATION_DURATION = 220; |
Lucas Dupin | 4749f1b | 2018-04-04 15:09:06 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Longer duration, currently only used when going to AOD. |
| 76 | */ |
| 77 | public static final long ANIMATION_DURATION_LONG = 1000; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 78 | /** |
| 79 | * When both scrims have 0 alpha. |
| 80 | */ |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 81 | public static final int TRANSPARENT = 0; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 82 | /** |
| 83 | * When scrims aren't transparent (alpha 0) but also not opaque (alpha 1.) |
| 84 | */ |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 85 | public static final int SEMI_TRANSPARENT = 1; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 86 | /** |
| 87 | * When at least 1 scrim is fully opaque (alpha set to 1.) |
| 88 | */ |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 89 | public static final int OPAQUE = 2; |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 90 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 91 | @IntDef(prefix = {"VISIBILITY_"}, value = { |
| 92 | TRANSPARENT, |
| 93 | SEMI_TRANSPARENT, |
| 94 | OPAQUE |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 95 | }) |
| 96 | @Retention(RetentionPolicy.SOURCE) |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 97 | public @interface ScrimVisibility { |
| 98 | } |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 99 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 100 | /** |
| 101 | * Default alpha value for most scrims. |
| 102 | */ |
Lucas Dupin | 3d36dd8 | 2019-01-02 14:38:35 -0800 | [diff] [blame] | 103 | public static final float GRADIENT_SCRIM_ALPHA = 0.2f; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 104 | /** |
Lucas Dupin | 3113db6 | 2019-03-08 18:21:27 -0800 | [diff] [blame] | 105 | * Scrim opacity when the phone is about to wake-up. |
| 106 | */ |
Lucas Dupin | 5f00fa5 | 2019-03-27 22:46:53 -0700 | [diff] [blame] | 107 | public static final float WAKE_SENSOR_SCRIM_ALPHA = 0.6f; |
Lucas Dupin | 3113db6 | 2019-03-08 18:21:27 -0800 | [diff] [blame] | 108 | /** |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 109 | * A scrim varies its opacity based on a busyness factor, for example |
| 110 | * how many notifications are currently visible. |
| 111 | */ |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 112 | public static final float GRADIENT_SCRIM_ALPHA_BUSY = 0.7f; |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 113 | |
Lucas Dupin | 55c6e80 | 2018-09-27 18:07:36 -0700 | [diff] [blame] | 114 | /** |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 115 | * The most common scrim, the one under the keyguard. |
| 116 | */ |
Lucas Dupin | a0bf851 | 2017-05-24 17:04:47 -0700 | [diff] [blame] | 117 | protected static final float SCRIM_BEHIND_ALPHA_KEYGUARD = GRADIENT_SCRIM_ALPHA; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 118 | |
| 119 | static final int TAG_KEY_ANIM = R.id.scrim; |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 120 | private static final int TAG_START_ALPHA = R.id.scrim_alpha_start; |
| 121 | private static final int TAG_END_ALPHA = R.id.scrim_alpha_end; |
Selim Cinek | 511f270 | 2017-04-10 19:53:01 -0700 | [diff] [blame] | 122 | private static final float NOT_INITIALIZED = -1; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 123 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 124 | private ScrimState mState = ScrimState.UNINITIALIZED; |
| 125 | private final Context mContext; |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 126 | |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 127 | protected final ScrimView mScrimInFront; |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 128 | protected final ScrimView mScrimBehind; |
| 129 | protected final ScrimView mScrimForBubble; |
| 130 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 131 | private final UnlockMethodCache mUnlockMethodCache; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 132 | private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 133 | private final DozeParameters mDozeParameters; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 134 | private final AlarmTimeout mTimeTicker; |
Lucas Dupin | 690c6f5 | 2018-07-10 15:28:57 -0700 | [diff] [blame] | 135 | private final KeyguardVisibilityCallback mKeyguardVisibilityCallback; |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 136 | private final Handler mHandler; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 137 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 138 | private final SysuiColorExtractor mColorExtractor; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 139 | private GradientColors mColors; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 140 | private boolean mNeedsDrawableColorUpdate; |
| 141 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 142 | protected float mScrimBehindAlpha; |
Lucas Dupin | 9324aa9 | 2017-07-26 20:29:38 -0700 | [diff] [blame] | 143 | protected float mScrimBehindAlphaResValue; |
Evan Rosky | 9a89501 | 2016-04-21 11:26:15 -0700 | [diff] [blame] | 144 | protected float mScrimBehindAlphaKeyguard = SCRIM_BEHIND_ALPHA_KEYGUARD; |
Xiaohui Chen | 4dab4b5 | 2016-03-07 12:31:14 -0800 | [diff] [blame] | 145 | |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 146 | // Assuming the shade is expanded during initialization |
| 147 | private float mExpansionFraction = 1f; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 148 | |
| 149 | private boolean mDarkenWhileDragging; |
Lucas Dupin | 67f0263 | 2018-03-12 11:08:31 -0700 | [diff] [blame] | 150 | private boolean mExpansionAffectsAlpha = true; |
Evan Rosky | 9a89501 | 2016-04-21 11:26:15 -0700 | [diff] [blame] | 151 | protected boolean mAnimateChange; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 152 | private boolean mUpdatePending; |
Jorim Jaggi | e93698b | 2016-11-11 18:24:38 -0800 | [diff] [blame] | 153 | private boolean mTracking; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 154 | protected long mAnimationDuration = -1; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 155 | private long mAnimationDelay; |
| 156 | private Runnable mOnAnimationFinished; |
Jorim Jaggi | f5304ad | 2017-07-17 18:31:13 +0200 | [diff] [blame] | 157 | private boolean mDeferFinishedListener; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 158 | private final Interpolator mInterpolator = new DecelerateInterpolator(); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 159 | |
| 160 | private float mInFrontAlpha = NOT_INITIALIZED; |
| 161 | private float mBehindAlpha = NOT_INITIALIZED; |
| 162 | private float mBubbleAlpha = NOT_INITIALIZED; |
| 163 | |
| 164 | private int mInFrontTint; |
| 165 | private int mBehindTint; |
| 166 | private int mBubbleTint; |
| 167 | |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 168 | private boolean mWallpaperVisibilityTimedOut; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 169 | private int mScrimsVisibility; |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 170 | private final TriConsumer<ScrimState, Float, GradientColors> mScrimStateListener; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 171 | private final Consumer<Integer> mScrimVisibleListener; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 172 | private boolean mBlankScreen; |
| 173 | private boolean mScreenBlankingCallbackCalled; |
| 174 | private Callback mCallback; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 175 | private boolean mWallpaperSupportsAmbientMode; |
Lucas Dupin | 3a64ed7 | 2018-02-12 12:44:37 -0800 | [diff] [blame] | 176 | private boolean mScreenOn; |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 177 | |
| 178 | // Scrim blanking callbacks |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 179 | private Runnable mPendingFrameCallback; |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 180 | private Runnable mBlankingTransitionRunnable; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 181 | |
| 182 | private final WakeLock mWakeLock; |
| 183 | private boolean mWakeLockHeld; |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 184 | private boolean mKeyguardOccluded; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 185 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 186 | public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront, ScrimView scrimForBubble, |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 187 | TriConsumer<ScrimState, Float, GradientColors> scrimStateListener, |
shawnlin | 317db37 | 2018-04-09 19:49:48 +0800 | [diff] [blame] | 188 | Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters, |
| 189 | AlarmManager alarmManager) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 190 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 191 | mScrimBehind = scrimBehind; |
| 192 | mScrimInFront = scrimInFront; |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 193 | mScrimForBubble = scrimForBubble; |
| 194 | |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 195 | mScrimStateListener = scrimStateListener; |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 196 | mScrimVisibleListener = scrimVisibleListener; |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 197 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 198 | mContext = scrimBehind.getContext(); |
| 199 | mUnlockMethodCache = UnlockMethodCache.getInstance(mContext); |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 200 | mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 201 | mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
Lucas Dupin | 690c6f5 | 2018-07-10 15:28:57 -0700 | [diff] [blame] | 202 | mKeyguardVisibilityCallback = new KeyguardVisibilityCallback(); |
| 203 | mKeyguardUpdateMonitor.registerCallback(mKeyguardVisibilityCallback); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 204 | mScrimBehindAlphaResValue = mContext.getResources().getFloat(R.dimen.scrim_behind_alpha); |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 205 | mHandler = getHandler(); |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 206 | mTimeTicker = new AlarmTimeout(alarmManager, this::onHideWallpaperTimeout, |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 207 | "hide_aod_wallpaper", mHandler); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 208 | mWakeLock = createWakeLock(); |
Lucas Dupin | 9324aa9 | 2017-07-26 20:29:38 -0700 | [diff] [blame] | 209 | // Scrim alpha is initially set to the value on the resource but might be changed |
| 210 | // to make sure that text on top of it is legible. |
| 211 | mScrimBehindAlpha = mScrimBehindAlphaResValue; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 212 | mDozeParameters = dozeParameters; |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 213 | |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 214 | mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
Lucas Dupin | 314d41f | 2017-05-08 15:52:58 -0700 | [diff] [blame] | 215 | mColorExtractor.addOnColorsChangedListener(this); |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 216 | mColors = mColorExtractor.getNeutralColors(); |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 217 | mNeedsDrawableColorUpdate = true; |
| 218 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 219 | final ScrimState[] states = ScrimState.values(); |
| 220 | for (int i = 0; i < states.length; i++) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 221 | states[i].init(mScrimInFront, mScrimBehind, mScrimForBubble, mDozeParameters); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 222 | states[i].setScrimBehindAlphaKeyguard(mScrimBehindAlphaKeyguard); |
| 223 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 224 | |
Lucas Dupin | 373356b | 2018-04-07 10:50:25 -0700 | [diff] [blame] | 225 | mScrimBehind.setDefaultFocusHighlightEnabled(false); |
| 226 | mScrimInFront.setDefaultFocusHighlightEnabled(false); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 227 | mScrimForBubble.setDefaultFocusHighlightEnabled(false); |
Lucas Dupin | 373356b | 2018-04-07 10:50:25 -0700 | [diff] [blame] | 228 | |
Selim Cinek | 511f270 | 2017-04-10 19:53:01 -0700 | [diff] [blame] | 229 | updateScrims(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 232 | public void transitionTo(ScrimState state) { |
| 233 | transitionTo(state, null); |
| 234 | } |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 235 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 236 | public void transitionTo(ScrimState state, Callback callback) { |
| 237 | if (state == mState) { |
Lucas Dupin | 19aba8e | 2017-12-11 12:42:26 -0800 | [diff] [blame] | 238 | // Call the callback anyway, unless it's already enqueued |
| 239 | if (callback != null && mCallback != callback) { |
| 240 | callback.onFinished(); |
| 241 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 242 | return; |
| 243 | } else if (DEBUG) { |
| 244 | Log.d(TAG, "State changed to: " + state); |
| 245 | } |
| 246 | |
| 247 | if (state == ScrimState.UNINITIALIZED) { |
| 248 | throw new IllegalArgumentException("Cannot change to UNINITIALIZED."); |
| 249 | } |
| 250 | |
Lucas Dupin | 8635c44 | 2017-12-08 10:36:28 -0800 | [diff] [blame] | 251 | final ScrimState oldState = mState; |
| 252 | mState = state; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 253 | Trace.traceCounter(Trace.TRACE_TAG_APP, "scrim_state", mState.getIndex()); |
Lucas Dupin | 8635c44 | 2017-12-08 10:36:28 -0800 | [diff] [blame] | 254 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 255 | if (mCallback != null) { |
| 256 | mCallback.onCancelled(); |
| 257 | } |
| 258 | mCallback = callback; |
| 259 | |
Lucas Dupin | 8635c44 | 2017-12-08 10:36:28 -0800 | [diff] [blame] | 260 | state.prepare(oldState); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 261 | mScreenBlankingCallbackCalled = false; |
| 262 | mAnimationDelay = 0; |
| 263 | mBlankScreen = state.getBlanksScreen(); |
| 264 | mAnimateChange = state.getAnimateChange(); |
| 265 | mAnimationDuration = state.getAnimationDuration(); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 266 | |
| 267 | mInFrontTint = state.getFrontTint(); |
| 268 | mBehindTint = state.getBehindTint(); |
| 269 | mBubbleTint = state.getBubbleTint(); |
| 270 | |
| 271 | mInFrontAlpha = state.getFrontAlpha(); |
| 272 | mBehindAlpha = state.getBehindAlpha(); |
| 273 | mBubbleAlpha = state.getBubbleAlpha(); |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 274 | applyExpansionToAlpha(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 275 | |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 276 | // Scrim might acquire focus when user is navigating with a D-pad or a keyboard. |
| 277 | // We need to disable focus otherwise AOD would end up with a gray overlay. |
| 278 | mScrimInFront.setFocusable(!state.isLowPowerState()); |
| 279 | mScrimBehind.setFocusable(!state.isLowPowerState()); |
| 280 | |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 281 | // Cancel blanking transitions that were pending before we requested a new state |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 282 | if (mPendingFrameCallback != null) { |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 283 | mScrimBehind.removeCallbacks(mPendingFrameCallback); |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 284 | mPendingFrameCallback = null; |
| 285 | } |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 286 | if (mHandler.hasCallbacks(mBlankingTransitionRunnable)) { |
| 287 | mHandler.removeCallbacks(mBlankingTransitionRunnable); |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 288 | mBlankingTransitionRunnable = null; |
| 289 | } |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 290 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 291 | // Showing/hiding the keyguard means that scrim colors have to be switched, not necessary |
| 292 | // to do the same when you're just showing the brightness mirror. |
| 293 | mNeedsDrawableColorUpdate = state != ScrimState.BRIGHTNESS_MIRROR; |
| 294 | |
Lucas Dupin | eea53b3 | 2017-12-18 13:47:14 -0800 | [diff] [blame] | 295 | // The device might sleep if it's entering AOD, we need to make sure that |
| 296 | // the animation plays properly until the last frame. |
| 297 | // It's important to avoid holding the wakelock unless necessary because |
| 298 | // WakeLock#aqcuire will trigger an IPC and will cause jank. |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 299 | if (mState.isLowPowerState()) { |
Lucas Dupin | eea53b3 | 2017-12-18 13:47:14 -0800 | [diff] [blame] | 300 | holdWakeLock(); |
| 301 | } |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 302 | |
TYM Tsai | a71c892 | 2019-01-07 15:57:53 +0800 | [diff] [blame] | 303 | // AOD wallpapers should fade away after a while. |
| 304 | // Docking pulses may take a long time, wallpapers should also fade away after a while. |
Jerry Chang | bde4c0c | 2019-06-13 16:58:41 +0800 | [diff] [blame] | 305 | mWallpaperVisibilityTimedOut = false; |
| 306 | if (shouldFadeAwayWallpaper()) { |
| 307 | mTimeTicker.schedule(mDozeParameters.getWallpaperAodDuration(), |
| 308 | AlarmTimeout.MODE_IGNORE_IF_SCHEDULED); |
Lucas Dupin | c780404 | 2018-12-21 12:26:33 -0800 | [diff] [blame] | 309 | } else { |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 310 | mTimeTicker.cancel(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Lucas Dupin | ff307d5 | 2018-02-05 21:16:39 -0800 | [diff] [blame] | 313 | if (mKeyguardUpdateMonitor.needsSlowUnlockTransition() && mState == ScrimState.UNLOCKED) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 314 | // In case the user isn't unlocked, make sure to delay a bit because the system is hosed |
| 315 | // with too many things at this case, in order to not skip the initial frames. |
| 316 | mScrimInFront.postOnAnimationDelayed(this::scheduleUpdate, 16); |
| 317 | mAnimationDelay = StatusBar.FADE_KEYGUARD_START_DELAY; |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 318 | } else if ((!mDozeParameters.getAlwaysOn() && oldState == ScrimState.AOD) |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 319 | || (mState == ScrimState.AOD && !mDozeParameters.getDisplayNeedsBlanking())) { |
| 320 | // Scheduling a frame isn't enough when: |
| 321 | // • Leaving doze and we need to modify scrim color immediately |
| 322 | // • ColorFade will not kick-in and scrim cannot wait for pre-draw. |
Lucas Dupin | ff307d5 | 2018-02-05 21:16:39 -0800 | [diff] [blame] | 323 | onPreDraw(); |
| 324 | } else { |
| 325 | scheduleUpdate(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 326 | } |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 327 | |
| 328 | dispatchScrimState(mScrimBehind.getViewAlpha()); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Jerry Chang | bde4c0c | 2019-06-13 16:58:41 +0800 | [diff] [blame] | 331 | private boolean shouldFadeAwayWallpaper() { |
| 332 | if (!mWallpaperSupportsAmbientMode) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | if (mState == ScrimState.AOD && mDozeParameters.getAlwaysOn()) { |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | if (mState == ScrimState.PULSING |
| 341 | && mCallback != null && mCallback.shouldTimeoutWallpaper()) { |
| 342 | return true; |
| 343 | } |
| 344 | |
| 345 | return false; |
| 346 | } |
| 347 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 348 | public ScrimState getState() { |
| 349 | return mState; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 350 | } |
| 351 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 352 | protected void setScrimBehindValues(float scrimBehindAlphaKeyguard) { |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 353 | mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 354 | ScrimState[] states = ScrimState.values(); |
| 355 | for (int i = 0; i < states.length; i++) { |
| 356 | states[i].setScrimBehindAlphaKeyguard(scrimBehindAlphaKeyguard); |
| 357 | } |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 358 | scheduleUpdate(); |
| 359 | } |
| 360 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 361 | public void onTrackingStarted() { |
Jorim Jaggi | e93698b | 2016-11-11 18:24:38 -0800 | [diff] [blame] | 362 | mTracking = true; |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 363 | mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 366 | public void onExpandingFinished() { |
Jorim Jaggi | e93698b | 2016-11-11 18:24:38 -0800 | [diff] [blame] | 367 | mTracking = false; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 370 | @VisibleForTesting |
| 371 | protected void onHideWallpaperTimeout() { |
TYM Tsai | a71c892 | 2019-01-07 15:57:53 +0800 | [diff] [blame] | 372 | if (mState != ScrimState.AOD && mState != ScrimState.PULSING) { |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | |
| 376 | holdWakeLock(); |
| 377 | mWallpaperVisibilityTimedOut = true; |
| 378 | mAnimateChange = true; |
| 379 | mAnimationDuration = mDozeParameters.getWallpaperFadeOutDuration(); |
| 380 | scheduleUpdate(); |
| 381 | } |
| 382 | |
| 383 | private void holdWakeLock() { |
| 384 | if (!mWakeLockHeld) { |
| 385 | if (mWakeLock != null) { |
| 386 | mWakeLockHeld = true; |
Lucas Dupin | ee4c9b7 | 2019-02-18 17:04:58 -0800 | [diff] [blame] | 387 | mWakeLock.acquire(TAG); |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 388 | } else { |
| 389 | Log.w(TAG, "Cannot hold wake lock, it has not been set yet"); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 394 | /** |
| 395 | * Current state of the shade expansion when pulling it from the top. |
| 396 | * This value is 1 when on top of the keyguard and goes to 0 as the user drags up. |
| 397 | * |
| 398 | * The expansion fraction is tied to the scrim opacity. |
| 399 | * |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 400 | * @param fraction From 0 to 1 where 0 means collapsed and 1 expanded. |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 401 | */ |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 402 | public void setPanelExpansion(float fraction) { |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 403 | if (mExpansionFraction != fraction) { |
| 404 | mExpansionFraction = fraction; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 405 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 406 | boolean relevantState = (mState == ScrimState.UNLOCKED |
| 407 | || mState == ScrimState.KEYGUARD |
| 408 | || mState == ScrimState.PULSING |
| 409 | || mState == ScrimState.BUBBLE_EXPANDED); |
| 410 | if (!(relevantState && mExpansionAffectsAlpha)) { |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 411 | return; |
| 412 | } |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 413 | applyExpansionToAlpha(); |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 414 | if (mUpdatePending) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 415 | return; |
| 416 | } |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 417 | setOrAdaptCurrentAnimation(mScrimBehind); |
| 418 | setOrAdaptCurrentAnimation(mScrimInFront); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 419 | setOrAdaptCurrentAnimation(mScrimForBubble); |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 420 | dispatchScrimState(mScrimBehind.getViewAlpha()); |
Jerry Chang | bde4c0c | 2019-06-13 16:58:41 +0800 | [diff] [blame] | 421 | |
| 422 | // Reset wallpaper timeout if it's already timeout like expanding panel while PULSING |
| 423 | // and docking. |
| 424 | if (mWallpaperVisibilityTimedOut) { |
| 425 | mWallpaperVisibilityTimedOut = false; |
| 426 | mTimeTicker.schedule(mDozeParameters.getWallpaperAodDuration(), |
| 427 | AlarmTimeout.MODE_IGNORE_IF_SCHEDULED); |
| 428 | } |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
| 432 | private void setOrAdaptCurrentAnimation(View scrim) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 433 | float alpha = getCurrentScrimAlpha(scrim); |
| 434 | if (isAnimating(scrim)) { |
| 435 | // Adapt current animation. |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 436 | ValueAnimator previousAnimator = (ValueAnimator) scrim.getTag(TAG_KEY_ANIM); |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 437 | float previousEndValue = (Float) scrim.getTag(TAG_END_ALPHA); |
| 438 | float previousStartValue = (Float) scrim.getTag(TAG_START_ALPHA); |
| 439 | float relativeDiff = alpha - previousEndValue; |
| 440 | float newStartValue = previousStartValue + relativeDiff; |
| 441 | scrim.setTag(TAG_START_ALPHA, newStartValue); |
| 442 | scrim.setTag(TAG_END_ALPHA, alpha); |
| 443 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 444 | } else { |
| 445 | // Set animation. |
| 446 | updateScrimColor(scrim, alpha, getCurrentScrimTint(scrim)); |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 447 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 448 | } |
| 449 | |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 450 | private void applyExpansionToAlpha() { |
Lucas Dupin | 67f0263 | 2018-03-12 11:08:31 -0700 | [diff] [blame] | 451 | if (!mExpansionAffectsAlpha) { |
| 452 | return; |
| 453 | } |
| 454 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 455 | if (mState == ScrimState.UNLOCKED || mState == ScrimState.BUBBLE_EXPANDED) { |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 456 | // Darken scrim as you pull down the shade when unlocked |
| 457 | float behindFraction = getInterpolatedFraction(); |
| 458 | behindFraction = (float) Math.pow(behindFraction, 0.8f); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 459 | mBehindAlpha = behindFraction * GRADIENT_SCRIM_ALPHA_BUSY; |
| 460 | mInFrontAlpha = 0; |
Lucas Dupin | 1c32743 | 2019-01-03 13:37:53 -0800 | [diff] [blame] | 461 | } else if (mState == ScrimState.KEYGUARD || mState == ScrimState.PULSING) { |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 462 | // Either darken of make the scrim transparent when you |
| 463 | // pull down the shade |
| 464 | float interpolatedFract = getInterpolatedFraction(); |
Lucas Dupin | 3d36dd8 | 2019-01-02 14:38:35 -0800 | [diff] [blame] | 465 | float alphaBehind = mState.getBehindAlpha(); |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 466 | if (mDarkenWhileDragging) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 467 | mBehindAlpha = MathUtils.lerp(GRADIENT_SCRIM_ALPHA_BUSY, alphaBehind, |
Lucas Dupin | b380c88 | 2018-02-25 21:57:17 -0800 | [diff] [blame] | 468 | interpolatedFract); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 469 | mInFrontAlpha = 0; |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 470 | } else { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 471 | mBehindAlpha = MathUtils.lerp(0 /* start */, alphaBehind, |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 472 | interpolatedFract); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 473 | mInFrontAlpha = 0; |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 474 | } |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 475 | mBehindTint = ColorUtils.blendARGB(ScrimState.BOUNCER.getBehindTint(), |
Lucas Dupin | 4cf0106 | 2019-03-08 17:07:49 -0800 | [diff] [blame] | 476 | mState.getBehindTint(), interpolatedFract); |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 480 | /** |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 481 | * Sets the given drawable as the background of the scrim that shows up behind the |
| 482 | * notifications. |
| 483 | */ |
| 484 | public void setScrimBehindDrawable(Drawable drawable) { |
| 485 | mScrimBehind.setDrawable(drawable); |
| 486 | } |
| 487 | |
Michael Wright | cae8875 | 2018-04-16 23:13:54 +0100 | [diff] [blame] | 488 | /** |
Lucas Dupin | 69bda60 | 2018-05-18 17:24:52 -0700 | [diff] [blame] | 489 | * Sets the front scrim opacity in AOD so it's not as bright. |
| 490 | * <p> |
| 491 | * Displays usually don't support multiple dimming settings when in low power mode. |
| 492 | * The workaround is to modify the front scrim opacity when in AOD, so it's not as |
| 493 | * bright when you're at the movies or lying down on bed. |
| 494 | * <p> |
| 495 | * This value will be lost during transitions and only updated again after the the |
| 496 | * device is dozing when the light sensor is on. |
Michael Wright | cae8875 | 2018-04-16 23:13:54 +0100 | [diff] [blame] | 497 | */ |
| 498 | public void setAodFrontScrimAlpha(float alpha) { |
Lucas Dupin | 69bda60 | 2018-05-18 17:24:52 -0700 | [diff] [blame] | 499 | if (mState == ScrimState.AOD && mDozeParameters.getAlwaysOn() |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 500 | && mInFrontAlpha != alpha) { |
| 501 | mInFrontAlpha = alpha; |
Lucas Dupin | 8523d13 | 2018-05-31 17:34:32 -0700 | [diff] [blame] | 502 | updateScrims(); |
Michael Wright | cae8875 | 2018-04-16 23:13:54 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | mState.AOD.setAodFrontScrimAlpha(alpha); |
| 506 | } |
| 507 | |
Lucas Dupin | 5f00fa5 | 2019-03-27 22:46:53 -0700 | [diff] [blame] | 508 | /** |
Lucas Dupin | 34306c3 | 2019-07-16 11:56:53 -0700 | [diff] [blame] | 509 | * Set front scrim to black, cancelling animations, in order to prepare to fade them |
| 510 | * away once the display turns on. |
| 511 | */ |
| 512 | public void prepareForGentleWakeUp() { |
| 513 | if (mState == ScrimState.AOD && mDozeParameters.getAlwaysOn()) { |
Mady Mellor | fa8c70d | 2019-07-17 13:44:01 -0700 | [diff] [blame^] | 514 | mInFrontAlpha = 1f; |
Lucas Dupin | 34306c3 | 2019-07-16 11:56:53 -0700 | [diff] [blame] | 515 | mAnimateChange = false; |
| 516 | updateScrims(); |
| 517 | mAnimateChange = true; |
| 518 | mAnimationDuration = ANIMATION_DURATION_LONG; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /** |
Lucas Dupin | 5f00fa5 | 2019-03-27 22:46:53 -0700 | [diff] [blame] | 523 | * If the lock screen sensor is active. |
| 524 | */ |
| 525 | public void setWakeLockScreenSensorActive(boolean active) { |
| 526 | for (ScrimState state : ScrimState.values()) { |
| 527 | state.setWakeLockScreenSensorActive(active); |
| 528 | } |
| 529 | |
| 530 | if (mState == ScrimState.PULSING) { |
| 531 | float newBehindAlpha = mState.getBehindAlpha(); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 532 | if (mBehindAlpha != newBehindAlpha) { |
| 533 | mBehindAlpha = newBehindAlpha; |
Lucas Dupin | 5f00fa5 | 2019-03-27 22:46:53 -0700 | [diff] [blame] | 534 | updateScrims(); |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
Evan Rosky | 9a89501 | 2016-04-21 11:26:15 -0700 | [diff] [blame] | 539 | protected void scheduleUpdate() { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 540 | if (mUpdatePending) return; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 541 | |
| 542 | // Make sure that a frame gets scheduled. |
| 543 | mScrimBehind.invalidate(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 544 | mScrimBehind.getViewTreeObserver().addOnPreDrawListener(this); |
| 545 | mUpdatePending = true; |
| 546 | } |
| 547 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 548 | protected void updateScrims() { |
Lucas Dupin | 9324aa9 | 2017-07-26 20:29:38 -0700 | [diff] [blame] | 549 | // Make sure we have the right gradients and their opacities will satisfy GAR. |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 550 | if (mNeedsDrawableColorUpdate) { |
| 551 | mNeedsDrawableColorUpdate = false; |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 552 | // Only animate scrim color if the scrim view is actually visible |
| 553 | boolean animateScrimInFront = mScrimInFront.getViewAlpha() != 0 && !mBlankScreen; |
| 554 | boolean animateScrimBehind = mScrimBehind.getViewAlpha() != 0 && !mBlankScreen; |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 555 | boolean animateScrimForBubble = mScrimForBubble.getViewAlpha() != 0 && !mBlankScreen; |
| 556 | |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 557 | mScrimInFront.setColors(mColors, animateScrimInFront); |
| 558 | mScrimBehind.setColors(mColors, animateScrimBehind); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 559 | mScrimForBubble.setColors(mColors, animateScrimForBubble); |
Lucas Dupin | 9324aa9 | 2017-07-26 20:29:38 -0700 | [diff] [blame] | 560 | |
| 561 | // Calculate minimum scrim opacity for white or black text. |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 562 | int textColor = mColors.supportsDarkText() ? Color.BLACK : Color.WHITE; |
| 563 | int mainColor = mColors.getMainColor(); |
Lucas Dupin | 9324aa9 | 2017-07-26 20:29:38 -0700 | [diff] [blame] | 564 | float minOpacity = ColorUtils.calculateMinimumBackgroundAlpha(textColor, mainColor, |
| 565 | 4.5f /* minimumContrast */) / 255f; |
| 566 | mScrimBehindAlpha = Math.max(mScrimBehindAlphaResValue, minOpacity); |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 567 | dispatchScrimState(mScrimBehind.getViewAlpha()); |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 570 | // We want to override the back scrim opacity for the AOD state |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 571 | // when it's time to fade the wallpaper away. |
TYM Tsai | a71c892 | 2019-01-07 15:57:53 +0800 | [diff] [blame] | 572 | boolean aodWallpaperTimeout = (mState == ScrimState.AOD || mState == ScrimState.PULSING) |
| 573 | && mWallpaperVisibilityTimedOut; |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 574 | // We also want to hide FLAG_SHOW_WHEN_LOCKED activities under the scrim. |
| 575 | boolean occludedKeyguard = (mState == ScrimState.PULSING || mState == ScrimState.AOD) |
| 576 | && mKeyguardOccluded; |
| 577 | if (aodWallpaperTimeout || occludedKeyguard) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 578 | mBehindAlpha = 1; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 579 | } |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 580 | setScrimAlpha(mScrimInFront, mInFrontAlpha); |
| 581 | setScrimAlpha(mScrimBehind, mBehindAlpha); |
| 582 | setScrimAlpha(mScrimForBubble, mBubbleAlpha); |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 583 | dispatchScrimsVisible(); |
| 584 | } |
| 585 | |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 586 | private void dispatchScrimState(float alpha) { |
| 587 | mScrimStateListener.accept(mState, alpha, mScrimInFront.getColors()); |
| 588 | } |
| 589 | |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 590 | private void dispatchScrimsVisible() { |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 591 | final int currentScrimVisibility; |
| 592 | if (mScrimInFront.getViewAlpha() == 1 || mScrimBehind.getViewAlpha() == 1) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 593 | currentScrimVisibility = OPAQUE; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 594 | } else if (mScrimInFront.getViewAlpha() == 0 && mScrimBehind.getViewAlpha() == 0) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 595 | currentScrimVisibility = TRANSPARENT; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 596 | } else { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 597 | currentScrimVisibility = SEMI_TRANSPARENT; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 598 | } |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 599 | |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 600 | if (mScrimsVisibility != currentScrimVisibility) { |
| 601 | mScrimsVisibility = currentScrimVisibility; |
| 602 | mScrimVisibleListener.accept(currentScrimVisibility); |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 603 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 606 | private float getInterpolatedFraction() { |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 607 | float frac = mExpansionFraction; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 608 | // let's start this 20% of the way down the screen |
| 609 | frac = frac * 1.2f - 0.2f; |
| 610 | if (frac <= 0) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 611 | return 0; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 612 | } else { |
| 613 | // woo, special effects |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 614 | return (float) (1f - 0.5f * (1f - Math.cos(3.14159f * Math.pow(1f - frac, 2f)))); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 618 | private void setScrimAlpha(ScrimView scrim, float alpha) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 619 | if (alpha == 0f) { |
| 620 | scrim.setClickable(false); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 621 | } else { |
Lucas Dupin | 1c32743 | 2019-01-03 13:37:53 -0800 | [diff] [blame] | 622 | // Eat touch events (unless dozing). |
| 623 | scrim.setClickable(mState != ScrimState.AOD); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 624 | } |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 625 | updateScrim(scrim, alpha); |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 626 | } |
| 627 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 628 | private String getScrimName(ScrimView scrim) { |
| 629 | if (scrim == mScrimInFront) { |
| 630 | return "front_scrim"; |
| 631 | } else if (scrim == mScrimBehind) { |
| 632 | return "back_scrim"; |
| 633 | } else if (scrim == mScrimForBubble) { |
| 634 | return "bubble_scrim"; |
| 635 | } |
| 636 | return "unknown_scrim"; |
| 637 | } |
| 638 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 639 | private void updateScrimColor(View scrim, float alpha, int tint) { |
| 640 | alpha = Math.max(0, Math.min(1.0f, alpha)); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 641 | if (scrim instanceof ScrimView) { |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 642 | ScrimView scrimView = (ScrimView) scrim; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 643 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 644 | Trace.traceCounter(Trace.TRACE_TAG_APP, getScrimName(scrimView) + "_alpha", |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 645 | (int) (alpha * 255)); |
| 646 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 647 | Trace.traceCounter(Trace.TRACE_TAG_APP, getScrimName(scrimView) + "_tint", |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 648 | Color.alpha(tint)); |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 649 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 650 | scrimView.setTint(tint); |
| 651 | scrimView.setViewAlpha(alpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 652 | } else { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 653 | scrim.setAlpha(alpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 654 | } |
Selim Cinek | 8cd8040 | 2017-08-01 10:44:29 -0700 | [diff] [blame] | 655 | dispatchScrimsVisible(); |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 658 | private void startScrimAnimation(final View scrim, float current) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 659 | ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); |
| 660 | final int initialScrimTint = scrim instanceof ScrimView ? ((ScrimView) scrim).getTint() : |
| 661 | Color.TRANSPARENT; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 662 | anim.addUpdateListener(animation -> { |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 663 | final float startAlpha = (Float) scrim.getTag(TAG_START_ALPHA); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 664 | final float animAmount = (float) animation.getAnimatedValue(); |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 665 | final int finalScrimTint = getCurrentScrimTint(scrim); |
| 666 | final float finalScrimAlpha = getCurrentScrimAlpha(scrim); |
| 667 | float alpha = MathUtils.lerp(startAlpha, finalScrimAlpha, animAmount); |
| 668 | alpha = MathUtils.constrain(alpha, 0f, 1f); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 669 | int tint = ColorUtils.blendARGB(initialScrimTint, finalScrimTint, animAmount); |
| 670 | updateScrimColor(scrim, alpha, tint); |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 671 | dispatchScrimsVisible(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 672 | }); |
Lucas Dupin | 3503c5f | 2018-03-02 19:04:00 -0800 | [diff] [blame] | 673 | anim.setInterpolator(mInterpolator); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 674 | anim.setStartDelay(mAnimationDelay); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 675 | anim.setDuration(mAnimationDuration); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 676 | anim.addListener(new AnimatorListenerAdapter() { |
Joanne Chung | a393ad6 | 2019-01-16 21:41:31 +0800 | [diff] [blame] | 677 | private Callback lastCallback = mCallback; |
| 678 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 679 | @Override |
| 680 | public void onAnimationEnd(Animator animation) { |
Joanne Chung | a393ad6 | 2019-01-16 21:41:31 +0800 | [diff] [blame] | 681 | onFinished(lastCallback); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 682 | |
| 683 | scrim.setTag(TAG_KEY_ANIM, null); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 684 | dispatchScrimsVisible(); |
| 685 | |
Jorim Jaggi | f5304ad | 2017-07-17 18:31:13 +0200 | [diff] [blame] | 686 | if (!mDeferFinishedListener && mOnAnimationFinished != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 687 | mOnAnimationFinished.run(); |
| 688 | mOnAnimationFinished = null; |
| 689 | } |
| 690 | } |
| 691 | }); |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 692 | |
| 693 | // Cache alpha values because we might want to update this animator in the future if |
| 694 | // the user expands the panel while the animation is still running. |
| 695 | scrim.setTag(TAG_START_ALPHA, current); |
| 696 | scrim.setTag(TAG_END_ALPHA, getCurrentScrimAlpha(scrim)); |
| 697 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 698 | scrim.setTag(TAG_KEY_ANIM, anim); |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 699 | anim.start(); |
| 700 | } |
| 701 | |
| 702 | private float getCurrentScrimAlpha(View scrim) { |
| 703 | if (scrim == mScrimInFront) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 704 | return mInFrontAlpha; |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 705 | } else if (scrim == mScrimBehind) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 706 | return mBehindAlpha; |
| 707 | } else if (scrim == mScrimForBubble) { |
| 708 | return mBubbleAlpha; |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 709 | } else { |
| 710 | throw new IllegalArgumentException("Unknown scrim view"); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | private int getCurrentScrimTint(View scrim) { |
| 715 | if (scrim == mScrimInFront) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 716 | return mInFrontTint; |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 717 | } else if (scrim == mScrimBehind) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 718 | return mBehindTint; |
| 719 | } else if (scrim == mScrimForBubble) { |
| 720 | return mBubbleTint; |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 721 | } else { |
| 722 | throw new IllegalArgumentException("Unknown scrim view"); |
| 723 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 724 | } |
| 725 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 726 | @Override |
| 727 | public boolean onPreDraw() { |
| 728 | mScrimBehind.getViewTreeObserver().removeOnPreDrawListener(this); |
| 729 | mUpdatePending = false; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 730 | if (mCallback != null) { |
| 731 | mCallback.onStart(); |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 732 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 733 | updateScrims(); |
Lucas Dupin | 3503c5f | 2018-03-02 19:04:00 -0800 | [diff] [blame] | 734 | if (mOnAnimationFinished != null && !isAnimating(mScrimInFront) |
| 735 | && !isAnimating(mScrimBehind)) { |
| 736 | mOnAnimationFinished.run(); |
| 737 | mOnAnimationFinished = null; |
| 738 | } |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 739 | return true; |
| 740 | } |
| 741 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 742 | private void onFinished() { |
Joanne Chung | a393ad6 | 2019-01-16 21:41:31 +0800 | [diff] [blame] | 743 | onFinished(mCallback); |
| 744 | } |
| 745 | |
| 746 | private void onFinished(Callback callback) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 747 | if (mWakeLockHeld) { |
Lucas Dupin | ee4c9b7 | 2019-02-18 17:04:58 -0800 | [diff] [blame] | 748 | mWakeLock.release(TAG); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 749 | mWakeLockHeld = false; |
| 750 | } |
Joanne Chung | a393ad6 | 2019-01-16 21:41:31 +0800 | [diff] [blame] | 751 | |
| 752 | if (callback != null) { |
| 753 | callback.onFinished(); |
| 754 | |
| 755 | if (callback == mCallback) { |
| 756 | mCallback = null; |
| 757 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 758 | } |
Joanne Chung | a393ad6 | 2019-01-16 21:41:31 +0800 | [diff] [blame] | 759 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 760 | // When unlocking with fingerprint, we'll fade the scrims from black to transparent. |
| 761 | // At the end of the animation we need to remove the tint. |
| 762 | if (mState == ScrimState.UNLOCKED) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 763 | mInFrontTint = Color.TRANSPARENT; |
| 764 | mBehindTint = Color.TRANSPARENT; |
| 765 | mBubbleTint = Color.TRANSPARENT; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 769 | private boolean isAnimating(View scrim) { |
| 770 | return scrim.getTag(TAG_KEY_ANIM) != null; |
| 771 | } |
| 772 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 773 | @VisibleForTesting |
| 774 | void setOnAnimationFinished(Runnable onAnimationFinished) { |
| 775 | mOnAnimationFinished = onAnimationFinished; |
| 776 | } |
Adrian Roos | 5f72c92 | 2016-03-08 15:54:26 -0800 | [diff] [blame] | 777 | |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 778 | private void updateScrim(ScrimView scrim, float alpha) { |
| 779 | final float currentAlpha = scrim.getViewAlpha(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 780 | |
| 781 | ValueAnimator previousAnimator = ViewState.getChildTag(scrim, TAG_KEY_ANIM); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 782 | if (previousAnimator != null) { |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 783 | if (mAnimateChange) { |
Jorim Jaggi | f5304ad | 2017-07-17 18:31:13 +0200 | [diff] [blame] | 784 | // We are not done yet! Defer calling the finished listener. |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 785 | mDeferFinishedListener = true; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 786 | } |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 787 | // Previous animators should always be cancelled. Not doing so would cause |
| 788 | // overlap, especially on states that don't animate, leading to flickering, |
| 789 | // and in the worst case, an internal state that doesn't represent what |
| 790 | // transitionTo requested. |
| 791 | cancelAnimator(previousAnimator); |
| 792 | mDeferFinishedListener = false; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 793 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 794 | |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 795 | if (mPendingFrameCallback != null) { |
| 796 | // Display is off and we're waiting. |
| 797 | return; |
| 798 | } else if (mBlankScreen) { |
| 799 | // Need to blank the display before continuing. |
| 800 | blankDisplay(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 801 | return; |
| 802 | } else if (!mScreenBlankingCallbackCalled) { |
| 803 | // Not blanking the screen. Letting the callback know that we're ready |
| 804 | // to replace what was on the screen before. |
| 805 | if (mCallback != null) { |
| 806 | mCallback.onDisplayBlanked(); |
| 807 | mScreenBlankingCallbackCalled = true; |
| 808 | } |
| 809 | } |
| 810 | |
Lucas Dupin | 6afae37 | 2017-11-30 13:09:22 -0500 | [diff] [blame] | 811 | if (scrim == mScrimBehind) { |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 812 | dispatchScrimState(alpha); |
Lucas Dupin | 6afae37 | 2017-11-30 13:09:22 -0500 | [diff] [blame] | 813 | } |
| 814 | |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 815 | final boolean wantsAlphaUpdate = alpha != currentAlpha; |
Lucas Dupin | 3503c5f | 2018-03-02 19:04:00 -0800 | [diff] [blame] | 816 | final boolean wantsTintUpdate = scrim.getTint() != getCurrentScrimTint(scrim); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 817 | |
| 818 | if (wantsAlphaUpdate || wantsTintUpdate) { |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 819 | if (mAnimateChange) { |
| 820 | startScrimAnimation(scrim, currentAlpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 821 | } else { |
Lucas Dupin | 3daf3b0 | 2018-02-27 17:23:41 -0800 | [diff] [blame] | 822 | // update the alpha directly |
| 823 | updateScrimColor(scrim, alpha, getCurrentScrimTint(scrim)); |
| 824 | onFinished(); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 825 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 826 | } else { |
| 827 | onFinished(); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Lucas Dupin | 80a3fcc | 2018-02-07 10:49:55 -0800 | [diff] [blame] | 831 | @VisibleForTesting |
| 832 | protected void cancelAnimator(ValueAnimator previousAnimator) { |
| 833 | if (previousAnimator != null) { |
| 834 | previousAnimator.cancel(); |
| 835 | } |
| 836 | } |
| 837 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 838 | private void blankDisplay() { |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 839 | updateScrimColor(mScrimInFront, 1, Color.BLACK); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 840 | |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 841 | // Notify callback that the screen is completely black and we're |
| 842 | // ready to change the display power mode |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 843 | mPendingFrameCallback = () -> { |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 844 | if (mCallback != null) { |
| 845 | mCallback.onDisplayBlanked(); |
| 846 | mScreenBlankingCallbackCalled = true; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 847 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 848 | |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 849 | mBlankingTransitionRunnable = () -> { |
| 850 | mBlankingTransitionRunnable = null; |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 851 | mPendingFrameCallback = null; |
| 852 | mBlankScreen = false; |
| 853 | // Try again. |
| 854 | updateScrims(); |
| 855 | }; |
| 856 | |
| 857 | // Setting power states can happen after we push out the frame. Make sure we |
| 858 | // stay fully opaque until the power state request reaches the lower levels. |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 859 | final int delay = mScreenOn ? 32 : 500; |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 860 | if (DEBUG) { |
Lucas Dupin | 3a64ed7 | 2018-02-12 12:44:37 -0800 | [diff] [blame] | 861 | Log.d(TAG, "Fading out scrims with delay: " + delay); |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 862 | } |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 863 | mHandler.postDelayed(mBlankingTransitionRunnable, delay); |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 864 | }; |
| 865 | doOnTheNextFrame(mPendingFrameCallback); |
| 866 | } |
| 867 | |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 868 | /** |
| 869 | * Executes a callback after the frame has hit the display. |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 870 | * |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 871 | * @param callback What to run. |
| 872 | */ |
Lucas Dupin | 8c7cb02 | 2018-02-05 10:49:03 -0800 | [diff] [blame] | 873 | @VisibleForTesting |
Lucas Dupin | 0791d97 | 2018-03-26 13:32:16 -0700 | [diff] [blame] | 874 | protected void doOnTheNextFrame(Runnable callback) { |
| 875 | // Just calling View#postOnAnimation isn't enough because the frame might not have reached |
| 876 | // the display yet. A timeout is the safest solution. |
| 877 | mScrimBehind.postOnAnimationDelayed(callback, 32 /* delayMillis */); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | @VisibleForTesting |
| 881 | protected Handler getHandler() { |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 882 | return new Handler(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 885 | public int getBackgroundColor() { |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 886 | int color = mColors.getMainColor(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 887 | return Color.argb((int) (mScrimBehind.getViewAlpha() * Color.alpha(color)), |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 888 | Color.red(color), Color.green(color), Color.blue(color)); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | public void setScrimBehindChangeRunnable(Runnable changeRunnable) { |
| 892 | mScrimBehind.setChangeRunnable(changeRunnable); |
| 893 | } |
Selim Cinek | e803491c | 2016-04-09 21:24:45 -0700 | [diff] [blame] | 894 | |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 895 | public void setCurrentUser(int currentUser) { |
| 896 | // Don't care in the base class. |
| 897 | } |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 898 | |
| 899 | @Override |
Lucas Dupin | 7aaa353 | 2017-05-28 08:51:07 -0700 | [diff] [blame] | 900 | public void onColorsChanged(ColorExtractor colorExtractor, int which) { |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 901 | mColors = mColorExtractor.getNeutralColors(); |
| 902 | mNeedsDrawableColorUpdate = true; |
| 903 | scheduleUpdate(); |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 904 | } |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 905 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 906 | @VisibleForTesting |
| 907 | protected WakeLock createWakeLock() { |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 908 | return new DelayedWakeLock(mHandler, WakeLock.createPartial(mContext, "Scrims")); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 909 | } |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 910 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 911 | @Override |
| 912 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Lucas Dupin | 3fcdd47 | 2018-01-19 19:06:45 -0800 | [diff] [blame] | 913 | pw.println(" ScrimController: "); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 914 | pw.print(" state: "); |
| 915 | pw.println(mState); |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 916 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 917 | pw.print(" frontScrim:"); |
| 918 | pw.print(" viewAlpha="); |
| 919 | pw.print(mScrimInFront.getViewAlpha()); |
| 920 | pw.print(" alpha="); |
| 921 | pw.print(mInFrontAlpha); |
| 922 | pw.print(" tint=0x"); |
| 923 | pw.println(Integer.toHexString(mScrimInFront.getTint())); |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 924 | |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 925 | pw.print(" backScrim:"); |
| 926 | pw.print(" viewAlpha="); |
| 927 | pw.print(mScrimBehind.getViewAlpha()); |
| 928 | pw.print(" alpha="); |
| 929 | pw.print(mBehindAlpha); |
| 930 | pw.print(" tint=0x"); |
| 931 | pw.println(Integer.toHexString(mScrimBehind.getTint())); |
| 932 | |
| 933 | pw.print(" bubbleScrim:"); |
| 934 | pw.print(" viewAlpha="); |
| 935 | pw.print(mScrimForBubble.getViewAlpha()); |
| 936 | pw.print(" alpha="); |
| 937 | pw.print(mBubbleAlpha); |
| 938 | pw.print(" tint=0x"); |
| 939 | pw.println(Integer.toHexString(mScrimForBubble.getTint())); |
| 940 | |
| 941 | pw.print(" mTracking="); |
| 942 | pw.println(mTracking); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 943 | } |
| 944 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 945 | public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) { |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 946 | mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode; |
| 947 | ScrimState[] states = ScrimState.values(); |
| 948 | for (int i = 0; i < states.length; i++) { |
| 949 | states[i].setWallpaperSupportsAmbientMode(wallpaperSupportsAmbientMode); |
| 950 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 953 | /** |
| 954 | * Interrupts blanking transitions once the display notifies that it's already on. |
| 955 | */ |
| 956 | public void onScreenTurnedOn() { |
Lucas Dupin | 3a64ed7 | 2018-02-12 12:44:37 -0800 | [diff] [blame] | 957 | mScreenOn = true; |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 958 | if (mHandler.hasCallbacks(mBlankingTransitionRunnable)) { |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 959 | if (DEBUG) { |
| 960 | Log.d(TAG, "Shorter blanking because screen turned on. All good."); |
| 961 | } |
Lucas Dupin | 54fbfb3 | 2019-03-05 18:08:13 -0800 | [diff] [blame] | 962 | mHandler.removeCallbacks(mBlankingTransitionRunnable); |
Lucas Dupin | 53cf12a | 2018-02-05 16:14:45 -0800 | [diff] [blame] | 963 | mBlankingTransitionRunnable.run(); |
| 964 | } |
| 965 | } |
| 966 | |
Lucas Dupin | 3a64ed7 | 2018-02-12 12:44:37 -0800 | [diff] [blame] | 967 | public void onScreenTurnedOff() { |
| 968 | mScreenOn = false; |
| 969 | } |
| 970 | |
Lucas Dupin | 67f0263 | 2018-03-12 11:08:31 -0700 | [diff] [blame] | 971 | public void setExpansionAffectsAlpha(boolean expansionAffectsAlpha) { |
| 972 | mExpansionAffectsAlpha = expansionAffectsAlpha; |
| 973 | } |
| 974 | |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 975 | public void setKeyguardOccluded(boolean keyguardOccluded) { |
| 976 | mKeyguardOccluded = keyguardOccluded; |
Lucas Dupin | 63d7217 | 2018-06-06 11:42:55 -0700 | [diff] [blame] | 977 | updateScrims(); |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 980 | public void setHasBackdrop(boolean hasBackdrop) { |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 981 | for (ScrimState state : ScrimState.values()) { |
| 982 | state.setHasBackdrop(hasBackdrop); |
| 983 | } |
Lucas Dupin | 9bee582 | 2018-07-09 14:32:53 -0700 | [diff] [blame] | 984 | |
| 985 | // Backdrop event may arrive after state was already applied, |
| 986 | // in this case, back-scrim needs to be re-evaluated |
| 987 | if (mState == ScrimState.AOD || mState == ScrimState.PULSING) { |
Lucas Dupin | 3d36dd8 | 2019-01-02 14:38:35 -0800 | [diff] [blame] | 988 | float newBehindAlpha = mState.getBehindAlpha(); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 989 | if (mBehindAlpha != newBehindAlpha) { |
| 990 | mBehindAlpha = newBehindAlpha; |
Lucas Dupin | 9bee582 | 2018-07-09 14:32:53 -0700 | [diff] [blame] | 991 | updateScrims(); |
| 992 | } |
| 993 | } |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Selim Cinek | 84b2acc | 2019-07-07 00:40:38 -0700 | [diff] [blame] | 996 | public void setUnlockIsFading(boolean unlockFading) { |
| 997 | for (ScrimState state : ScrimState.values()) { |
| 998 | state.setUnlockIsFading(unlockFading); |
| 999 | } |
| 1000 | } |
| 1001 | |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 1002 | public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) { |
| 1003 | for (ScrimState state : ScrimState.values()) { |
| 1004 | state.setLaunchingAffordanceWithPreview(launchingAffordanceWithPreview); |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 1008 | public interface Callback { |
| 1009 | default void onStart() { |
| 1010 | } |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 1011 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 1012 | default void onDisplayBlanked() { |
| 1013 | } |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 1014 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 1015 | default void onFinished() { |
| 1016 | } |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 1017 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 1018 | default void onCancelled() { |
| 1019 | } |
Jerry Chang | bde4c0c | 2019-06-13 16:58:41 +0800 | [diff] [blame] | 1020 | /** Returns whether to timeout wallpaper or not. */ |
| 1021 | default boolean shouldTimeoutWallpaper() { |
| 1022 | return false; |
| 1023 | } |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 1024 | } |
Lucas Dupin | 690c6f5 | 2018-07-10 15:28:57 -0700 | [diff] [blame] | 1025 | |
| 1026 | /** |
| 1027 | * Simple keyguard callback that updates scrims when keyguard visibility changes. |
| 1028 | */ |
| 1029 | private class KeyguardVisibilityCallback extends KeyguardUpdateMonitorCallback { |
| 1030 | |
| 1031 | @Override |
| 1032 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 1033 | mNeedsDrawableColorUpdate = true; |
| 1034 | scheduleUpdate(); |
| 1035 | } |
| 1036 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 1037 | } |