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 | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 108 | mCurrentBehindAlpha = mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 109 | mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f; |
| 110 | mCurrentInFrontTint = Color.BLACK; |
| 111 | mCurrentBehindTint = Color.BLACK; |
Lucas Dupin | 4749f1b | 2018-04-04 15:09:06 -0700 | [diff] [blame] | 112 | mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG; |
Lucas Dupin | ea0116e | 2018-04-05 10:09:29 -0700 | [diff] [blame] | 113 | // DisplayPowerManager may blank the screen for us, |
| 114 | // in this case we just need to set our state. |
| 115 | mAnimateChange = mDozeParameters.shouldControlScreenOff(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 116 | } |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 117 | |
| 118 | @Override |
| 119 | public boolean isLowPowerState() { |
| 120 | return true; |
| 121 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 122 | }, |
| 123 | |
| 124 | /** |
| 125 | * When phone wakes up because you received a notification. |
| 126 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 127 | PULSING(5) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 128 | @Override |
| 129 | public void prepare(ScrimState previousState) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 130 | mCurrentInFrontAlpha = 0; |
| 131 | mCurrentInFrontTint = Color.BLACK; |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 132 | mCurrentBehindAlpha = mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 133 | mCurrentBehindTint = Color.BLACK; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 134 | mBlankScreen = mDisplayRequiresBlanking; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 135 | } |
| 136 | }, |
| 137 | |
| 138 | /** |
| 139 | * Unlocked on top of an app (launcher or any other activity.) |
| 140 | */ |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 141 | UNLOCKED(6) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 142 | @Override |
| 143 | public void prepare(ScrimState previousState) { |
| 144 | mCurrentBehindAlpha = 0; |
| 145 | mCurrentInFrontAlpha = 0; |
| 146 | mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION; |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 147 | mAnimateChange = !mLaunchingAffordanceWithPreview; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 148 | |
Lucas Dupin | d35502f | 2018-06-27 13:35:52 -0700 | [diff] [blame] | 149 | if (previousState == ScrimState.AOD) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 150 | // Fade from black to transparent when coming directly from AOD |
| 151 | updateScrimColor(mScrimInFront, 1, Color.BLACK); |
| 152 | updateScrimColor(mScrimBehind, 1, Color.BLACK); |
| 153 | // Scrims should still be black at the end of the transition. |
| 154 | mCurrentInFrontTint = Color.BLACK; |
| 155 | mCurrentBehindTint = Color.BLACK; |
| 156 | mBlankScreen = true; |
| 157 | } else { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 158 | mCurrentInFrontTint = Color.TRANSPARENT; |
| 159 | mCurrentBehindTint = Color.TRANSPARENT; |
| 160 | mBlankScreen = false; |
| 161 | } |
| 162 | } |
| 163 | }; |
| 164 | |
| 165 | boolean mBlankScreen = false; |
| 166 | long mAnimationDuration = ScrimController.ANIMATION_DURATION; |
| 167 | int mCurrentInFrontTint = Color.TRANSPARENT; |
| 168 | int mCurrentBehindTint = Color.TRANSPARENT; |
| 169 | boolean mAnimateChange = true; |
| 170 | float mCurrentInFrontAlpha; |
| 171 | float mCurrentBehindAlpha; |
| 172 | float mAodFrontScrimAlpha; |
| 173 | float mScrimBehindAlphaKeyguard; |
| 174 | ScrimView mScrimInFront; |
| 175 | ScrimView mScrimBehind; |
| 176 | DozeParameters mDozeParameters; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 177 | boolean mDisplayRequiresBlanking; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 178 | boolean mWallpaperSupportsAmbientMode; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 179 | int mIndex; |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 180 | boolean mHasBackdrop; |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 181 | boolean mLaunchingAffordanceWithPreview; |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 182 | |
| 183 | ScrimState(int index) { |
| 184 | mIndex = index; |
| 185 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 186 | |
| 187 | public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) { |
| 188 | mScrimInFront = scrimInFront; |
| 189 | mScrimBehind = scrimBehind; |
| 190 | mDozeParameters = dozeParameters; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 191 | mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking(); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | public void prepare(ScrimState previousState) { |
| 195 | } |
| 196 | |
Lucas Dupin | 5866aaf | 2018-02-02 14:45:31 -0800 | [diff] [blame] | 197 | public int getIndex() { |
| 198 | return mIndex; |
| 199 | } |
| 200 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 201 | public float getFrontAlpha() { |
| 202 | return mCurrentInFrontAlpha; |
| 203 | } |
| 204 | |
Lucas Dupin | b380c88 | 2018-02-25 21:57:17 -0800 | [diff] [blame] | 205 | public float getBehindAlpha(float busyness) { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 206 | return mCurrentBehindAlpha; |
| 207 | } |
| 208 | |
| 209 | public int getFrontTint() { |
| 210 | return mCurrentInFrontTint; |
| 211 | } |
| 212 | |
| 213 | public int getBehindTint() { |
| 214 | return mCurrentBehindTint; |
| 215 | } |
| 216 | |
| 217 | public long getAnimationDuration() { |
| 218 | return mAnimationDuration; |
| 219 | } |
| 220 | |
| 221 | public boolean getBlanksScreen() { |
| 222 | return mBlankScreen; |
| 223 | } |
| 224 | |
| 225 | public void updateScrimColor(ScrimView scrim, float alpha, int tint) { |
| 226 | Trace.traceCounter(Trace.TRACE_TAG_APP, |
| 227 | scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha", |
| 228 | (int) (alpha * 255)); |
| 229 | |
| 230 | Trace.traceCounter(Trace.TRACE_TAG_APP, |
| 231 | scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint", |
| 232 | Color.alpha(tint)); |
| 233 | |
| 234 | scrim.setTint(tint); |
| 235 | scrim.setViewAlpha(alpha); |
| 236 | } |
| 237 | |
| 238 | public boolean getAnimateChange() { |
| 239 | return mAnimateChange; |
| 240 | } |
| 241 | |
| 242 | public void setAodFrontScrimAlpha(float aodFrontScrimAlpha) { |
| 243 | mAodFrontScrimAlpha = aodFrontScrimAlpha; |
| 244 | } |
| 245 | |
| 246 | public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) { |
| 247 | mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard; |
| 248 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 249 | |
| 250 | public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) { |
| 251 | mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode; |
| 252 | } |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 253 | |
Lucas Dupin | 193677c | 2018-06-11 19:16:03 -0700 | [diff] [blame] | 254 | public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) { |
| 255 | mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview; |
| 256 | } |
| 257 | |
Lucas Dupin | 38962d7 | 2018-03-14 12:41:39 -0700 | [diff] [blame] | 258 | public boolean isLowPowerState() { |
| 259 | return false; |
| 260 | } |
Lucas Dupin | f8463ee | 2018-06-11 16:18:15 -0700 | [diff] [blame] | 261 | |
| 262 | public void setHasBackdrop(boolean hasBackdrop) { |
| 263 | mHasBackdrop = hasBackdrop; |
| 264 | } |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 265 | } |