diff options
author | Patrick Dubroy <dubroy@google.com> | 2010-10-13 17:32:10 -0700 |
---|---|---|
committer | Patrick Dubroy <dubroy@google.com> | 2010-10-13 18:13:11 -0700 |
commit | fe6bd87881e47b9ff38f58bd083042ae0f6a39d7 (patch) | |
tree | facc1e0c187a6f9a3df89ca32199690461c58a0e /src/com/android/launcher2/InterruptibleInOutAnimator.java | |
parent | a7825f8ce6118f5c95ea9944a3bb2a2267710ed3 (diff) | |
download | android_packages_apps_Trebuchet-fe6bd87881e47b9ff38f58bd083042ae0f6a39d7.tar.gz android_packages_apps_Trebuchet-fe6bd87881e47b9ff38f58bd083042ae0f6a39d7.tar.bz2 android_packages_apps_Trebuchet-fe6bd87881e47b9ff38f58bd083042ae0f6a39d7.zip |
Fix some incorrect animation code that might be causing visual glitches.
Diffstat (limited to 'src/com/android/launcher2/InterruptibleInOutAnimator.java')
-rw-r--r-- | src/com/android/launcher2/InterruptibleInOutAnimator.java | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/com/android/launcher2/InterruptibleInOutAnimator.java b/src/com/android/launcher2/InterruptibleInOutAnimator.java index 920aa43e4..0b2f34561 100644 --- a/src/com/android/launcher2/InterruptibleInOutAnimator.java +++ b/src/com/android/launcher2/InterruptibleInOutAnimator.java @@ -37,6 +37,12 @@ public class InterruptibleInOutAnimator extends ValueAnimator { private Object mTag = null; + private static final int STOPPED = 0; + private static final int IN = 1; + private static final int OUT = 2; + + private int mDirection = STOPPED; + public InterruptibleInOutAnimator(long duration, Object fromValue, Object toValue) { super(duration, fromValue, toValue); mOriginalDuration = duration; @@ -44,26 +50,49 @@ public class InterruptibleInOutAnimator extends ValueAnimator { mOriginalToValue = toValue; } - private void animateTo(Object toValue) { - // This only makes sense when it's running in the opposite direction, or stopped. - setDuration(mOriginalDuration - getCurrentPlayTime()); - + private void animate(int direction) { + final long currentPlayTime = getCurrentPlayTime(); + final Object toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue; final Object startValue = mFirstRun ? mOriginalFromValue : getAnimatedValue(); + + // Make sure it's stopped before we modify any values cancel(); + if (startValue != toValue) { + mDirection = direction; + setDuration(mOriginalDuration - currentPlayTime); setValues(startValue, toValue); start(); mFirstRun = false; } } + @Override + public void cancel() { + super.cancel(); + mDirection = STOPPED; + } + + @Override + public void end() { + super.end(); + mDirection = STOPPED; + } + + /** + * Return true when the animation is not running and it hasn't even been started. + */ + public boolean isStopped() { + return mDirection == STOPPED; + } + /** * This is the equivalent of calling Animator.start(), except that it can be called when * the animation is running in the opposite direction, in which case we reverse * direction and animate for a correspondingly shorter duration. */ public void animateIn() { - animateTo(mOriginalToValue); + animate(IN); } /** @@ -73,7 +102,7 @@ public class InterruptibleInOutAnimator extends ValueAnimator { * direction and animate for a correspondingly shorter duration. */ public void animateOut() { - animateTo(mOriginalFromValue); + animate(OUT); } public void setTag(Object tag) { |