blob: 081ebfac5f1bc24ec6235fd71095fe7030597b31 [file] [log] [blame]
Lucas Dupin9e3fa102017-11-08 17:16:55 -08001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.graphics.Color;
20import android.os.Trace;
Lucas Dupinb380c882018-02-25 21:57:17 -080021import android.util.MathUtils;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080022
23import com.android.systemui.statusbar.ScrimView;
Lucas Dupin43d0d732017-11-16 11:23:49 -080024import com.android.systemui.statusbar.stack.StackStateAnimator;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080025
26/**
27 * Possible states of the ScrimController state machine.
28 */
29public enum ScrimState {
30
31 /**
32 * Initial state.
33 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080034 UNINITIALIZED(-1),
Lucas Dupin9e3fa102017-11-08 17:16:55 -080035
36 /**
37 * On the lock screen.
38 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080039 KEYGUARD(0) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080040
41 @Override
42 public void prepare(ScrimState previousState) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080043 mBlankScreen = false;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080044 if (previousState == ScrimState.AOD) {
Lucas Dupin43d0d732017-11-16 11:23:49 -080045 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 Dupin43d0d732017-11-16 11:23:49 -080051 }
52 } else {
53 mAnimationDuration = ScrimController.ANIMATION_DURATION;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080054 }
55 mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
56 mCurrentInFrontAlpha = 0;
57 }
Lucas Dupinb380c882018-02-25 21:57:17 -080058
59 @Override
60 public float getBehindAlpha(float busynessFactor) {
61 return MathUtils.map(0 /* start */, 1 /* stop */,
Lucas Dupin932f3b92018-05-01 15:43:06 -070062 mScrimBehindAlphaKeyguard, ScrimController.GRADIENT_SCRIM_ALPHA_BUSY,
Lucas Dupinb380c882018-02-25 21:57:17 -080063 busynessFactor);
64 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -080065 },
66
67 /**
Lucas Dupinbc9aac12018-03-04 20:18:15 -080068 * Showing password challenge on the keyguard.
Lucas Dupin9e3fa102017-11-08 17:16:55 -080069 */
Lucas Dupin5866aaf2018-02-02 14:45:31 -080070 BOUNCER(1) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080071 @Override
72 public void prepare(ScrimState previousState) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080073 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 Dupin05726cd2018-03-13 14:00:24 -070081 BOUNCER_SCRIMMED(2) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080082 @Override
83 public void prepare(ScrimState previousState) {
84 mCurrentBehindAlpha = 0;
85 mCurrentInFrontAlpha = ScrimController.GRADIENT_SCRIM_ALPHA_BUSY;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080086 }
87 },
88
89 /**
90 * Changing screen brightness from quick settings.
91 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -080092 BRIGHTNESS_MIRROR(3) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080093 @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 Dupinbc9aac12018-03-04 20:18:15 -0800103 AOD(4) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800104 @Override
105 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800106 final boolean alwaysOnEnabled = mDozeParameters.getAlwaysOn();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800107 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800108 mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
109 mCurrentInFrontTint = Color.BLACK;
110 mCurrentBehindTint = Color.BLACK;
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700111 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700112 // DisplayPowerManager may blank the screen for us,
113 // in this case we just need to set our state.
114 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800115 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700116
117 @Override
Lucas Dupin218a0cb2018-07-09 14:32:53 -0700118 public float getBehindAlpha(float busyness) {
119 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
120 }
121
122 @Override
Lucas Dupin38962d72018-03-14 12:41:39 -0700123 public boolean isLowPowerState() {
124 return true;
125 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800126 },
127
128 /**
129 * When phone wakes up because you received a notification.
130 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800131 PULSING(5) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800132 @Override
133 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800134 mCurrentInFrontAlpha = 0;
135 mCurrentInFrontTint = Color.BLACK;
136 mCurrentBehindTint = Color.BLACK;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800137 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800138 }
Lucas Dupin218a0cb2018-07-09 14:32:53 -0700139
140 @Override
141 public float getBehindAlpha(float busyness) {
142 return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
143 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800144 },
145
146 /**
147 * Unlocked on top of an app (launcher or any other activity.)
148 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800149 UNLOCKED(6) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800150 @Override
151 public void prepare(ScrimState previousState) {
152 mCurrentBehindAlpha = 0;
153 mCurrentInFrontAlpha = 0;
154 mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION;
Lucas Dupin193677c2018-06-11 19:16:03 -0700155 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800156
Lucas Dupind35502f2018-06-27 13:35:52 -0700157 if (previousState == ScrimState.AOD) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800158 // 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 Dupin9e3fa102017-11-08 17:16:55 -0800166 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 Dupin43d0d732017-11-16 11:23:49 -0800185 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700186 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800187 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700188 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700189 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800190
191 ScrimState(int index) {
192 mIndex = index;
193 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800194
195 public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
196 mScrimInFront = scrimInFront;
197 mScrimBehind = scrimBehind;
198 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800199 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800200 }
201
202 public void prepare(ScrimState previousState) {
203 }
204
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800205 public int getIndex() {
206 return mIndex;
207 }
208
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800209 public float getFrontAlpha() {
210 return mCurrentInFrontAlpha;
211 }
212
Lucas Dupinb380c882018-02-25 21:57:17 -0800213 public float getBehindAlpha(float busyness) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800214 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 Dupin7517b5d2017-08-22 12:51:25 -0700257
258 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
259 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
260 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700261
Lucas Dupin193677c2018-06-11 19:16:03 -0700262 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
263 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
264 }
265
Lucas Dupin38962d72018-03-14 12:41:39 -0700266 public boolean isLowPowerState() {
267 return false;
268 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700269
270 public void setHasBackdrop(boolean hasBackdrop) {
271 mHasBackdrop = hasBackdrop;
272 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800273}