From e7587d2f23f3ab9e133b40cd7fed4b030609f252 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 24 May 2012 18:50:02 -0700 Subject: Fix issue where reorder animations could leave views in translated state Change-Id: I75f590c4ba43fec0550bbd003022d5c8309881a3 --- src/com/android/launcher2/CellLayout.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index c7ad92310..a96b5b168 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -31,7 +31,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Point; -import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; @@ -426,7 +425,7 @@ public class CellLayout extends ViewGroup { if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); - cd.setBounds(0, 0, 80, 80); + cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { @@ -1926,7 +1925,7 @@ public class CellLayout extends ViewGroup { float finalScale; float initScale; private static final int DURATION = 300; - ValueAnimator va; + Animator a; public ReorderHintAnimation(View child, int cellX0, int cellY0, int cellX1, int cellY1, int spanX, int spanY) { @@ -1969,11 +1968,16 @@ public class CellLayout extends ViewGroup { ReorderHintAnimation oldAnimation = mShakeAnimators.get(child); oldAnimation.cancel(); mShakeAnimators.remove(child); + if (finalDeltaX == 0 && finalDeltaY == 0) { + completeAnimationImmediately(); + return; + } } if (finalDeltaX == 0 && finalDeltaY == 0) { return; } - va = ValueAnimator.ofFloat(0f, 1f); + ValueAnimator va = ValueAnimator.ofFloat(0f, 1f); + a = va; va.setRepeatMode(ValueAnimator.REVERSE); va.setRepeatCount(ValueAnimator.INFINITE); va.setDuration(DURATION); @@ -2004,12 +2008,18 @@ public class CellLayout extends ViewGroup { } private void cancel() { - va.cancel(); + if (a != null) { + a.cancel(); + } } + private void completeAnimationImmediately() { - va.cancel(); + if (a != null) { + a.cancel(); + } AnimatorSet s = new AnimatorSet(); + a = s; s.playTogether( ObjectAnimator.ofFloat(child, "scaleX", 1f), ObjectAnimator.ofFloat(child, "scaleY", 1f), -- cgit v1.2.3