From fe6bd87881e47b9ff38f58bd083042ae0f6a39d7 Mon Sep 17 00:00:00 2001 From: Patrick Dubroy Date: Wed, 13 Oct 2010 17:32:10 -0700 Subject: Fix some incorrect animation code that might be causing visual glitches. --- src/com/android/launcher2/CellLayout.java | 17 +++++---- .../launcher2/InterruptibleInOutAnimator.java | 41 ++++++++++++++++++---- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 5c1f57052..3c6a8aaed 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -212,6 +212,12 @@ public class CellLayout extends ViewGroup implements Dimmable { // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { + if (false) { + Object val = animation.getAnimatedValue(); + Log.d(TAG, "anim " + thisIndex + " update: " + val + + ", isStopped " + anim.isStopped()); + } + // Try to prevent it from continuing to run animation.cancel(); } else { @@ -1138,15 +1144,14 @@ public class CellLayout extends ViewGroup implements Dimmable { * or it may have begun on another layout. */ void onDragEnter(View dragView) { - if (mDragging) { + if (!mDragging) { // Log.d(TAG, "Received onDragEnter while drag still active"); + // Fade in the drag indicators + if (mCrosshairsAnimator != null) { + mCrosshairsAnimator.animateIn(); + } } mDragging = true; - - // Fade in the drag indicators - if (mCrosshairsAnimator != null) { - mCrosshairsAnimator.animateIn(); - } } /** 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) { -- cgit v1.2.3