blob: 19015fcdacf73f2341ca88551f13241e2508df24 [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 Dupinf8463ee2018-06-11 16:18:15 -0700108 mCurrentBehindAlpha = mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800109 mCurrentInFrontAlpha = alwaysOnEnabled ? mAodFrontScrimAlpha : 1f;
110 mCurrentInFrontTint = Color.BLACK;
111 mCurrentBehindTint = Color.BLACK;
Lucas Dupin4749f1b2018-04-04 15:09:06 -0700112 mAnimationDuration = ScrimController.ANIMATION_DURATION_LONG;
Lucas Dupinea0116e2018-04-05 10:09:29 -0700113 // DisplayPowerManager may blank the screen for us,
114 // in this case we just need to set our state.
115 mAnimateChange = mDozeParameters.shouldControlScreenOff();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800116 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700117
118 @Override
119 public boolean isLowPowerState() {
120 return true;
121 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800122 },
123
124 /**
125 * When phone wakes up because you received a notification.
126 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800127 PULSING(5) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800128 @Override
129 public void prepare(ScrimState previousState) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800130 mCurrentInFrontAlpha = 0;
131 mCurrentInFrontTint = Color.BLACK;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700132 mCurrentBehindAlpha = mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800133 mCurrentBehindTint = Color.BLACK;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800134 mBlankScreen = mDisplayRequiresBlanking;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800135 }
136 },
137
138 /**
139 * Unlocked on top of an app (launcher or any other activity.)
140 */
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800141 UNLOCKED(6) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800142 @Override
143 public void prepare(ScrimState previousState) {
144 mCurrentBehindAlpha = 0;
145 mCurrentInFrontAlpha = 0;
146 mAnimationDuration = StatusBar.FADE_KEYGUARD_DURATION;
Lucas Dupin193677c2018-06-11 19:16:03 -0700147 mAnimateChange = !mLaunchingAffordanceWithPreview;
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800148
Lucas Dupind35502f2018-06-27 13:35:52 -0700149 if (previousState == ScrimState.AOD) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800150 // 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 Dupin9e3fa102017-11-08 17:16:55 -0800158 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 Dupin43d0d732017-11-16 11:23:49 -0800177 boolean mDisplayRequiresBlanking;
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700178 boolean mWallpaperSupportsAmbientMode;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800179 int mIndex;
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700180 boolean mHasBackdrop;
Lucas Dupin193677c2018-06-11 19:16:03 -0700181 boolean mLaunchingAffordanceWithPreview;
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800182
183 ScrimState(int index) {
184 mIndex = index;
185 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800186
187 public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters) {
188 mScrimInFront = scrimInFront;
189 mScrimBehind = scrimBehind;
190 mDozeParameters = dozeParameters;
Lucas Dupin43d0d732017-11-16 11:23:49 -0800191 mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800192 }
193
194 public void prepare(ScrimState previousState) {
195 }
196
Lucas Dupin5866aaf2018-02-02 14:45:31 -0800197 public int getIndex() {
198 return mIndex;
199 }
200
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800201 public float getFrontAlpha() {
202 return mCurrentInFrontAlpha;
203 }
204
Lucas Dupinb380c882018-02-25 21:57:17 -0800205 public float getBehindAlpha(float busyness) {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800206 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 Dupin7517b5d2017-08-22 12:51:25 -0700249
250 public void setWallpaperSupportsAmbientMode(boolean wallpaperSupportsAmbientMode) {
251 mWallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode;
252 }
Lucas Dupin38962d72018-03-14 12:41:39 -0700253
Lucas Dupin193677c2018-06-11 19:16:03 -0700254 public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
255 mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
256 }
257
Lucas Dupin38962d72018-03-14 12:41:39 -0700258 public boolean isLowPowerState() {
259 return false;
260 }
Lucas Dupinf8463ee2018-06-11 16:18:15 -0700261
262 public void setHasBackdrop(boolean hasBackdrop) {
263 mHasBackdrop = hasBackdrop;
264 }
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800265}