OSDN Git Service

Fix bug with views disappearing after dragging.
authorPatrick Dubroy <dubroy@google.com>
Tue, 2 Nov 2010 21:46:20 +0000 (14:46 -0700)
committerPatrick Dubroy <dubroy@google.com>
Tue, 2 Nov 2010 21:51:33 +0000 (14:51 -0700)
src/com/android/launcher2/Workspace.java

index 08e0460..ddf441a 100644 (file)
@@ -1172,28 +1172,29 @@ public class Workspace extends SmoothPagedView
             duration *= mQuintEaseOutInterpolator.getInterpolation(dist / maxDist);
         }
 
-        // Lazy initialize the animation
-        if (mDropAnim == null) {
-            mDropAnim = new ValueAnimator();
-            mDropAnim.setInterpolator(mQuintEaseOutInterpolator);
-
-            // The view is invisible during the animation; we render it manually.
-            mDropAnim.addListener(new AnimatorListenerAdapter() {
-                public void onAnimationStart(Animator animation) {
-                    // Set this here so that we don't render it until the animation begins
-                    mDropView = view;
-                }
+        if (mDropAnim != null) {
+            // This should really be end(), but that will not be called synchronously,
+            // so instead we use LauncherAnimatorListenerAdapter.onAnimationEndOrCancel()
+            // and call cancel() here.
+            mDropAnim.cancel();
+        }
+        mDropAnim = new ValueAnimator();
+        mDropAnim.setInterpolator(mQuintEaseOutInterpolator);
 
-                public void onAnimationEnd(Animator animation) {
-                    if (mDropView != null) {
-                        mDropView.setVisibility(View.VISIBLE);
-                        mDropView = null;
-                    }
+        // The view is invisible during the animation; we render it manually.
+        mDropAnim.addListener(new LauncherAnimatorListenerAdapter() {
+            public void onAnimationStart(Animator animation) {
+                // Set this here so that we don't render it until the animation begins
+                mDropView = view;
+            }
+
+            public void onAnimationEndOrCancel(Animator animation) {
+                if (mDropView != null) {
+                    mDropView.setVisibility(View.VISIBLE);
+                    mDropView = null;
                 }
-            });
-        } else {
-            mDropAnim.end(); // Make sure it's not already running
-        }
+            }
+        });
 
         mDropAnim.setDuration(duration);
         mDropAnim.setFloatValues(0.0f, 1.0f);