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 | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 33 | import com.android.systemui.statusbar.BackDropView; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 34 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
| 35 | import com.android.systemui.statusbar.NotificationData; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 36 | import com.android.systemui.statusbar.ScrimView; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 37 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 38 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 39 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 40 | /** |
| 41 | * Controls both the scrim behind the notifications and in front of the notifications (when a |
| 42 | * security method gets shown). |
| 43 | */ |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 44 | public class ScrimController implements ViewTreeObserver.OnPreDrawListener, |
| 45 | HeadsUpManager.OnHeadsUpChangedListener { |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 46 | public static final long ANIMATION_DURATION = 220; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 47 | public static final Interpolator KEYGUARD_FADE_OUT_INTERPOLATOR |
| 48 | = new PathInterpolator(0f, 0, 0.7f, 1f); |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 49 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 50 | private static final float SCRIM_BEHIND_ALPHA = 0.62f; |
Jorim Jaggi | e571622 | 2015-05-14 14:13:20 -0700 | [diff] [blame] | 51 | private static final float SCRIM_BEHIND_ALPHA_KEYGUARD = 0.45f; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 52 | private static final float SCRIM_BEHIND_ALPHA_UNLOCKING = 0.2f; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 53 | private static final float SCRIM_IN_FRONT_ALPHA = 0.75f; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 54 | private static final int TAG_KEY_ANIM = R.id.scrim; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 55 | private static final int TAG_KEY_ANIM_TARGET = R.id.scrim_target; |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 56 | 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 Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 58 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame^] | 59 | protected final ScrimView mScrimBehind; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 60 | private final ScrimView mScrimInFront; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 61 | private final UnlockMethodCache mUnlockMethodCache; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 62 | private final View mHeadsUpScrim; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 63 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame^] | 64 | protected boolean mKeyguardShowing; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 65 | private float mFraction; |
| 66 | |
| 67 | private boolean mDarkenWhileDragging; |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame^] | 68 | protected boolean mBouncerShowing; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 69 | private boolean mWakeAndUnlocking; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 70 | private boolean mAnimateChange; |
| 71 | private boolean mUpdatePending; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 72 | private boolean mExpanding; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 73 | private boolean mAnimateKeyguardFadingOut; |
| 74 | private long mDurationOverride = -1; |
| 75 | private long mAnimationDelay; |
| 76 | private Runnable mOnAnimationFinished; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 77 | private final Interpolator mInterpolator = new DecelerateInterpolator(); |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 78 | private BackDropView mBackDropView; |
Jorim Jaggi | 0e66439 | 2014-09-27 01:30:22 +0200 | [diff] [blame] | 79 | private boolean mScrimSrcEnabled; |
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; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 92 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 93 | public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront, View headsUpScrim, |
| 94 | boolean scrimSrcEnabled) { |
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); |
Jorim Jaggi | 0e66439 | 2014-09-27 01:30:22 +0200 | [diff] [blame] | 100 | mScrimSrcEnabled = scrimSrcEnabled; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 101 | updateHeadsUpScrim(false); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | public void setKeyguardShowing(boolean showing) { |
| 105 | mKeyguardShowing = showing; |
| 106 | scheduleUpdate(); |
| 107 | } |
| 108 | |
| 109 | public void onTrackingStarted() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 110 | mExpanding = true; |
Selim Cinek | e8bae62 | 2015-07-15 13:24:06 -0700 | [diff] [blame] | 111 | mDarkenWhileDragging = !mUnlockMethodCache.canSkipBouncer(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 114 | public void onExpandingFinished() { |
| 115 | mExpanding = false; |
| 116 | } |
| 117 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 118 | public void setPanelExpansion(float fraction) { |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 119 | if (mFraction != fraction) { |
| 120 | mFraction = fraction; |
| 121 | scheduleUpdate(); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 122 | if (mPinnedHeadsUpCount != 0) { |
| 123 | updateHeadsUpScrim(false); |
| 124 | } |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 125 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | public void setBouncerShowing(boolean showing) { |
| 129 | mBouncerShowing = showing; |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 130 | mAnimateChange = !mExpanding && !mDontAnimateBouncerChanges; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 131 | scheduleUpdate(); |
| 132 | } |
| 133 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 134 | public void setWakeAndUnlocking() { |
| 135 | mWakeAndUnlocking = true; |
| 136 | scheduleUpdate(); |
| 137 | } |
| 138 | |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 139 | public void animateKeyguardFadingOut(long delay, long duration, Runnable onAnimationFinished, |
| 140 | boolean skipFirstFrame) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 141 | mWakeAndUnlocking = false; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 142 | mAnimateKeyguardFadingOut = true; |
| 143 | mDurationOverride = duration; |
| 144 | mAnimationDelay = delay; |
| 145 | mAnimateChange = true; |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 146 | mSkipFirstFrame = skipFirstFrame; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 147 | mOnAnimationFinished = onAnimationFinished; |
| 148 | scheduleUpdate(); |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 149 | |
| 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 Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 155 | public void abortKeyguardFadingOut() { |
| 156 | if (mAnimateKeyguardFadingOut) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 157 | endAnimateKeyguardFadingOut(true /* force */); |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 161 | public void animateGoingToFullShade(long delay, long duration) { |
| 162 | mDurationOverride = duration; |
| 163 | mAnimationDelay = delay; |
| 164 | mAnimateChange = true; |
| 165 | scheduleUpdate(); |
| 166 | } |
| 167 | |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 168 | public void animateNextChange() { |
| 169 | mAnimateChange = true; |
| 170 | } |
| 171 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 172 | public void setDozing(boolean dozing) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 173 | if (mDozing != dozing) { |
| 174 | mDozing = dozing; |
| 175 | scheduleUpdate(); |
| 176 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 177 | } |
| 178 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 179 | public void setDozeInFrontAlpha(float alpha) { |
| 180 | mDozeInFrontAlpha = alpha; |
| 181 | updateScrimColor(mScrimInFront); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 182 | } |
| 183 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 184 | public void setDozeBehindAlpha(float alpha) { |
| 185 | mDozeBehindAlpha = alpha; |
| 186 | updateScrimColor(mScrimBehind); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 189 | public float getDozeBehindAlpha() { |
| 190 | return mDozeBehindAlpha; |
Jeff Brown | 4d69e22 | 2014-09-18 15:27:50 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 193 | public float getDozeInFrontAlpha() { |
| 194 | return mDozeInFrontAlpha; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 197 | private void scheduleUpdate() { |
| 198 | if (mUpdatePending) return; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 199 | |
| 200 | // Make sure that a frame gets scheduled. |
| 201 | mScrimBehind.invalidate(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 202 | mScrimBehind.getViewTreeObserver().addOnPreDrawListener(this); |
| 203 | mUpdatePending = true; |
| 204 | } |
| 205 | |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame^] | 206 | protected void updateScrims() { |
Selim Cinek | 37c110f | 2015-05-22 12:38:44 -0700 | [diff] [blame] | 207 | if (mAnimateKeyguardFadingOut || mForceHideScrims) { |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 208 | setScrimInFrontColor(0f); |
| 209 | setScrimBehindColor(0f); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 210 | } 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 Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 214 | if (mDozing) { |
| 215 | setScrimInFrontColor(0f); |
| 216 | setScrimBehindColor(1f); |
| 217 | } else { |
| 218 | setScrimInFrontColor(1f); |
| 219 | setScrimBehindColor(0f); |
| 220 | } |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 221 | } else if (!mKeyguardShowing && !mBouncerShowing) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 222 | updateScrimNormal(); |
| 223 | setScrimInFrontColor(0); |
| 224 | } else { |
| 225 | updateScrimKeyguard(); |
| 226 | } |
| 227 | mAnimateChange = false; |
| 228 | } |
| 229 | |
| 230 | private void updateScrimKeyguard() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 231 | if (mExpanding && mDarkenWhileDragging) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 232 | float behindFraction = Math.max(0, Math.min(mFraction, 1)); |
| 233 | float fraction = 1 - behindFraction; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 234 | fraction = (float) Math.pow(fraction, 0.8f); |
| 235 | behindFraction = (float) Math.pow(behindFraction, 0.8f); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 236 | setScrimInFrontColor(fraction * SCRIM_IN_FRONT_ALPHA); |
| 237 | setScrimBehindColor(behindFraction * SCRIM_BEHIND_ALPHA_KEYGUARD); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 238 | } else if (mBouncerShowing) { |
| 239 | setScrimInFrontColor(SCRIM_IN_FRONT_ALPHA); |
| 240 | setScrimBehindColor(0f); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 241 | } else { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 242 | float fraction = Math.max(0, Math.min(mFraction, 1)); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 243 | setScrimInFrontColor(0f); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 244 | setScrimBehindColor(fraction |
| 245 | * (SCRIM_BEHIND_ALPHA_KEYGUARD - SCRIM_BEHIND_ALPHA_UNLOCKING) |
| 246 | + SCRIM_BEHIND_ALPHA_UNLOCKING); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 247 | } |
| 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 Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 273 | // Eat touch events (unless dozing). |
| 274 | mScrimInFront.setClickable(!mDozing); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 278 | private void setScrimColor(View scrim, float alpha) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 279 | updateScrim(mAnimateChange, scrim, alpha, getCurrentScrimAlpha(scrim)); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 282 | private float getDozeAlpha(View scrim) { |
| 283 | return scrim == mScrimBehind ? mDozeBehindAlpha : mDozeInFrontAlpha; |
| 284 | } |
| 285 | |
| 286 | private float getCurrentScrimAlpha(View scrim) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 287 | return scrim == mScrimBehind ? mCurrentBehindAlpha |
| 288 | : scrim == mScrimInFront ? mCurrentInFrontAlpha |
| 289 | : mCurrentHeadsUpAlpha; |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | private void setCurrentScrimAlpha(View scrim, float alpha) { |
| 293 | if (scrim == mScrimBehind) { |
| 294 | mCurrentBehindAlpha = alpha; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 295 | } else if (scrim == mScrimInFront) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 296 | mCurrentInFrontAlpha = alpha; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 297 | } else { |
| 298 | alpha = Math.max(0.0f, Math.min(1.0f, alpha)); |
| 299 | mCurrentHeadsUpAlpha = alpha; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 300 | } |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 303 | private void updateScrimColor(View scrim) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 304 | float alpha1 = getCurrentScrimAlpha(scrim); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 305 | 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 Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 314 | private void startScrimAnimation(final View scrim, float target) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 315 | float current = getCurrentScrimAlpha(scrim); |
| 316 | ValueAnimator anim = ValueAnimator.ofFloat(current, target); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 317 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 318 | @Override |
| 319 | public void onAnimationUpdate(ValueAnimator animation) { |
Jorim Jaggi | 048af1f | 2014-11-11 22:51:10 +0100 | [diff] [blame] | 320 | float alpha = (float) animation.getAnimatedValue(); |
| 321 | setCurrentScrimAlpha(scrim, alpha); |
| 322 | updateScrimColor(scrim); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 323 | } |
| 324 | }); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 325 | anim.setInterpolator(getInterpolator()); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 326 | anim.setStartDelay(mAnimationDelay); |
| 327 | anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION); |
| 328 | anim.addListener(new AnimatorListenerAdapter() { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 329 | @Override |
| 330 | public void onAnimationEnd(Animator animation) { |
| 331 | if (mOnAnimationFinished != null) { |
| 332 | mOnAnimationFinished.run(); |
| 333 | mOnAnimationFinished = null; |
| 334 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 335 | scrim.setTag(TAG_KEY_ANIM, null); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 336 | scrim.setTag(TAG_KEY_ANIM_TARGET, null); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 337 | } |
| 338 | }); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 339 | anim.start(); |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 340 | if (mSkipFirstFrame) { |
| 341 | anim.setCurrentPlayTime(16); |
| 342 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 343 | scrim.setTag(TAG_KEY_ANIM, anim); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 344 | scrim.setTag(TAG_KEY_ANIM_TARGET, target); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 347 | private Interpolator getInterpolator() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 348 | return mAnimateKeyguardFadingOut ? KEYGUARD_FADE_OUT_INTERPOLATOR : mInterpolator; |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 349 | } |
| 350 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 351 | @Override |
| 352 | public boolean onPreDraw() { |
| 353 | mScrimBehind.getViewTreeObserver().removeOnPreDrawListener(this); |
| 354 | mUpdatePending = false; |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 355 | if (mDontAnimateBouncerChanges) { |
| 356 | mDontAnimateBouncerChanges = false; |
| 357 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 358 | updateScrims(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 359 | mDurationOverride = -1; |
| 360 | mAnimationDelay = 0; |
Jorim Jaggi | ab45a21 | 2015-08-20 16:59:44 -0700 | [diff] [blame] | 361 | mSkipFirstFrame = false; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 362 | |
| 363 | // 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] | 364 | endAnimateKeyguardFadingOut(false /* force */); |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 365 | return true; |
| 366 | } |
| 367 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 368 | private void endAnimateKeyguardFadingOut(boolean force) { |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 369 | mAnimateKeyguardFadingOut = false; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 370 | if ((force || (!isAnimating(mScrimInFront) && !isAnimating(mScrimBehind))) |
| 371 | && mOnAnimationFinished != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 372 | mOnAnimationFinished.run(); |
| 373 | mOnAnimationFinished = null; |
| 374 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 375 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 376 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 377 | private boolean isAnimating(View scrim) { |
| 378 | return scrim.getTag(TAG_KEY_ANIM) != null; |
| 379 | } |
| 380 | |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 381 | 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 Jaggi | 0e66439 | 2014-09-27 01:30:22 +0200 | [diff] [blame] | 393 | boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE && mScrimSrcEnabled; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 394 | mScrimBehind.setDrawAsSrc(asSrc); |
| 395 | } |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 396 | |
| 397 | @Override |
John Spurlock | b349af57 | 2015-04-29 12:24:19 -0400 | [diff] [blame] | 398 | public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | @Override |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 402 | 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 Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 413 | } |
| 414 | updateHeadsUpScrim(true); |
| 415 | } |
| 416 | |
| 417 | @Override |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 418 | public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | private void updateHeadsUpScrim(boolean animate) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 422 | 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 Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 427 | TAG_KEY_ANIM); |
| 428 | float animEndValue = -1; |
| 429 | if (previousAnimator != null) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 430 | if (animate || alpha == currentAlpha) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 431 | previousAnimator.cancel(); |
Selim Cinek | 737bff3 | 2015-05-08 16:08:35 -0700 | [diff] [blame] | 432 | } else { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 433 | animEndValue = StackStateAnimator.getChildTag(scrim, TAG_END_ALPHA); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 434 | } |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 435 | } |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 436 | if (alpha != currentAlpha && alpha != animEndValue) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 437 | if (animate) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 438 | startScrimAnimation(scrim, alpha); |
| 439 | scrim.setTag(TAG_START_ALPHA, currentAlpha); |
| 440 | scrim.setTag(TAG_END_ALPHA, alpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 441 | } else { |
| 442 | if (previousAnimator != null) { |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 443 | float previousStartValue = StackStateAnimator.getChildTag(scrim, |
| 444 | TAG_START_ALPHA); |
| 445 | float previousEndValue = StackStateAnimator.getChildTag(scrim, |
| 446 | TAG_END_ALPHA); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 447 | // 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 Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 453 | scrim.setTag(TAG_START_ALPHA, newStartValue); |
| 454 | scrim.setTag(TAG_END_ALPHA, alpha); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 455 | previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); |
| 456 | } else { |
| 457 | // update the alpha directly |
Selim Cinek | 5104a6d | 2015-12-18 18:38:31 -0800 | [diff] [blame] | 458 | setCurrentScrimAlpha(scrim, alpha); |
| 459 | updateScrimColor(scrim); |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 465 | /** |
| 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 Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 472 | public void setTopHeadsUpDragAmount(View draggedHeadsUpView, float topHeadsUpDragAmount) { |
| 473 | mTopHeadsUpDragAmount = topHeadsUpDragAmount; |
| 474 | mDraggedHeadsUpView = draggedHeadsUpView; |
| 475 | updateHeadsUpScrim(false); |
| 476 | } |
| 477 | |
| 478 | private float calculateHeadsUpAlpha() { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 479 | float alpha; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 480 | if (mPinnedHeadsUpCount >= 2) { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 481 | alpha = 1.0f; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 482 | } else if (mPinnedHeadsUpCount == 0) { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 483 | alpha = 0.0f; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 484 | } else { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 485 | alpha = 1.0f - mTopHeadsUpDragAmount; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 486 | } |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 487 | float expandFactor = (1.0f - mFraction); |
| 488 | expandFactor = Math.max(expandFactor, 0.0f); |
| 489 | return alpha * expandFactor; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 490 | } |
Selim Cinek | 37c110f | 2015-05-22 12:38:44 -0700 | [diff] [blame] | 491 | |
| 492 | public void forceHideScrims(boolean hide) { |
| 493 | mForceHideScrims = hide; |
| 494 | mAnimateChange = false; |
| 495 | scheduleUpdate(); |
| 496 | } |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 497 | |
| 498 | public void dontAnimateBouncerChangesUntilNextFrame() { |
| 499 | mDontAnimateBouncerChanges = true; |
| 500 | } |
Selim Cinek | 6811d72 | 2016-01-19 17:53:12 -0800 | [diff] [blame] | 501 | |
| 502 | public void setExcludedBackgroundArea(Rect area) { |
| 503 | mScrimBehind.setExcludedArea(area); |
| 504 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 505 | |
| 506 | public int getScrimBehindColor() { |
| 507 | return mScrimBehind.getScrimColorWithAlpha(); |
| 508 | } |
| 509 | |
| 510 | public void setScrimBehindChangeRunnable(Runnable changeRunnable) { |
| 511 | mScrimBehind.setChangeRunnable(changeRunnable); |
| 512 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 513 | } |