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