diff options
author | Alan Viverette <alanv@google.com> | 2014-05-01 17:20:55 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-05-01 17:20:55 -0700 |
commit | de399397947c5379c61a1003c017b96accbbf545 (patch) | |
tree | 70da7acdd28090845dfae6af772034952a947521 /graphics | |
parent | edfb6b6b747e09334c102bff7cb2c4f8a8c86129 (diff) | |
download | frameworks_base-de399397947c5379c61a1003c017b96accbbf545.zip frameworks_base-de399397947c5379c61a1003c017b96accbbf545.tar.gz frameworks_base-de399397947c5379c61a1003c017b96accbbf545.tar.bz2 |
Support for list selector ripple during arrow movement & drag
BUG: 14231774
BUG: 14230395
Change-Id: I23efbc88c3f05b3f323e47bcb34f55ff70ad6828
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/drawable/Ripple.java | 142 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java | 13 |
2 files changed, 89 insertions, 66 deletions
diff --git a/graphics/java/android/graphics/drawable/Ripple.java b/graphics/java/android/graphics/drawable/Ripple.java index 207834a..3446000 100644 --- a/graphics/java/android/graphics/drawable/Ripple.java +++ b/graphics/java/android/graphics/drawable/Ripple.java @@ -18,6 +18,7 @@ package android.graphics.drawable; import android.animation.Animator; import android.animation.Animator.AnimatorListener; +import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.graphics.Canvas; @@ -85,8 +86,9 @@ class Ripple { /** Configured maximum ripple radius. */ private final int mMaxInsideRadius; - private ObjectAnimator mEnter; - private ObjectAnimator mExit; + private ObjectAnimator mOuter; + private ObjectAnimator mInner; + private ObjectAnimator mAlpha; /** Maximum ripple radius. */ private int mMaxRadius; @@ -267,28 +269,46 @@ class Ripple { public void exit() { mExitFinished = false; - final ObjectAnimator exit = ObjectAnimator.ofFloat(this, "innerRadius", 0, mMaxRadius); - exit.setAutoCancel(true); - exit.setDuration(EXIT_DURATION); - exit.setInterpolator(INTERPOLATOR); - exit.addListener(mAnimationListener); + final ObjectAnimator inner = ObjectAnimator.ofFloat(this, "innerRadius", 0, mMaxRadius); + inner.setAutoCancel(true); + inner.setDuration(EXIT_DURATION); + inner.setInterpolator(INTERPOLATOR); + inner.addListener(mAnimationListener); - if (mEnter != null && mEnter.isStarted()) { + if (mOuter != null && mOuter.isStarted()) { // If we haven't been running the enter animation for long enough, // delay the exit animator. - final int elapsed = (int) (mEnter.getAnimatedFraction() * mEnter.getDuration()); + final int elapsed = (int) (mOuter.getAnimatedFraction() * mOuter.getDuration()); final int delay = Math.max(0, EXIT_MIN_DELAY - elapsed); - exit.setStartDelay(delay); + inner.setStartDelay(delay); } - exit.start(); + inner.start(); - final ObjectAnimator fade = ObjectAnimator.ofFloat(this, "alphaMultiplier", 0); - fade.setAutoCancel(true); - fade.setDuration(EXIT_DURATION); - fade.start(); + final ObjectAnimator alpha = ObjectAnimator.ofFloat(this, "alphaMultiplier", 0); + alpha.setAutoCancel(true); + alpha.setDuration(EXIT_DURATION); + alpha.start(); - mExit = exit; + mInner = inner; + mAlpha = alpha; + } + + /** + * Cancel all animations. + */ + public void cancel() { + if (mInner != null) { + mInner.end(); + } + + if (mOuter != null) { + mOuter.cancel(); + } + + if (mAlpha != null) { + mAlpha.end(); + } } private void invalidateSelf() { @@ -299,47 +319,55 @@ class Ripple { * Starts the enter animation. */ private void enter() { - final ObjectAnimator enter = ObjectAnimator.ofFloat(this, "outerRadius", mMaxRadius); - enter.setAutoCancel(true); - enter.setDuration(ENTER_DURATION); - enter.setInterpolator(INTERPOLATOR); - enter.start(); - - final ObjectAnimator fade = ObjectAnimator.ofFloat(this, "alphaMultiplier", 1); - fade.setAutoCancel(true); - fade.setDuration(FADE_DURATION); - fade.start(); - - // TODO: Starting with a delay will still cancel the fade in. - if (false && mPulseEnabled) { - final ObjectAnimator pulse = ObjectAnimator.ofFloat( - this, "alphaMultiplier", 1, PULSE_MIN_ALPHA); - pulse.setAutoCancel(true); - pulse.setDuration(PULSE_DURATION + PULSE_INTERVAL); - pulse.setRepeatCount(ObjectAnimator.INFINITE); - pulse.setRepeatMode(ObjectAnimator.REVERSE); - pulse.setStartDelay(PULSE_DELAY); - pulse.start(); + final ObjectAnimator outer = ObjectAnimator.ofFloat(this, "outerRadius", mMaxRadius); + outer.setAutoCancel(true); + outer.setDuration(ENTER_DURATION); + outer.setInterpolator(INTERPOLATOR); + outer.start(); + + final ObjectAnimator alpha = ObjectAnimator.ofFloat(this, "alphaMultiplier", 1); + if (mPulseEnabled) { + alpha.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + final ObjectAnimator pulse = ObjectAnimator.ofFloat( + this, "alphaMultiplier", 1, PULSE_MIN_ALPHA); + pulse.setAutoCancel(true); + pulse.setDuration(PULSE_DURATION + PULSE_INTERVAL); + pulse.setRepeatCount(ObjectAnimator.INFINITE); + pulse.setRepeatMode(ObjectAnimator.REVERSE); + pulse.setStartDelay(PULSE_DELAY); + pulse.start(); + + mAlpha = pulse; + } + }); } + alpha.setAutoCancel(true); + alpha.setDuration(FADE_DURATION); + alpha.start(); - mEnter = enter; + mOuter = outer; + mAlpha = alpha; } /** * Starts the outside transition animation. */ private void outside() { - final float targetRadius = mMaxOutsideRadius; - final ObjectAnimator outside = ObjectAnimator.ofFloat(this, "outerRadius", targetRadius); - outside.setAutoCancel(true); - outside.setDuration(OUTSIDE_DURATION); - outside.setInterpolator(INTERPOLATOR); - outside.start(); - - final ObjectAnimator fade = ObjectAnimator.ofFloat(this, "alphaMultiplier", 1); - fade.setAutoCancel(true); - fade.setDuration(FADE_DURATION); - fade.start(); + final ObjectAnimator outer = ObjectAnimator.ofFloat(this, "outerRadius", mMaxOutsideRadius); + outer.setAutoCancel(true); + outer.setDuration(OUTSIDE_DURATION); + outer.setInterpolator(INTERPOLATOR); + outer.start(); + + final ObjectAnimator alpha = ObjectAnimator.ofFloat(this, "alphaMultiplier", 1); + alpha.setAutoCancel(true); + alpha.setDuration(FADE_DURATION); + alpha.start(); + + mOuter = outer; + mAlpha = alpha; } /** @@ -358,27 +386,15 @@ class Ripple { } } - private final AnimatorListener mAnimationListener = new AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - } - - @Override - public void onAnimationRepeat(Animator animation) { - } - + private final AnimatorListener mAnimationListener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { - if (animation == mExit) { + if (animation == mInner) { mExitFinished = true; mOuterRadius = 0; mInnerRadius = 0; mAlphaMultiplier = 1; } } - - @Override - public void onAnimationCancel(Animator animation) { - } }; } diff --git a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java b/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java index 9000e5a..0097183 100644 --- a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java +++ b/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java @@ -380,11 +380,18 @@ public class TouchFeedbackDrawable extends LayerDrawable { @Override public void clearHotspots() { - if (mRipples == null) { - return; + if (mRipples != null) { + mRipples.clear(); + } + + final int count = mAnimatingRipplesCount; + final Ripple[] ripples = mAnimatingRipples; + for (int i = 0; i < count; i++) { + ripples[i].cancel(); + ripples[i] = null; } - mRipples.clear(); + mAnimatingRipplesCount = 0; invalidateSelf(); } |