Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.graphics.Color; |
| 20 | import android.os.Trace; |
Lucas Dupin | b380c88 | 2018-02-25 21:57:17 -0800 | [diff] [blame] | 21 | import android.util.MathUtils; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 22 | |
| 23 | import com.android.systemui.statusbar.ScrimView; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 24 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Possible states of the ScrimController state machine. |
| 28 | */ |
| 29 | public enum ScrimState { |
| 30 | |
| 31 | /** |
| 32 | * Initial state. |
| 33 | */ |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 34 | UNINITIALIZED(-1), |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * On the lock screen. |
| 38 | */ |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 39 | KEYGUARD(0) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 40 | |
| 41 | @Override |
| 42 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 43 | mBlankScreen = false; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 44 | if (previousState == ScrimState.AOD) { |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 45 | mAnimationDuration = StackStateAnimator.ANIMATION_DURATION_WAKEUP; |
| 46 | if (mDisplayRequiresBlanking) { |
| 47 | // DisplayPowerManager will blank the screen, we'll just |
| 48 | // set our scrim to black in this frame to avoid flickering and |
| 49 | // fade it out afterwards. |
| 50 | mBlankScreen = true; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 51 | } |
| 52 | } else { |
| 53 | mAnimationDuration = ScrimController.ANIMATION_DURATION; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 54 | } |
| 55 | mCurrentBehindAlpha = mScrimBehindAlphaKeyguard; |
| 56 | mCurrentInFrontAlpha = 0; |
| 57 | } |
Lucas Dupin | b380c88 | 2018-02-25 21:57:17 -0800 | [diff] [blame] | 58 | |
| 59 | @Override |
| 60 | public float getBehindAlpha(float busynessFactor) { |
| 61 | return MathUtils.map(0 /* start */, 1 /* stop */, |
Lucas Dupin | 932f3b9 | 2018-05-01 15:43:06 -0700 | [diff] [blame] | 62 | mScrimBehindAlphaKeyguard, ScrimController.GRADIENT_SCRIM_ALPHA_BUSY, |
Lucas Dupin | b380c88 | 2018-02-25 21:57:17 -0800 | [diff] [blame] | 63 | busynessFactor); |
| 64 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 65 | }, |
| 66 | |
| 67 | /** |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 68 | * Showing password challenge on the keyguard. |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 69 | */ |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 70 | BOUNCER(1) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 71 | @Override |
| 72 | public void prepare(ScrimState previousState) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 73 | mCurrentBehindAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY; |
| 74 | mCurrentInFrontAlpha = 0f; |
| 75 | } |
| 76 | }, |
| 77 | |
| 78 | /** |
| 79 | * Showing password challenge on top of a FLAG_SHOW_WHEN_LOCKED activity. |
| 80 | */ |
Lucas Dupin | 05726cd | 2018-03-13 14:00:24 -0700 | [diff] [blame] | 81 | BOUNCER_SCRIMMED(2) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 82 | @Override |
| 83 | public void prepare(ScrimState previousState) { |
| 84 | mCurrentBehindAlpha = 0; |
| 85 | mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 86 | } |
| 87 | }, |
| 88 | |
| 89 | /** |
| 90 | * Changing screen brightness from quick settings. |
| 91 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 92 | BRIGHTNESS_MIRROR(3) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 93 | @Override |
| 94 | public void prepare(ScrimState previousState) { |
| 95 | mCurrentBehindAlpha = 0; |
| 96 | mCurrentInFrontAlpha = 0; |
| 97 | } |
| 98 | }, |
| 99 | |
| 100 | /** |
| 101 | * Always on display or screen off. |
| 102 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 103 | AOD(4) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 104 | @Override |
| 105 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 106 | final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn(); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 107 | mBlankScreen = mDisplayRequiresBlanking; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 108 | mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f; |
| 109 | mCurrentInFrontTint = Color.BLACK; |
| 110 | mCurrentBehindTint = Color.BLACK; |
Lucas Dupin | 4749f1b | 2018-04-04 15:09:06 -0700 | [diff] [blame] | 111 | mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG; |
Lucas Dupin | ea0116e | 2018-04-05 10:09:29 -0700 | [diff] [blame] | 112 | // DisplayPowerManager may blank the screen for us, |
| 113 | // in this case we just need to set our state. |
| 114 | mAnimateChange = mDozeParameters.shouldControlScreenOff(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 115 | } |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 116 | |
| 117 | @Override |
Lucas Dupin | 218a0cb | 2018-07-09 14:32:53 -0700 | [diff] [blame] | 118 | public float getBehindAlpha(float busyness) { |
| 119 | return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f; |
| 120 | } |
| 121 | |
| 122 | @Override |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 123 | public boolean isLowPowerState() { |
| 124 | return true; |
| 125 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 126 | }, |
| 127 | |
| 128 | /** |
| 129 | * When phone wakes up because you received a notification. |
| 130 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 131 | PULSING(5) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 132 | @Override |
| 133 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 134 | mCurrentInFrontAlpha = 0; |
| 135 | mCurrentInFrontTint = Color.BLACK; |
| 136 | mCurrentBehindTint = Color.BLACK; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 137 | mBlankScreen = mDisplayRequiresBlanking; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 138 | } |
Lucas Dupin | 218a0cb | 2018-07-09 14:32:53 -0700 | [diff] [blame] | 139 | |
| 140 | @Override |
| 141 | public float getBehindAlpha(float busyness) { |
| 142 | return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f; |
| 143 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 144 | }, |
| 145 | |
| 146 | /** |
| 147 | * Unlocked on top of an app (launcher or any other activity.) |
| 148 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 149 | UNLOCKED(6) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 150 | @Override |
| 151 | public void prepare(ScrimState previousState) { |
| 152 | mCurrentBehindAlpha = 0; |
| 153 | mCurrentInFrontAlpha = 0; |
| 154 | mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION; |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 155 | mAnimateChange = !mLaunchingAffordanceWithPreview; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 156 | |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 157 | if (previousState == ScrimState.AOD) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 158 | // Fade from black to transparent when coming directly from AOD |
| 159 | updateScrimColor(mScrimInFront, 1, Color.BLACK); |
| 160 | updateScrimColor(mScrimBehind, 1, Color.BLACK); |
| 161 | // Scrims should still be black at the end of the transition. |
| 162 | mCurrentInFrontTint = Color.BLACK; |
| 163 | mCurrentBehindTint = Color.BLACK; |
| 164 | mBlankScreen = true; |
| 165 | } else { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 166 | mCurrentInFrontTint = Color.TRANSPARENT; |
| 167 | mCurrentBehindTint = Color.TRANSPARENT; |
| 168 | mBlankScreen = false; |
| 169 | } |
| 170 | } |
| 171 | }; |
| 172 | |
| 173 | boolean mBlankScreen = false; |
| 174 | long mAnimationDuration = ScrimController.ANIMATION_DURATION; |
| 175 | int mCurrentInFrontTint = Color.TRANSPARENT; |
| 176 | int mCurrentBehindTint = Color.TRANSPARENT; |
| 177 | boolean mAnimateChange = true; |
| 178 | float mCurrentInFrontAlpha; |
| 179 | float mCurrentBehindAlpha; |
| 180 | float mAodFrontScrimAlpha; |
| 181 | float mScrimBehindAlphaKeyguard; |
| 182 | ScrimView mScrimInFront; |
| 183 | ScrimView mScrimBehind; |
| 184 | DozeParameters mDozeParameters; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 185 | boolean mDisplayRequiresBlanking; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 186 | boolean mWallpaperSupportsAmbientMode; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 187 | int mIndex; |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 188 | boolean mHasBackdrop; |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 189 | boolean mLaunchingAffordanceWithPreview; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 190 | |
| 191 | ScrimState(int index) { |
| 192 | mIndex = index; |
| 193 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 194 | |
| 195 | public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) { |
| 196 | mScrimInFront = scrimInFront; |
| 197 | mScrimBehind = scrimBehind; |
| 198 | mDozeParameters = dozeParameters; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 199 | mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | public void prepare(ScrimState previousState) { |
| 203 | } |
| 204 | |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 205 | public int getIndex() { |
| 206 | return mIndex; |
| 207 | } |
| 208 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 209 | public float getFrontAlpha() { |
| 210 | return mCurrentInFrontAlpha; |
| 211 | } |
| 212 | |
Lucas Dupin | b380c88 | 2018-02-25 21:57:17 -0800 | [diff] [blame] | 213 | public float getBehindAlpha(float busyness) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 214 | return mCurrentBehindAlpha; |
| 215 | } |
| 216 | |
| 217 | public int getFrontTint() { |
| 218 | return mCurrentInFrontTint; |
| 219 | } |
| 220 | |
| 221 | public int getBehindTint() { |
| 222 | return mCurrentBehindTint; |
| 223 | } |
| 224 | |
| 225 | public long getAnimationDuration() { |
| 226 | return mAnimationDuration; |
| 227 | } |
| 228 | |
| 229 | public boolean getBlanksScreen() { |
| 230 | return mBlankScreen; |
| 231 | } |
| 232 | |
| 233 | public void updateScrimColor(ScrimView scrim, float alpha, int tint) { |
| 234 | Trace.traceCounter(Trace.TRACE_TAG_APP, |
| 235 | scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha", |
| 236 | (int) (alpha * 255)); |
| 237 | |
| 238 | Trace.traceCounter(Trace.TRACE_TAG_APP, |
| 239 | scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint", |
| 240 | Color.alpha(tint)); |
| 241 | |
| 242 | scrim.setTint(tint); |
| 243 | scrim.setViewAlpha(alpha); |
| 244 | } |
| 245 | |
| 246 | public boolean getAnimateChange() { |
| 247 | return mAnimateChange; |
| 248 | } |
| 249 | |
| 250 | public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) { |
| 251 | mAodFrontScrimAlpha = aodFrontScrimAlpha; |
| 252 | } |
| 253 | |
| 254 | public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) { |
| 255 | mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard; |
| 256 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 257 | |
| 258 | public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) { |
| 259 | mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode; |
| 260 | } |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 261 | |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 262 | public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) { |
| 263 | mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview; |
| 264 | } |
| 265 | |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 266 | public boolean isLowPowerState() { |
| 267 | return false; |
| 268 | } |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 269 | |
| 270 | public void setHasBackdrop(boolean hasBackdrop) { |
| 271 | mHasBackdrop = hasBackdrop; |
| 272 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 273 | } |