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