blob: fe76ae75152066bcff455857748859dc7140a0a8 [file] [log] [blame]
Jorim Jaggiecc798e2014-05-26 18:14:37 +02001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Selim Cinekaac93252015-04-14 20:04:12 -070021import android.animation.PropertyValuesHolder;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020022import android.animation.ValueAnimator;
John Spurlockd06aa572014-09-10 10:40:49 -040023import android.content.Context;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020024import android.graphics.Color;
Selim Cinek6811d722016-01-19 17:53:12 -080025import android.graphics.Rect;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020026import android.view.View;
27import android.view.ViewTreeObserver;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020028import android.view.animation.DecelerateInterpolator;
29import android.view.animation.Interpolator;
Jorim Jaggi0d210f62015-07-10 14:24:44 -070030import android.view.animation.PathInterpolator;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020031
John Spurlockbf370992014-06-17 13:58:31 -040032import com.android.systemui.R;
Selim Cineka0fad3b2014-09-19 17:20:05 +020033import com.android.systemui.statusbar.BackDropView;
Selim Cinekaac93252015-04-14 20:04:12 -070034import com.android.systemui.statusbar.ExpandableNotificationRow;
35import com.android.systemui.statusbar.NotificationData;
Selim Cineka0fad3b2014-09-19 17:20:05 +020036import com.android.systemui.statusbar.ScrimView;
Selim Cinekaac93252015-04-14 20:04:12 -070037import com.android.systemui.statusbar.policy.HeadsUpManager;
38import com.android.systemui.statusbar.stack.StackStateAnimator;
John Spurlockbf370992014-06-17 13:58:31 -040039
Jorim Jaggiecc798e2014-05-26 18:14:37 +020040/**
41 * Controls both the scrim behind the notifications and in front of the notifications (when a
42 * security method gets shown).
43 */
Selim Cinekaac93252015-04-14 20:04:12 -070044public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
45 HeadsUpManager.OnHeadsUpChangedListener {
John Spurlock8b12f222014-09-09 11:54:11 -040046 public static final long ANIMATION_DURATION = 220;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070047 public static final Interpolator KEYGUARD_FADE_OUT_INTERPOLATOR
48 = new PathInterpolator(0f, 0, 0.7f, 1f);
John Spurlock8b12f222014-09-09 11:54:11 -040049
Jorim Jaggiecc798e2014-05-26 18:14:37 +020050 private static final float SCRIM_BEHIND_ALPHA = 0.62f;
Jorim Jaggie5716222015-05-14 14:13:20 -070051 private static final float SCRIM_BEHIND_ALPHA_KEYGUARD = 0.45f;
Jorim Jaggi76a16232014-08-08 17:00:47 +020052 private static final float SCRIM_BEHIND_ALPHA_UNLOCKING = 0.2f;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020053 private static final float SCRIM_IN_FRONT_ALPHA = 0.75f;
John Spurlockbf370992014-06-17 13:58:31 -040054 private static final int TAG_KEY_ANIM = R.id.scrim;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070055 private static final int TAG_KEY_ANIM_TARGET = R.id.scrim_target;
Selim Cinek5104a6d2015-12-18 18:38:31 -080056 private static final int TAG_START_ALPHA = R.id.scrim_alpha_start;
57 private static final int TAG_END_ALPHA = R.id.scrim_alpha_end;
John Spurlockbf370992014-06-17 13:58:31 -040058
Xiaohui Chen5da71352016-02-22 10:04:41 -080059 protected final ScrimView mScrimBehind;
Selim Cineka0fad3b2014-09-19 17:20:05 +020060 private final ScrimView mScrimInFront;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020061 private final UnlockMethodCache mUnlockMethodCache;
Selim Cinekaac93252015-04-14 20:04:12 -070062 private final View mHeadsUpScrim;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020063
Xiaohui Chen5da71352016-02-22 10:04:41 -080064 protected boolean mKeyguardShowing;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020065 private float mFraction;
66
67 private boolean mDarkenWhileDragging;
Xiaohui Chen5da71352016-02-22 10:04:41 -080068 protected boolean mBouncerShowing;
Jorim Jaggi0d210f62015-07-10 14:24:44 -070069 private boolean mWakeAndUnlocking;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020070 private boolean mAnimateChange;
71 private boolean mUpdatePending;
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +020072 private boolean mExpanding;
Jorim Jaggie29b2db2014-05-30 23:17:03 +020073 private boolean mAnimateKeyguardFadingOut;
74 private long mDurationOverride = -1;
75 private long mAnimationDelay;
76 private Runnable mOnAnimationFinished;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020077 private final Interpolator mInterpolator = new DecelerateInterpolator();
Selim Cineka0fad3b2014-09-19 17:20:05 +020078 private BackDropView mBackDropView;
Jorim Jaggi0e664392014-09-27 01:30:22 +020079 private boolean mScrimSrcEnabled;
Jorim Jaggi048af1f2014-11-11 22:51:10 +010080 private boolean mDozing;
81 private float mDozeInFrontAlpha;
82 private float mDozeBehindAlpha;
83 private float mCurrentInFrontAlpha;
84 private float mCurrentBehindAlpha;
Selim Cinekaac93252015-04-14 20:04:12 -070085 private float mCurrentHeadsUpAlpha = 1;
Selim Cinek684a4422015-04-15 16:18:39 -070086 private int mPinnedHeadsUpCount;
Selim Cinekaac93252015-04-14 20:04:12 -070087 private float mTopHeadsUpDragAmount;
88 private View mDraggedHeadsUpView;
Selim Cinek37c110f2015-05-22 12:38:44 -070089 private boolean mForceHideScrims;
Jorim Jaggiab45a212015-08-20 16:59:44 -070090 private boolean mSkipFirstFrame;
Selim Cinek372d1bd2015-08-14 13:19:37 -070091 private boolean mDontAnimateBouncerChanges;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020092
Selim Cinekaac93252015-04-14 20:04:12 -070093 public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront, View headsUpScrim,
94 boolean scrimSrcEnabled) {
Jorim Jaggiecc798e2014-05-26 18:14:37 +020095 mScrimBehind = scrimBehind;
96 mScrimInFront = scrimInFront;
Selim Cinekaac93252015-04-14 20:04:12 -070097 mHeadsUpScrim = headsUpScrim;
John Spurlockd06aa572014-09-10 10:40:49 -040098 final Context context = scrimBehind.getContext();
99 mUnlockMethodCache = UnlockMethodCache.getInstance(context);
Jorim Jaggi0e664392014-09-27 01:30:22 +0200100 mScrimSrcEnabled = scrimSrcEnabled;
Selim Cinekaac93252015-04-14 20:04:12 -0700101 updateHeadsUpScrim(false);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200102 }
103
104 public void setKeyguardShowing(boolean showing) {
105 mKeyguardShowing = showing;
106 scheduleUpdate();
107 }
108
109 public void onTrackingStarted() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200110 mExpanding = true;
Selim Cineke8bae622015-07-15 13:24:06 -0700111 mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer();
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200112 }
113
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200114 public void onExpandingFinished() {
115 mExpanding = false;
116 }
117
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200118 public void setPanelExpansion(float fraction) {
Jorim Jaggi93439da2014-06-30 23:53:39 +0200119 if (mFraction != fraction) {
120 mFraction = fraction;
121 scheduleUpdate();
Selim Cinek131c1e22015-05-11 19:04:49 -0700122 if (mPinnedHeadsUpCount != 0) {
123 updateHeadsUpScrim(false);
124 }
Jorim Jaggi93439da2014-06-30 23:53:39 +0200125 }
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200126 }
127
128 public void setBouncerShowing(boolean showing) {
129 mBouncerShowing = showing;
Selim Cinek372d1bd2015-08-14 13:19:37 -0700130 mAnimateChange = !mExpanding && !mDontAnimateBouncerChanges;
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200131 scheduleUpdate();
132 }
133
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700134 public void setWakeAndUnlocking() {
135 mWakeAndUnlocking = true;
136 scheduleUpdate();
137 }
138
Jorim Jaggiab45a212015-08-20 16:59:44 -0700139 public void animateKeyguardFadingOut(long delay, long duration, Runnable onAnimationFinished,
140 boolean skipFirstFrame) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700141 mWakeAndUnlocking = false;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200142 mAnimateKeyguardFadingOut = true;
143 mDurationOverride = duration;
144 mAnimationDelay = delay;
145 mAnimateChange = true;
Jorim Jaggiab45a212015-08-20 16:59:44 -0700146 mSkipFirstFrame = skipFirstFrame;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200147 mOnAnimationFinished = onAnimationFinished;
148 scheduleUpdate();
Jorim Jaggiab45a212015-08-20 16:59:44 -0700149
150 // No need to wait for the next frame to be drawn for this case - onPreDraw will execute
151 // the changes we just scheduled.
152 onPreDraw();
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200153 }
154
Selim Cinekedd32b82015-06-23 22:05:58 -0400155 public void abortKeyguardFadingOut() {
156 if (mAnimateKeyguardFadingOut) {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700157 endAnimateKeyguardFadingOut(true /* force */);
Selim Cinekedd32b82015-06-23 22:05:58 -0400158 }
159 }
160
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200161 public void animateGoingToFullShade(long delay, long duration) {
162 mDurationOverride = duration;
163 mAnimationDelay = delay;
164 mAnimateChange = true;
165 scheduleUpdate();
166 }
167
Selim Cinek5104a6d2015-12-18 18:38:31 -0800168 public void animateNextChange() {
169 mAnimateChange = true;
170 }
171
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100172 public void setDozing(boolean dozing) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700173 if (mDozing != dozing) {
174 mDozing = dozing;
175 scheduleUpdate();
176 }
John Spurlockbf370992014-06-17 13:58:31 -0400177 }
178
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100179 public void setDozeInFrontAlpha(float alpha) {
180 mDozeInFrontAlpha = alpha;
181 updateScrimColor(mScrimInFront);
John Spurlockd06aa572014-09-10 10:40:49 -0400182 }
183
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100184 public void setDozeBehindAlpha(float alpha) {
185 mDozeBehindAlpha = alpha;
186 updateScrimColor(mScrimBehind);
John Spurlockbf370992014-06-17 13:58:31 -0400187 }
188
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100189 public float getDozeBehindAlpha() {
190 return mDozeBehindAlpha;
Jeff Brown4d69e222014-09-18 15:27:50 -0700191 }
192
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100193 public float getDozeInFrontAlpha() {
194 return mDozeInFrontAlpha;
John Spurlockbf370992014-06-17 13:58:31 -0400195 }
196
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200197 private void scheduleUpdate() {
198 if (mUpdatePending) return;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200199
200 // Make sure that a frame gets scheduled.
201 mScrimBehind.invalidate();
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200202 mScrimBehind.getViewTreeObserver().addOnPreDrawListener(this);
203 mUpdatePending = true;
204 }
205
Xiaohui Chen5da71352016-02-22 10:04:41 -0800206 protected void updateScrims() {
Selim Cinek37c110f2015-05-22 12:38:44 -0700207 if (mAnimateKeyguardFadingOut || mForceHideScrims) {
Selim Cinekbaa23272014-07-08 18:01:07 +0200208 setScrimInFrontColor(0f);
209 setScrimBehindColor(0f);
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700210 } else if (mWakeAndUnlocking) {
211
212 // During wake and unlock, we first hide everything behind a black scrim, which then
213 // gets faded out from animateKeyguardFadingOut.
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700214 if (mDozing) {
215 setScrimInFrontColor(0f);
216 setScrimBehindColor(1f);
217 } else {
218 setScrimInFrontColor(1f);
219 setScrimBehindColor(0f);
220 }
John Spurlock8b12f222014-09-09 11:54:11 -0400221 } else if (!mKeyguardShowing && !mBouncerShowing) {
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200222 updateScrimNormal();
223 setScrimInFrontColor(0);
224 } else {
225 updateScrimKeyguard();
226 }
227 mAnimateChange = false;
228 }
229
230 private void updateScrimKeyguard() {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200231 if (mExpanding && mDarkenWhileDragging) {
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200232 float behindFraction = Math.max(0, Math.min(mFraction, 1));
233 float fraction = 1 - behindFraction;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200234 fraction = (float) Math.pow(fraction, 0.8f);
235 behindFraction = (float) Math.pow(behindFraction, 0.8f);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200236 setScrimInFrontColor(fraction * SCRIM_IN_FRONT_ALPHA);
237 setScrimBehindColor(behindFraction * SCRIM_BEHIND_ALPHA_KEYGUARD);
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200238 } else if (mBouncerShowing) {
239 setScrimInFrontColor(SCRIM_IN_FRONT_ALPHA);
240 setScrimBehindColor(0f);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200241 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +0200242 float fraction = Math.max(0, Math.min(mFraction, 1));
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200243 setScrimInFrontColor(0f);
Jorim Jaggi76a16232014-08-08 17:00:47 +0200244 setScrimBehindColor(fraction
245 * (SCRIM_BEHIND_ALPHA_KEYGUARD - SCRIM_BEHIND_ALPHA_UNLOCKING)
246 + SCRIM_BEHIND_ALPHA_UNLOCKING);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200247 }
248 }
249
250 private void updateScrimNormal() {
251 float frac = mFraction;
252 // let's start this 20% of the way down the screen
253 frac = frac * 1.2f - 0.2f;
254 if (frac <= 0) {
255 setScrimBehindColor(0);
256 } else {
257 // woo, special effects
258 final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2f))));
259 setScrimBehindColor(k * SCRIM_BEHIND_ALPHA);
260 }
261 }
262
263 private void setScrimBehindColor(float alpha) {
264 setScrimColor(mScrimBehind, alpha);
265 }
266
267 private void setScrimInFrontColor(float alpha) {
268 setScrimColor(mScrimInFront, alpha);
269 if (alpha == 0f) {
270 mScrimInFront.setClickable(false);
271 } else {
272
John Spurlock8b12f222014-09-09 11:54:11 -0400273 // Eat touch events (unless dozing).
274 mScrimInFront.setClickable(!mDozing);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200275 }
276 }
277
Selim Cinekaac93252015-04-14 20:04:12 -0700278 private void setScrimColor(View scrim, float alpha) {
Selim Cinek5104a6d2015-12-18 18:38:31 -0800279 updateScrim(mAnimateChange, scrim, alpha, getCurrentScrimAlpha(scrim));
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200280 }
281
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100282 private float getDozeAlpha(View scrim) {
283 return scrim == mScrimBehind ? mDozeBehindAlpha : mDozeInFrontAlpha;
284 }
285
286 private float getCurrentScrimAlpha(View scrim) {
Selim Cinekaac93252015-04-14 20:04:12 -0700287 return scrim == mScrimBehind ? mCurrentBehindAlpha
288 : scrim == mScrimInFront ? mCurrentInFrontAlpha
289 : mCurrentHeadsUpAlpha;
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100290 }
291
292 private void setCurrentScrimAlpha(View scrim, float alpha) {
293 if (scrim == mScrimBehind) {
294 mCurrentBehindAlpha = alpha;
Selim Cinekaac93252015-04-14 20:04:12 -0700295 } else if (scrim == mScrimInFront) {
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100296 mCurrentInFrontAlpha = alpha;
Selim Cinekaac93252015-04-14 20:04:12 -0700297 } else {
298 alpha = Math.max(0.0f, Math.min(1.0f, alpha));
299 mCurrentHeadsUpAlpha = alpha;
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200300 }
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100301 }
302
Selim Cinekaac93252015-04-14 20:04:12 -0700303 private void updateScrimColor(View scrim) {
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100304 float alpha1 = getCurrentScrimAlpha(scrim);
Selim Cinekaac93252015-04-14 20:04:12 -0700305 if (scrim instanceof ScrimView) {
306 float alpha2 = getDozeAlpha(scrim);
307 float alpha = 1 - (1 - alpha1) * (1 - alpha2);
308 ((ScrimView) scrim).setScrimColor(Color.argb((int) (alpha * 255), 0, 0, 0));
309 } else {
310 scrim.setAlpha(alpha1);
311 }
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100312 }
313
Selim Cinekaac93252015-04-14 20:04:12 -0700314 private void startScrimAnimation(final View scrim, float target) {
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100315 float current = getCurrentScrimAlpha(scrim);
316 ValueAnimator anim = ValueAnimator.ofFloat(current, target);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200317 anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
318 @Override
319 public void onAnimationUpdate(ValueAnimator animation) {
Jorim Jaggi048af1f2014-11-11 22:51:10 +0100320 float alpha = (float) animation.getAnimatedValue();
321 setCurrentScrimAlpha(scrim, alpha);
322 updateScrimColor(scrim);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200323 }
324 });
Jorim Jaggi16423aa2014-10-28 11:42:58 +0100325 anim.setInterpolator(getInterpolator());
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200326 anim.setStartDelay(mAnimationDelay);
327 anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION);
328 anim.addListener(new AnimatorListenerAdapter() {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200329 @Override
330 public void onAnimationEnd(Animator animation) {
331 if (mOnAnimationFinished != null) {
332 mOnAnimationFinished.run();
333 mOnAnimationFinished = null;
334 }
John Spurlockbf370992014-06-17 13:58:31 -0400335 scrim.setTag(TAG_KEY_ANIM, null);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700336 scrim.setTag(TAG_KEY_ANIM_TARGET, null);
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200337 }
338 });
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200339 anim.start();
Jorim Jaggiab45a212015-08-20 16:59:44 -0700340 if (mSkipFirstFrame) {
341 anim.setCurrentPlayTime(16);
342 }
John Spurlockbf370992014-06-17 13:58:31 -0400343 scrim.setTag(TAG_KEY_ANIM, anim);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700344 scrim.setTag(TAG_KEY_ANIM_TARGET, target);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200345 }
346
Jorim Jaggi16423aa2014-10-28 11:42:58 +0100347 private Interpolator getInterpolator() {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700348 return mAnimateKeyguardFadingOut ? KEYGUARD_FADE_OUT_INTERPOLATOR : mInterpolator;
Jorim Jaggi16423aa2014-10-28 11:42:58 +0100349 }
350
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200351 @Override
352 public boolean onPreDraw() {
353 mScrimBehind.getViewTreeObserver().removeOnPreDrawListener(this);
354 mUpdatePending = false;
Selim Cinek372d1bd2015-08-14 13:19:37 -0700355 if (mDontAnimateBouncerChanges) {
356 mDontAnimateBouncerChanges = false;
357 }
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200358 updateScrims();
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200359 mDurationOverride = -1;
360 mAnimationDelay = 0;
Jorim Jaggiab45a212015-08-20 16:59:44 -0700361 mSkipFirstFrame = false;
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200362
363 // Make sure that we always call the listener even if we didn't start an animation.
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700364 endAnimateKeyguardFadingOut(false /* force */);
Selim Cinekedd32b82015-06-23 22:05:58 -0400365 return true;
366 }
367
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700368 private void endAnimateKeyguardFadingOut(boolean force) {
Selim Cinekedd32b82015-06-23 22:05:58 -0400369 mAnimateKeyguardFadingOut = false;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700370 if ((force || (!isAnimating(mScrimInFront) && !isAnimating(mScrimBehind)))
371 && mOnAnimationFinished != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200372 mOnAnimationFinished.run();
373 mOnAnimationFinished = null;
374 }
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200375 }
John Spurlockbf370992014-06-17 13:58:31 -0400376
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700377 private boolean isAnimating(View scrim) {
378 return scrim.getTag(TAG_KEY_ANIM) != null;
379 }
380
Selim Cineka0fad3b2014-09-19 17:20:05 +0200381 public void setBackDropView(BackDropView backDropView) {
382 mBackDropView = backDropView;
383 mBackDropView.setOnVisibilityChangedRunnable(new Runnable() {
384 @Override
385 public void run() {
386 updateScrimBehindDrawingMode();
387 }
388 });
389 updateScrimBehindDrawingMode();
390 }
391
392 private void updateScrimBehindDrawingMode() {
Jorim Jaggi0e664392014-09-27 01:30:22 +0200393 boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE && mScrimSrcEnabled;
Selim Cineka0fad3b2014-09-19 17:20:05 +0200394 mScrimBehind.setDrawAsSrc(asSrc);
395 }
Selim Cinekaac93252015-04-14 20:04:12 -0700396
397 @Override
John Spurlockb349af572015-04-29 12:24:19 -0400398 public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) {
Selim Cinekaac93252015-04-14 20:04:12 -0700399 }
400
401 @Override
Selim Cinek684a4422015-04-15 16:18:39 -0700402 public void onHeadsUpPinned(ExpandableNotificationRow headsUp) {
403 mPinnedHeadsUpCount++;
404 updateHeadsUpScrim(true);
405 }
406
407 @Override
408 public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) {
409 mPinnedHeadsUpCount--;
410 if (headsUp == mDraggedHeadsUpView) {
411 mDraggedHeadsUpView = null;
412 mTopHeadsUpDragAmount = 0.0f;
Selim Cinekaac93252015-04-14 20:04:12 -0700413 }
414 updateHeadsUpScrim(true);
415 }
416
417 @Override
Selim Cinek684a4422015-04-15 16:18:39 -0700418 public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
Selim Cinekaac93252015-04-14 20:04:12 -0700419 }
420
421 private void updateHeadsUpScrim(boolean animate) {
Selim Cinek5104a6d2015-12-18 18:38:31 -0800422 updateScrim(animate, mHeadsUpScrim, calculateHeadsUpAlpha(), mCurrentHeadsUpAlpha);
423 }
424
425 private void updateScrim(boolean animate, View scrim, float alpha, float currentAlpha) {
426 ValueAnimator previousAnimator = StackStateAnimator.getChildTag(scrim,
Selim Cinekaac93252015-04-14 20:04:12 -0700427 TAG_KEY_ANIM);
428 float animEndValue = -1;
429 if (previousAnimator != null) {
Selim Cinek5104a6d2015-12-18 18:38:31 -0800430 if (animate || alpha == currentAlpha) {
Selim Cinekaac93252015-04-14 20:04:12 -0700431 previousAnimator.cancel();
Selim Cinek737bff32015-05-08 16:08:35 -0700432 } else {
Selim Cinek5104a6d2015-12-18 18:38:31 -0800433 animEndValue = StackStateAnimator.getChildTag(scrim, TAG_END_ALPHA);
Selim Cinekaac93252015-04-14 20:04:12 -0700434 }
Selim Cinekaac93252015-04-14 20:04:12 -0700435 }
Selim Cinek5104a6d2015-12-18 18:38:31 -0800436 if (alpha != currentAlpha && alpha != animEndValue) {
Selim Cinekaac93252015-04-14 20:04:12 -0700437 if (animate) {
Selim Cinek5104a6d2015-12-18 18:38:31 -0800438 startScrimAnimation(scrim, alpha);
439 scrim.setTag(TAG_START_ALPHA, currentAlpha);
440 scrim.setTag(TAG_END_ALPHA, alpha);
Selim Cinekaac93252015-04-14 20:04:12 -0700441 } else {
442 if (previousAnimator != null) {
Selim Cinek5104a6d2015-12-18 18:38:31 -0800443 float previousStartValue = StackStateAnimator.getChildTag(scrim,
444 TAG_START_ALPHA);
445 float previousEndValue = StackStateAnimator.getChildTag(scrim,
446 TAG_END_ALPHA);
Selim Cinekaac93252015-04-14 20:04:12 -0700447 // we need to increase all animation keyframes of the previous animator by the
448 // relative change to the end value
449 PropertyValuesHolder[] values = previousAnimator.getValues();
450 float relativeDiff = alpha - previousEndValue;
451 float newStartValue = previousStartValue + relativeDiff;
452 values[0].setFloatValues(newStartValue, alpha);
Selim Cinek5104a6d2015-12-18 18:38:31 -0800453 scrim.setTag(TAG_START_ALPHA, newStartValue);
454 scrim.setTag(TAG_END_ALPHA, alpha);
Selim Cinekaac93252015-04-14 20:04:12 -0700455 previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
456 } else {
457 // update the alpha directly
Selim Cinek5104a6d2015-12-18 18:38:31 -0800458 setCurrentScrimAlpha(scrim, alpha);
459 updateScrimColor(scrim);
Selim Cinekaac93252015-04-14 20:04:12 -0700460 }
461 }
462 }
463 }
464
Selim Cinek684a4422015-04-15 16:18:39 -0700465 /**
466 * Set the amount the current top heads up view is dragged. The range is from 0 to 1 and 0 means
467 * the heads up is in its resting space and 1 means it's fully dragged out.
468 *
469 * @param draggedHeadsUpView the dragged view
470 * @param topHeadsUpDragAmount how far is it dragged
471 */
Selim Cinekaac93252015-04-14 20:04:12 -0700472 public void setTopHeadsUpDragAmount(View draggedHeadsUpView, float topHeadsUpDragAmount) {
473 mTopHeadsUpDragAmount = topHeadsUpDragAmount;
474 mDraggedHeadsUpView = draggedHeadsUpView;
475 updateHeadsUpScrim(false);
476 }
477
478 private float calculateHeadsUpAlpha() {
Selim Cinek131c1e22015-05-11 19:04:49 -0700479 float alpha;
Selim Cinek684a4422015-04-15 16:18:39 -0700480 if (mPinnedHeadsUpCount >= 2) {
Selim Cinek131c1e22015-05-11 19:04:49 -0700481 alpha = 1.0f;
Selim Cinek684a4422015-04-15 16:18:39 -0700482 } else if (mPinnedHeadsUpCount == 0) {
Selim Cinek131c1e22015-05-11 19:04:49 -0700483 alpha = 0.0f;
Selim Cinekaac93252015-04-14 20:04:12 -0700484 } else {
Selim Cinek131c1e22015-05-11 19:04:49 -0700485 alpha = 1.0f - mTopHeadsUpDragAmount;
Selim Cinekaac93252015-04-14 20:04:12 -0700486 }
Selim Cinek131c1e22015-05-11 19:04:49 -0700487 float expandFactor = (1.0f - mFraction);
488 expandFactor = Math.max(expandFactor, 0.0f);
489 return alpha * expandFactor;
Selim Cinekaac93252015-04-14 20:04:12 -0700490 }
Selim Cinek37c110f2015-05-22 12:38:44 -0700491
492 public void forceHideScrims(boolean hide) {
493 mForceHideScrims = hide;
494 mAnimateChange = false;
495 scheduleUpdate();
496 }
Selim Cinek372d1bd2015-08-14 13:19:37 -0700497
498 public void dontAnimateBouncerChangesUntilNextFrame() {
499 mDontAnimateBouncerChanges = true;
500 }
Selim Cinek6811d722016-01-19 17:53:12 -0800501
502 public void setExcludedBackgroundArea(Rect area) {
503 mScrimBehind.setExcludedArea(area);
504 }
Selim Cinekd35c2792016-01-21 13:20:57 -0800505
506 public int getScrimBehindColor() {
507 return mScrimBehind.getScrimColorWithAlpha();
508 }
509
510 public void setScrimBehindChangeRunnable(Runnable changeRunnable) {
511 mScrimBehind.setChangeRunnable(changeRunnable);
512 }
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200513}