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 | |
parent | a7825f8ce6118f5c95ea9944a3bb2a2267710ed3 (diff) | |
download | packages_apps_trebuchet-fe6bd87881e47b9ff38f58bd083042ae0f6a39d7.zip packages_apps_trebuchet-fe6bd87881e47b9ff38f58bd083042ae0f6a39d7.tar.gz packages_apps_trebuchet-fe6bd87881e47b9ff38f58bd083042ae0f6a39d7.tar.bz2 |
Fix some incorrect animation code that might be causing visual glitches.
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r-- | src/com/android/launcher2/CellLayout.java | 17 | ||||
-rw-r--r-- | src/com/android/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 5c1f570..3c6a8aa 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 920aa43..0b2f345 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) { |