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