Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 21 | import android.animation.PropertyValuesHolder; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 23 | import android.content.Context; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 24 | import android.graphics.Color; |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 25 | import android.graphics.Rect; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 26 | import android.view.View; |
| 27 | import android.view.ViewTreeObserver; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 28 | import android.view.animation.DecelerateInterpolator; |
| 29 | import android.view.animation.Interpolator; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 30 | import android.view.animation.PathInterpolator; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 31 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 32 | import com.android.systemui.R; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 33 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
| 34 | import com.android.systemui.statusbar.NotificationData; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 35 | import com.android.systemui.statusbar.ScrimView; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 37 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 38 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 39 | /** |
| 40 | * Controls both the scrim behind the notifications and in front of the notifications (when a |
| 41 | * security method gets shown). |
| 42 | */ |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 43 | public class ScrimController implements ViewTreeObserver.OnPreDrawListener, |
| 44 | HeadsUpManager.OnHeadsUpChangedListener { |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 45 | public static final long ANIMATION_DURATION = 220; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 46 | public static final Interpolator KEYGUARD_FADE_OUT_INTERPOLATOR |
| 47 | = new PathInterpolator(0f, 0, 0.7f, 1f); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 48 | private static final float SCRIM_BEHIND_ALPHA = 0.62f; |
Jorim Jaggi | e571622 | 2015-05-14 14:13:20 -0700 | [diff] [blame] | 49 | private static final float SCRIM_BEHIND_ALPHA_KEYGUARD = 0.45f; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 50 | private static final float SCRIM_BEHIND_ALPHA_UNLOCKING = 0.2f; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 51 | private static final float SCRIM_IN_FRONT_ALPHA = 0.75f; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 52 | private static final int TAG_KEY_ANIM = R.id.scrim; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 53 | private static final int TAG_KEY_ANIM_TARGET = R.id.scrim_target; |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 54 | private static final int TAG_START_ALPHA = R.id.scrim_alpha_start; |
| 55 | private static final int TAG_END_ALPHA = R.id.scrim_alpha_end; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 56 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 57 | protected final ScrimView mScrimBehind; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 58 | private final ScrimView mScrimInFront; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 59 | private final UnlockMethodCache mUnlockMethodCache; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 60 | private final View mHeadsUpScrim; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 61 | |
Xiaohui Chen | 4dab4b5 | 2016-03-07 12:31:14 -0800 | [diff] [blame] | 62 | private float mScrimBehindAlpha = SCRIM_BEHIND_ALPHA; |
| 63 | private float mScrimBehindAlphaKeyguard = SCRIM_BEHIND_ALPHA_KEYGUARD; |
| 64 | private float mScrimBehindAlphaUnlocking = SCRIM_BEHIND_ALPHA_UNLOCKING; |
| 65 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 66 | protected boolean mKeyguardShowing; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 67 | private float mFraction; |
| 68 | |
| 69 | private boolean mDarkenWhileDragging; |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 70 | protected boolean mBouncerShowing; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 71 | private boolean mWakeAndUnlocking; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 72 | private boolean mAnimateChange; |
| 73 | private boolean mUpdatePending; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 74 | private boolean mExpanding; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 75 | private boolean mAnimateKeyguardFadingOut; |
| 76 | private long mDurationOverride = -1; |
| 77 | private long mAnimationDelay; |
| 78 | private Runnable mOnAnimationFinished; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 79 | private final Interpolator mInterpolator = new DecelerateInterpolator(); |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 80 | private boolean mDozing; |
| 81 | private float mDozeInFrontAlpha; |
| 82 | private float mDozeBehindAlpha; |
| 83 | private float mCurrentInFrontAlpha; |
| 84 | private float mCurrentBehindAlpha; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 85 | private float mCurrentHeadsUpAlpha = 1; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 86 | private int mPinnedHeadsUpCount; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 87 | private float mTopHeadsUpDragAmount; |
| 88 | private View mDraggedHeadsUpView; |
Selim Cinek | 37c110f | 2015-05-22 12:38:44 -0700 | [diff] [blame] | 89 | private boolean mForceHideScrims; |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 90 | private boolean mSkipFirstFrame; |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 91 | private boolean mDontAnimateBouncerChanges; |
Adrian Roos | 5f72c92 | 2016-03-08 15:54:26 -0800 | [diff] [blame] | 92 | private boolean mKeyguardFadingOutInProgress; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 93 | |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 94 | public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront, View headsUpScrim) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 95 | mScrimBehind = scrimBehind; |
| 96 | mScrimInFront = scrimInFront; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 97 | mHeadsUpScrim = headsUpScrim; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 98 | final Context context = scrimBehind.getContext(); |
| 99 | mUnlockMethodCache = UnlockMethodCache.getInstance(context); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 100 | updateHeadsUpScrim(false); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | public void setKeyguardShowing(boolean showing) { |
| 104 | mKeyguardShowing = showing; |
| 105 | scheduleUpdate(); |
| 106 | } |
| 107 | |
Xiaohui Chen | 4dab4b5 | 2016-03-07 12:31:14 -0800 | [diff] [blame] | 108 | public void setShowScrimBehind(boolean show) { |
| 109 | if (show) { |
| 110 | mScrimBehindAlpha = SCRIM_BEHIND_ALPHA; |
| 111 | mScrimBehindAlphaKeyguard = SCRIM_BEHIND_ALPHA_KEYGUARD; |
| 112 | mScrimBehindAlphaUnlocking = SCRIM_BEHIND_ALPHA_UNLOCKING; |
| 113 | } else { |
| 114 | mScrimBehindAlpha = 0; |
| 115 | mScrimBehindAlphaKeyguard = 0; |
| 116 | mScrimBehindAlphaUnlocking = 0; |
| 117 | } |
| 118 | scheduleUpdate(); |
| 119 | } |
| 120 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 121 | public void onTrackingStarted() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 122 | mExpanding = true; |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 123 | mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 126 | public void onExpandingFinished() { |
| 127 | mExpanding = false; |
| 128 | } |
| 129 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 130 | public void setPanelExpansion(float fraction) { |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 131 | if (mFraction != fraction) { |
| 132 | mFraction = fraction; |
| 133 | scheduleUpdate(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 134 | if (mPinnedHeadsUpCount != 0) { |
| 135 | updateHeadsUpScrim(false); |
| 136 | } |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 137 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | public void setBouncerShowing(boolean showing) { |
| 141 | mBouncerShowing = showing; |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 142 | mAnimateChange = !mExpanding && !mDontAnimateBouncerChanges; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 143 | scheduleUpdate(); |
| 144 | } |
| 145 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 146 | public void setWakeAndUnlocking() { |
| 147 | mWakeAndUnlocking = true; |
| 148 | scheduleUpdate(); |
| 149 | } |
| 150 | |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 151 | public void animateKeyguardFadingOut(long delay, long duration, Runnable onAnimationFinished, |
| 152 | boolean skipFirstFrame) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 153 | mWakeAndUnlocking = false; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 154 | mAnimateKeyguardFadingOut = true; |
| 155 | mDurationOverride = duration; |
| 156 | mAnimationDelay = delay; |
| 157 | mAnimateChange = true; |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 158 | mSkipFirstFrame = skipFirstFrame; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 159 | mOnAnimationFinished = onAnimationFinished; |
| 160 | scheduleUpdate(); |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 161 | |
| 162 | // No need to wait for the next frame to be drawn for this case - onPreDraw will execute |
| 163 | // the changes we just scheduled. |
| 164 | onPreDraw(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 167 | public void abortKeyguardFadingOut() { |
| 168 | if (mAnimateKeyguardFadingOut) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 169 | endAnimateKeyguardFadingOut(true /* force */); |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 173 | public void animateGoingToFullShade(long delay, long duration) { |
| 174 | mDurationOverride = duration; |
| 175 | mAnimationDelay = delay; |
| 176 | mAnimateChange = true; |
| 177 | scheduleUpdate(); |
| 178 | } |
| 179 | |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 180 | public void animateNextChange() { |
| 181 | mAnimateChange = true; |
| 182 | } |
| 183 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 184 | public void setDozing(boolean dozing) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 185 | if (mDozing != dozing) { |
| 186 | mDozing = dozing; |
| 187 | scheduleUpdate(); |
| 188 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 191 | public void setDozeInFrontAlpha(float alpha) { |
| 192 | mDozeInFrontAlpha = alpha; |
| 193 | updateScrimColor(mScrimInFront); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 196 | public void setDozeBehindAlpha(float alpha) { |
| 197 | mDozeBehindAlpha = alpha; |
| 198 | updateScrimColor(mScrimBehind); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 201 | public float getDozeBehindAlpha() { |
| 202 | return mDozeBehindAlpha; |
Jeff Brown | 4d69e22 | 2014-09-18 15:27:50 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 205 | public float getDozeInFrontAlpha() { |
| 206 | return mDozeInFrontAlpha; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 209 | private void scheduleUpdate() { |
| 210 | if (mUpdatePending) return; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 211 | |
| 212 | // Make sure that a frame gets scheduled. |
| 213 | mScrimBehind.invalidate(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 214 | mScrimBehind.getViewTreeObserver().addOnPreDrawListener(this); |
| 215 | mUpdatePending = true; |
| 216 | } |
| 217 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 218 | protected void updateScrims() { |
Selim Cinek | 37c110f | 2015-05-22 12:38:44 -0700 | [diff] [blame] | 219 | if (mAnimateKeyguardFadingOut || mForceHideScrims) { |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 220 | setScrimInFrontColor(0f); |
| 221 | setScrimBehindColor(0f); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 222 | } else if (mWakeAndUnlocking) { |
| 223 | |
| 224 | // During wake and unlock, we first hide everything behind a black scrim, which then |
| 225 | // gets faded out from animateKeyguardFadingOut. |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 226 | if (mDozing) { |
| 227 | setScrimInFrontColor(0f); |
| 228 | setScrimBehindColor(1f); |
| 229 | } else { |
| 230 | setScrimInFrontColor(1f); |
| 231 | setScrimBehindColor(0f); |
| 232 | } |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 233 | } else if (!mKeyguardShowing && !mBouncerShowing) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 234 | updateScrimNormal(); |
| 235 | setScrimInFrontColor(0); |
| 236 | } else { |
| 237 | updateScrimKeyguard(); |
| 238 | } |
| 239 | mAnimateChange = false; |
| 240 | } |
| 241 | |
| 242 | private void updateScrimKeyguard() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 243 | if (mExpanding && mDarkenWhileDragging) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 244 | float behindFraction = Math.max(0, Math.min(mFraction, 1)); |
| 245 | float fraction = 1 - behindFraction; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 246 | fraction = (float) Math.pow(fraction, 0.8f); |
| 247 | behindFraction = (float) Math.pow(behindFraction, 0.8f); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 248 | setScrimInFrontColor(fraction * SCRIM_IN_FRONT_ALPHA); |
Xiaohui Chen | 4dab4b5 | 2016-03-07 12:31:14 -0800 | [diff] [blame] | 249 | setScrimBehindColor(behindFraction * mScrimBehindAlphaKeyguard); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 250 | } else if (mBouncerShowing) { |
| 251 | setScrimInFrontColor(SCRIM_IN_FRONT_ALPHA); |
| 252 | setScrimBehindColor(0f); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 253 | } else { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 254 | float fraction = Math.max(0, Math.min(mFraction, 1)); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 255 | setScrimInFrontColor(0f); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 256 | setScrimBehindColor(fraction |
Xiaohui Chen | 4dab4b5 | 2016-03-07 12:31:14 -0800 | [diff] [blame] | 257 | * (mScrimBehindAlphaKeyguard - mScrimBehindAlphaUnlocking) |
| 258 | + mScrimBehindAlphaUnlocking); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | private void updateScrimNormal() { |
| 263 | float frac = mFraction; |
| 264 | // let's start this 20% of the way down the screen |
| 265 | frac = frac * 1.2f - 0.2f; |
| 266 | if (frac <= 0) { |
| 267 | setScrimBehindColor(0); |
| 268 | } else { |
| 269 | // woo, special effects |
| 270 | final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2f)))); |
Xiaohui Chen | 4dab4b5 | 2016-03-07 12:31:14 -0800 | [diff] [blame] | 271 | setScrimBehindColor(k * mScrimBehindAlpha); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| 275 | private void setScrimBehindColor(float alpha) { |
| 276 | setScrimColor(mScrimBehind, alpha); |
| 277 | } |
| 278 | |
| 279 | private void setScrimInFrontColor(float alpha) { |
| 280 | setScrimColor(mScrimInFront, alpha); |
| 281 | if (alpha == 0f) { |
| 282 | mScrimInFront.setClickable(false); |
| 283 | } else { |
| 284 | |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 285 | // Eat touch events (unless dozing). |
| 286 | mScrimInFront.setClickable(!mDozing); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 290 | private void setScrimColor(View scrim, float alpha) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 291 | updateScrim(mAnimateChange, scrim, alpha, getCurrentScrimAlpha(scrim)); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 294 | private float getDozeAlpha(View scrim) { |
| 295 | return scrim == mScrimBehind ? mDozeBehindAlpha : mDozeInFrontAlpha; |
| 296 | } |
| 297 | |
| 298 | private float getCurrentScrimAlpha(View scrim) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 299 | return scrim == mScrimBehind ? mCurrentBehindAlpha |
| 300 | : scrim == mScrimInFront ? mCurrentInFrontAlpha |
| 301 | : mCurrentHeadsUpAlpha; |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | private void setCurrentScrimAlpha(View scrim, float alpha) { |
| 305 | if (scrim == mScrimBehind) { |
| 306 | mCurrentBehindAlpha = alpha; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 307 | } else if (scrim == mScrimInFront) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 308 | mCurrentInFrontAlpha = alpha; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 309 | } else { |
| 310 | alpha = Math.max(0.0f, Math.min(1.0f, alpha)); |
| 311 | mCurrentHeadsUpAlpha = alpha; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 312 | } |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 313 | } |
| 314 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 315 | private void updateScrimColor(View scrim) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 316 | float alpha1 = getCurrentScrimAlpha(scrim); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 317 | if (scrim instanceof ScrimView) { |
| 318 | float alpha2 = getDozeAlpha(scrim); |
| 319 | float alpha = 1 - (1 - alpha1) * (1 - alpha2); |
| 320 | ((ScrimView) scrim).setScrimColor(Color.argb((int) (alpha * 255), 0, 0, 0)); |
| 321 | } else { |
| 322 | scrim.setAlpha(alpha1); |
| 323 | } |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 326 | private void startScrimAnimation(final View scrim, float target) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 327 | float current = getCurrentScrimAlpha(scrim); |
| 328 | ValueAnimator anim = ValueAnimator.ofFloat(current, target); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 329 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 330 | @Override |
| 331 | public void onAnimationUpdate(ValueAnimator animation) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 332 | float alpha = (float) animation.getAnimatedValue(); |
| 333 | setCurrentScrimAlpha(scrim, alpha); |
| 334 | updateScrimColor(scrim); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 335 | } |
| 336 | }); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 337 | anim.setInterpolator(getInterpolator()); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 338 | anim.setStartDelay(mAnimationDelay); |
| 339 | anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION); |
| 340 | anim.addListener(new AnimatorListenerAdapter() { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 341 | @Override |
| 342 | public void onAnimationEnd(Animator animation) { |
| 343 | if (mOnAnimationFinished != null) { |
| 344 | mOnAnimationFinished.run(); |
| 345 | mOnAnimationFinished = null; |
Adrian Roos | 5f72c92 | 2016-03-08 15:54:26 -0800 | [diff] [blame] | 346 | mKeyguardFadingOutInProgress = false; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 347 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 348 | scrim.setTag(TAG_KEY_ANIM, null); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 349 | scrim.setTag(TAG_KEY_ANIM_TARGET, null); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 350 | } |
| 351 | }); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 352 | anim.start(); |
Adrian Roos | 5f72c92 | 2016-03-08 15:54:26 -0800 | [diff] [blame] | 353 | if (mAnimateKeyguardFadingOut) { |
| 354 | mKeyguardFadingOutInProgress = true; |
| 355 | } |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 356 | if (mSkipFirstFrame) { |
| 357 | anim.setCurrentPlayTime(16); |
| 358 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 359 | scrim.setTag(TAG_KEY_ANIM, anim); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 360 | scrim.setTag(TAG_KEY_ANIM_TARGET, target); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 363 | private Interpolator getInterpolator() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 364 | return mAnimateKeyguardFadingOut ? KEYGUARD_FADE_OUT_INTERPOLATOR : mInterpolator; |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 367 | @Override |
| 368 | public boolean onPreDraw() { |
| 369 | mScrimBehind.getViewTreeObserver().removeOnPreDrawListener(this); |
| 370 | mUpdatePending = false; |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 371 | if (mDontAnimateBouncerChanges) { |
| 372 | mDontAnimateBouncerChanges = false; |
| 373 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 374 | updateScrims(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 375 | mDurationOverride = -1; |
| 376 | mAnimationDelay = 0; |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 377 | mSkipFirstFrame = false; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 378 | |
| 379 | // Make sure that we always call the listener even if we didn't start an animation. |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 380 | endAnimateKeyguardFadingOut(false /* force */); |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 381 | return true; |
| 382 | } |
| 383 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 384 | private void endAnimateKeyguardFadingOut(boolean force) { |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 385 | mAnimateKeyguardFadingOut = false; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 386 | if ((force || (!isAnimating(mScrimInFront) && !isAnimating(mScrimBehind))) |
| 387 | && mOnAnimationFinished != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 388 | mOnAnimationFinished.run(); |
| 389 | mOnAnimationFinished = null; |
Adrian Roos | 5f72c92 | 2016-03-08 15:54:26 -0800 | [diff] [blame] | 390 | mKeyguardFadingOutInProgress = false; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 391 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 392 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 393 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 394 | private boolean isAnimating(View scrim) { |
| 395 | return scrim.getTag(TAG_KEY_ANIM) != null; |
| 396 | } |
| 397 | |
Selim Cinek | 2550325 | 2016-03-03 15:31:43 -0800 | [diff] [blame] | 398 | public void setDrawBehindAsSrc(boolean asSrc) { |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 399 | mScrimBehind.setDrawAsSrc(asSrc); |
| 400 | } |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 401 | |
| 402 | @Override |
John Spurlock | b349af57 | 2015-04-29 12:24:19 -0400 | [diff] [blame] | 403 | public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | @Override |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 407 | public void onHeadsUpPinned(ExpandableNotificationRow headsUp) { |
| 408 | mPinnedHeadsUpCount++; |
| 409 | updateHeadsUpScrim(true); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) { |
| 414 | mPinnedHeadsUpCount--; |
| 415 | if (headsUp == mDraggedHeadsUpView) { |
| 416 | mDraggedHeadsUpView = null; |
| 417 | mTopHeadsUpDragAmount = 0.0f; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 418 | } |
| 419 | updateHeadsUpScrim(true); |
| 420 | } |
| 421 | |
| 422 | @Override |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 423 | public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | private void updateHeadsUpScrim(boolean animate) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 427 | updateScrim(animate, mHeadsUpScrim, calculateHeadsUpAlpha(), mCurrentHeadsUpAlpha); |
| 428 | } |
| 429 | |
| 430 | private void updateScrim(boolean animate, View scrim, float alpha, float currentAlpha) { |
Adrian Roos | 5f72c92 | 2016-03-08 15:54:26 -0800 | [diff] [blame] | 431 | if (mKeyguardFadingOutInProgress) { |
| 432 | return; |
| 433 | } |
| 434 | |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 435 | ValueAnimator previousAnimator = StackStateAnimator.getChildTag(scrim, |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 436 | TAG_KEY_ANIM); |
| 437 | float animEndValue = -1; |
| 438 | if (previousAnimator != null) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 439 | if (animate || alpha == currentAlpha) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 440 | previousAnimator.cancel(); |
Selim Cinek | 737bff3 | 2015-05-08 16:08:35 -0700 | [diff] [blame] | 441 | } else { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 442 | animEndValue = StackStateAnimator.getChildTag(scrim, TAG_END_ALPHA); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 443 | } |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 444 | } |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 445 | if (alpha != currentAlpha && alpha != animEndValue) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 446 | if (animate) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 447 | startScrimAnimation(scrim, alpha); |
| 448 | scrim.setTag(TAG_START_ALPHA, currentAlpha); |
| 449 | scrim.setTag(TAG_END_ALPHA, alpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 450 | } else { |
| 451 | if (previousAnimator != null) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 452 | float previousStartValue = StackStateAnimator.getChildTag(scrim, |
| 453 | TAG_START_ALPHA); |
| 454 | float previousEndValue = StackStateAnimator.getChildTag(scrim, |
| 455 | TAG_END_ALPHA); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 456 | // we need to increase all animation keyframes of the previous animator by the |
| 457 | // relative change to the end value |
| 458 | PropertyValuesHolder[] values = previousAnimator.getValues(); |
| 459 | float relativeDiff = alpha - previousEndValue; |
| 460 | float newStartValue = previousStartValue + relativeDiff; |
| 461 | values[0].setFloatValues(newStartValue, alpha); |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 462 | scrim.setTag(TAG_START_ALPHA, newStartValue); |
| 463 | scrim.setTag(TAG_END_ALPHA, alpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 464 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 465 | } else { |
| 466 | // update the alpha directly |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 467 | setCurrentScrimAlpha(scrim, alpha); |
| 468 | updateScrimColor(scrim); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 474 | /** |
| 475 | * Set the amount the current top heads up view is dragged. The range is from 0 to 1 and 0 means |
| 476 | * the heads up is in its resting space and 1 means it's fully dragged out. |
| 477 | * |
| 478 | * @param draggedHeadsUpView the dragged view |
| 479 | * @param topHeadsUpDragAmount how far is it dragged |
| 480 | */ |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 481 | public void setTopHeadsUpDragAmount(View draggedHeadsUpView, float topHeadsUpDragAmount) { |
| 482 | mTopHeadsUpDragAmount = topHeadsUpDragAmount; |
| 483 | mDraggedHeadsUpView = draggedHeadsUpView; |
| 484 | updateHeadsUpScrim(false); |
| 485 | } |
| 486 | |
| 487 | private float calculateHeadsUpAlpha() { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 488 | float alpha; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 489 | if (mPinnedHeadsUpCount >= 2) { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 490 | alpha = 1.0f; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 491 | } else if (mPinnedHeadsUpCount == 0) { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 492 | alpha = 0.0f; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 493 | } else { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 494 | alpha = 1.0f - mTopHeadsUpDragAmount; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 495 | } |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 496 | float expandFactor = (1.0f - mFraction); |
| 497 | expandFactor = Math.max(expandFactor, 0.0f); |
| 498 | return alpha * expandFactor; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 499 | } |
Selim Cinek | 37c110f | 2015-05-22 12:38:44 -0700 | [diff] [blame] | 500 | |
| 501 | public void forceHideScrims(boolean hide) { |
| 502 | mForceHideScrims = hide; |
| 503 | mAnimateChange = false; |
| 504 | scheduleUpdate(); |
| 505 | } |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 506 | |
| 507 | public void dontAnimateBouncerChangesUntilNextFrame() { |
| 508 | mDontAnimateBouncerChanges = true; |
| 509 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 510 | |
| 511 | public void setExcludedBackgroundArea(Rect area) { |
| 512 | mScrimBehind.setExcludedArea(area); |
| 513 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 514 | |
| 515 | public int getScrimBehindColor() { |
| 516 | return mScrimBehind.getScrimColorWithAlpha(); |
| 517 | } |
| 518 | |
| 519 | public void setScrimBehindChangeRunnable(Runnable changeRunnable) { |
| 520 | mScrimBehind.setChangeRunnable(changeRunnable); |
| 521 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 522 | } |