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; |
| 21 | import android.animation.ValueAnimator; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 23 | import android.graphics.Color; |
| 24 | import android.graphics.drawable.ColorDrawable; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 25 | import android.util.Log; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 26 | import android.view.View; |
| 27 | import android.view.ViewTreeObserver; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 28 | import android.view.animation.AnimationUtils; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 29 | import android.view.animation.DecelerateInterpolator; |
| 30 | import android.view.animation.Interpolator; |
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; |
| 33 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 34 | /** |
| 35 | * Controls both the scrim behind the notifications and in front of the notifications (when a |
| 36 | * security method gets shown). |
| 37 | */ |
| 38 | public class ScrimController implements ViewTreeObserver.OnPreDrawListener { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 39 | private static final String TAG = "ScrimController"; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 40 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 41 | |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 42 | public static final long ANIMATION_DURATION = 220; |
| 43 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 44 | private static final float SCRIM_BEHIND_ALPHA = 0.62f; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 45 | private static final float SCRIM_BEHIND_ALPHA_KEYGUARD = 0.55f; |
| 46 | private static final float SCRIM_BEHIND_ALPHA_UNLOCKING = 0.2f; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 47 | private static final float SCRIM_IN_FRONT_ALPHA = 0.75f; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 48 | private static final int TAG_KEY_ANIM = R.id.scrim; |
| 49 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 50 | private final View mScrimBehind; |
| 51 | private final View mScrimInFront; |
| 52 | private final UnlockMethodCache mUnlockMethodCache; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 53 | private final DozeParameters mDozeParameters; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 54 | |
| 55 | private boolean mKeyguardShowing; |
| 56 | private float mFraction; |
| 57 | |
| 58 | private boolean mDarkenWhileDragging; |
| 59 | private boolean mBouncerShowing; |
| 60 | private boolean mAnimateChange; |
| 61 | private boolean mUpdatePending; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 62 | private boolean mExpanding; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 63 | private boolean mAnimateKeyguardFadingOut; |
| 64 | private long mDurationOverride = -1; |
| 65 | private long mAnimationDelay; |
| 66 | private Runnable mOnAnimationFinished; |
| 67 | private boolean mAnimationStarted; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 68 | private boolean mDozing; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 69 | private long mPulseEndTime; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 70 | private final Interpolator mInterpolator = new DecelerateInterpolator(); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 71 | private final Interpolator mLinearOutSlowInInterpolator; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 72 | |
| 73 | public ScrimController(View scrimBehind, View scrimInFront) { |
| 74 | mScrimBehind = scrimBehind; |
| 75 | mScrimInFront = scrimInFront; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 76 | final Context context = scrimBehind.getContext(); |
| 77 | mUnlockMethodCache = UnlockMethodCache.getInstance(context); |
| 78 | mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 79 | android.R.interpolator.linear_out_slow_in); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 80 | mDozeParameters = new DozeParameters(context); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | public void setKeyguardShowing(boolean showing) { |
| 84 | mKeyguardShowing = showing; |
| 85 | scheduleUpdate(); |
| 86 | } |
| 87 | |
| 88 | public void onTrackingStarted() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 89 | mExpanding = true; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 90 | mDarkenWhileDragging = !mUnlockMethodCache.isMethodInsecure(); |
| 91 | } |
| 92 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 93 | public void onExpandingFinished() { |
| 94 | mExpanding = false; |
| 95 | } |
| 96 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 97 | public void setPanelExpansion(float fraction) { |
Jorim Jaggi | 93439da | 2014-06-30 23:53:39 +0200 | [diff] [blame] | 98 | if (mFraction != fraction) { |
| 99 | mFraction = fraction; |
| 100 | scheduleUpdate(); |
| 101 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | public void setBouncerShowing(boolean showing) { |
| 105 | mBouncerShowing = showing; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 106 | mAnimateChange = !mExpanding; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 107 | scheduleUpdate(); |
| 108 | } |
| 109 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 110 | public void animateKeyguardFadingOut(long delay, long duration, Runnable onAnimationFinished) { |
| 111 | mAnimateKeyguardFadingOut = true; |
| 112 | mDurationOverride = duration; |
| 113 | mAnimationDelay = delay; |
| 114 | mAnimateChange = true; |
| 115 | mOnAnimationFinished = onAnimationFinished; |
| 116 | scheduleUpdate(); |
| 117 | } |
| 118 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 119 | public void animateGoingToFullShade(long delay, long duration) { |
| 120 | mDurationOverride = duration; |
| 121 | mAnimationDelay = delay; |
| 122 | mAnimateChange = true; |
| 123 | scheduleUpdate(); |
| 124 | } |
| 125 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 126 | public void setDozing(boolean dozing) { |
| 127 | if (mDozing == dozing) return; |
| 128 | mDozing = dozing; |
| 129 | if (!mDozing) { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 130 | cancelPulsing(); |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 131 | mAnimateChange = true; |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame^] | 132 | } else { |
| 133 | mAnimateChange = false; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 134 | } |
| 135 | scheduleUpdate(); |
| 136 | } |
| 137 | |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 138 | /** When dozing, fade screen contents in and out using the front scrim. */ |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame^] | 139 | public long pulse() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 140 | if (!mDozing) return 0; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 141 | final long now = System.currentTimeMillis(); |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame^] | 142 | if (DEBUG) Log.d(TAG, "pulse mPulseEndTime=" + mPulseEndTime + " now=" + now); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 143 | if (mPulseEndTime != 0 && mPulseEndTime > now) return mPulseEndTime - now; |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame^] | 144 | mScrimInFront.post(mPulseIn); |
| 145 | mPulseEndTime = now + mDozeParameters.getPulseDuration(); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 146 | return mPulseEndTime - now; |
| 147 | } |
| 148 | |
| 149 | public boolean isPulsing() { |
| 150 | return mDozing && mPulseEndTime != 0; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 151 | } |
| 152 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 153 | private void cancelPulsing() { |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 154 | if (DEBUG) Log.d(TAG, "Cancel pulsing"); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 155 | mScrimInFront.removeCallbacks(mPulseIn); |
| 156 | mScrimInFront.removeCallbacks(mPulseOut); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 157 | mPulseEndTime = 0; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 158 | } |
| 159 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 160 | private void scheduleUpdate() { |
| 161 | if (mUpdatePending) return; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 162 | |
| 163 | // Make sure that a frame gets scheduled. |
| 164 | mScrimBehind.invalidate(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 165 | mScrimBehind.getViewTreeObserver().addOnPreDrawListener(this); |
| 166 | mUpdatePending = true; |
| 167 | } |
| 168 | |
| 169 | private void updateScrims() { |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 170 | if (mAnimateKeyguardFadingOut) { |
| 171 | setScrimInFrontColor(0f); |
| 172 | setScrimBehindColor(0f); |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 173 | } else if (!mKeyguardShowing && !mBouncerShowing) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 174 | updateScrimNormal(); |
| 175 | setScrimInFrontColor(0); |
| 176 | } else { |
| 177 | updateScrimKeyguard(); |
| 178 | } |
| 179 | mAnimateChange = false; |
| 180 | } |
| 181 | |
| 182 | private void updateScrimKeyguard() { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 183 | if (mExpanding && mDarkenWhileDragging) { |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 184 | float behindFraction = Math.max(0, Math.min(mFraction, 1)); |
| 185 | float fraction = 1 - behindFraction; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 186 | fraction = (float) Math.pow(fraction, 0.8f); |
| 187 | behindFraction = (float) Math.pow(behindFraction, 0.8f); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 188 | setScrimInFrontColor(fraction * SCRIM_IN_FRONT_ALPHA); |
| 189 | setScrimBehindColor(behindFraction * SCRIM_BEHIND_ALPHA_KEYGUARD); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 190 | } else if (mBouncerShowing) { |
| 191 | setScrimInFrontColor(SCRIM_IN_FRONT_ALPHA); |
| 192 | setScrimBehindColor(0f); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 193 | } else if (mDozing) { |
| 194 | setScrimInFrontColor(1); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 195 | } else { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 196 | float fraction = Math.max(0, Math.min(mFraction, 1)); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 197 | setScrimInFrontColor(0f); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 198 | setScrimBehindColor(fraction |
| 199 | * (SCRIM_BEHIND_ALPHA_KEYGUARD - SCRIM_BEHIND_ALPHA_UNLOCKING) |
| 200 | + SCRIM_BEHIND_ALPHA_UNLOCKING); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | private void updateScrimNormal() { |
| 205 | float frac = mFraction; |
| 206 | // let's start this 20% of the way down the screen |
| 207 | frac = frac * 1.2f - 0.2f; |
| 208 | if (frac <= 0) { |
| 209 | setScrimBehindColor(0); |
| 210 | } else { |
| 211 | // woo, special effects |
| 212 | final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2f)))); |
| 213 | setScrimBehindColor(k * SCRIM_BEHIND_ALPHA); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | private void setScrimBehindColor(float alpha) { |
| 218 | setScrimColor(mScrimBehind, alpha); |
| 219 | } |
| 220 | |
| 221 | private void setScrimInFrontColor(float alpha) { |
| 222 | setScrimColor(mScrimInFront, alpha); |
| 223 | if (alpha == 0f) { |
| 224 | mScrimInFront.setClickable(false); |
| 225 | } else { |
| 226 | |
John Spurlock | 8b12f22 | 2014-09-09 11:54:11 -0400 | [diff] [blame] | 227 | // Eat touch events (unless dozing). |
| 228 | mScrimInFront.setClickable(!mDozing); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | private void setScrimColor(View scrim, float alpha) { |
| 233 | int color = Color.argb((int) (alpha * 255), 0, 0, 0); |
| 234 | if (mAnimateChange) { |
| 235 | startScrimAnimation(scrim, color); |
| 236 | } else { |
| 237 | scrim.setBackgroundColor(color); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | private void startScrimAnimation(final View scrim, int targetColor) { |
| 242 | int current = getBackgroundAlpha(scrim); |
| 243 | int target = Color.alpha(targetColor); |
| 244 | if (current == targetColor) { |
| 245 | return; |
| 246 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 247 | Object runningAnim = scrim.getTag(TAG_KEY_ANIM); |
| 248 | if (runningAnim instanceof ValueAnimator) { |
| 249 | ((ValueAnimator) runningAnim).cancel(); |
| 250 | } |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 251 | ValueAnimator anim = ValueAnimator.ofInt(current, target); |
| 252 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 253 | @Override |
| 254 | public void onAnimationUpdate(ValueAnimator animation) { |
| 255 | int value = (int) animation.getAnimatedValue(); |
| 256 | scrim.setBackgroundColor(Color.argb(value, 0, 0, 0)); |
| 257 | } |
| 258 | }); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 259 | anim.setInterpolator(mAnimateKeyguardFadingOut |
| 260 | ? mLinearOutSlowInInterpolator |
| 261 | : mInterpolator); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 262 | anim.setStartDelay(mAnimationDelay); |
| 263 | anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION); |
| 264 | anim.addListener(new AnimatorListenerAdapter() { |
| 265 | |
| 266 | @Override |
| 267 | public void onAnimationEnd(Animator animation) { |
| 268 | if (mOnAnimationFinished != null) { |
| 269 | mOnAnimationFinished.run(); |
| 270 | mOnAnimationFinished = null; |
| 271 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 272 | scrim.setTag(TAG_KEY_ANIM, null); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 273 | } |
| 274 | }); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 275 | anim.start(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 276 | scrim.setTag(TAG_KEY_ANIM, anim); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 277 | mAnimationStarted = true; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | private int getBackgroundAlpha(View scrim) { |
| 281 | if (scrim.getBackground() instanceof ColorDrawable) { |
| 282 | ColorDrawable drawable = (ColorDrawable) scrim.getBackground(); |
| 283 | return Color.alpha(drawable.getColor()); |
| 284 | } else { |
| 285 | return 0; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public boolean onPreDraw() { |
| 291 | mScrimBehind.getViewTreeObserver().removeOnPreDrawListener(this); |
| 292 | mUpdatePending = false; |
| 293 | updateScrims(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 294 | mAnimateKeyguardFadingOut = false; |
| 295 | mDurationOverride = -1; |
| 296 | mAnimationDelay = 0; |
| 297 | |
| 298 | // Make sure that we always call the listener even if we didn't start an animation. |
| 299 | if (!mAnimationStarted && mOnAnimationFinished != null) { |
| 300 | mOnAnimationFinished.run(); |
| 301 | mOnAnimationFinished = null; |
| 302 | } |
| 303 | mAnimationStarted = false; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 304 | return true; |
| 305 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 306 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 307 | private final Runnable mPulseIn = new Runnable() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 308 | @Override |
| 309 | public void run() { |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 310 | if (DEBUG) Log.d(TAG, "Pulse in, mDozing=" + mDozing); |
| 311 | if (!mDozing) return; |
| 312 | mDurationOverride = mDozeParameters.getPulseInDuration(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 313 | mAnimationDelay = 0; |
| 314 | mAnimateChange = true; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 315 | mOnAnimationFinished = mPulseInFinished; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 316 | setScrimColor(mScrimInFront, 0); |
| 317 | } |
| 318 | }; |
| 319 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 320 | private final Runnable mPulseInFinished = new Runnable() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 321 | @Override |
| 322 | public void run() { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 323 | if (DEBUG) Log.d(TAG, "Pulse in finished, mDozing=" + mDozing); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 324 | if (!mDozing) return; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 325 | mScrimInFront.postDelayed(mPulseOut, mDozeParameters.getPulseVisibleDuration()); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 326 | } |
| 327 | }; |
| 328 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 329 | private final Runnable mPulseOut = new Runnable() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 330 | @Override |
| 331 | public void run() { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 332 | if (DEBUG) Log.d(TAG, "Pulse out, mDozing=" + mDozing); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 333 | if (!mDozing) return; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 334 | mDurationOverride = mDozeParameters.getPulseOutDuration(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 335 | mAnimationDelay = 0; |
| 336 | mAnimateChange = true; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 337 | mOnAnimationFinished = mPulseOutFinished; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 338 | setScrimColor(mScrimInFront, 1); |
| 339 | } |
| 340 | }; |
| 341 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 342 | private final Runnable mPulseOutFinished = new Runnable() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 343 | @Override |
| 344 | public void run() { |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 345 | if (DEBUG) Log.d(TAG, "Pulse out finished"); |
| 346 | mPulseEndTime = 0; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 347 | } |
| 348 | }; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 349 | } |