From 6441de0ec2a71862798dd51180d0811b42edd514 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Wed, 14 Dec 2011 14:25:32 -0800 Subject: Fixing subtle animation jank when dropping icon on adjacent page -> The old path of the icon wasn't correct from a motion standpoint Change-Id: Icb4b06b5cd5649e983d43953ff369d1d8d8cdee2 --- src/com/android/launcher2/DeleteDropTarget.java | 2 +- src/com/android/launcher2/DragLayer.java | 28 ++++++++++++++++++------- src/com/android/launcher2/Folder.java | 2 +- src/com/android/launcher2/FolderIcon.java | 2 +- src/com/android/launcher2/Workspace.java | 4 +--- 5 files changed, 24 insertions(+), 14 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/launcher2/DeleteDropTarget.java b/src/com/android/launcher2/DeleteDropTarget.java index f19970823..3b82f9e94 100644 --- a/src/com/android/launcher2/DeleteDropTarget.java +++ b/src/com/android/launcher2/DeleteDropTarget.java @@ -193,7 +193,7 @@ public class DeleteDropTarget extends ButtonDropTarget { }; dragLayer.animateView(d.dragView, from, to, 0.1f, 0.1f, DELETE_ANIMATION_DURATION, new DecelerateInterpolator(2), - new DecelerateInterpolator(1.5f), onAnimationEndRunnable, false); + new DecelerateInterpolator(1.5f), onAnimationEndRunnable, false, null); } private void completeDrop(DragObject d) { diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java index 915477119..c315b6018 100644 --- a/src/com/android/launcher2/DragLayer.java +++ b/src/com/android/launcher2/DragLayer.java @@ -63,6 +63,8 @@ public class DragLayer extends FrameLayout { private ValueAnimator mFadeOutAnim = null; private TimeInterpolator mCubicEaseOutInterpolator = new DecelerateInterpolator(1.5f); private View mDropView = null; + private int mAnchorViewInitialScrollX = 0; + private View mAnchorView = null; private int[] mDropViewPos = new int[2]; private float mDropViewScale; @@ -420,16 +422,16 @@ public class DragLayer extends FrameLayout { final int fromY = r.top; animateViewIntoPosition(dragView, fromX, fromY, pos[0], pos[1], scale, - onFinishRunnable, true, -1); + onFinishRunnable, true, -1, null); } public void animateViewIntoPosition(DragView dragView, final View child, final Runnable onFinishAnimationRunnable) { - animateViewIntoPosition(dragView, child, -1, onFinishAnimationRunnable); + animateViewIntoPosition(dragView, child, -1, onFinishAnimationRunnable, null); } public void animateViewIntoPosition(DragView dragView, final View child, int duration, - final Runnable onFinishAnimationRunnable) { + final Runnable onFinishAnimationRunnable, View anchorView) { ((CellLayoutChildren) child.getParent()).measureChild(child); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); @@ -485,16 +487,17 @@ public class DragLayer extends FrameLayout { } }; animateViewIntoPosition(dragView, fromX, fromY, toX, toY, scale, - onCompleteRunnable, true, duration); + onCompleteRunnable, true, duration, anchorView); } private void animateViewIntoPosition(final View view, final int fromX, final int fromY, final int toX, final int toY, float finalScale, Runnable onCompleteRunnable, - boolean fadeOut, int duration) { + boolean fadeOut, int duration, View anchorView) { Rect from = new Rect(fromX, fromY, fromX + view.getMeasuredWidth(), fromY + view.getMeasuredHeight()); Rect to = new Rect(toX, toY, toX + view.getMeasuredWidth(), toY + view.getMeasuredHeight()); - animateView(view, from, to, 1f, finalScale, duration, null, null, onCompleteRunnable, true); + animateView(view, from, to, 1f, finalScale, duration, null, null, + onCompleteRunnable, true, anchorView); } /** @@ -514,11 +517,14 @@ public class DragLayer extends FrameLayout { * @param onCompleteRunnable Optional runnable to run on animation completion. * @param fadeOut Whether or not to fade out the view once the animation completes. If true, * the runnable will execute after the view is faded out. + * @param anchorView If not null, this represents the view which the animated view stays + * anchored to in case scrolling is currently taking place. Note: currently this is + * only used for the X dimension for the case of the workspace. */ public void animateView(final View view, final Rect from, final Rect to, final float finalAlpha, final float finalScale, int duration, final Interpolator motionInterpolator, final Interpolator alphaInterpolator, final Runnable onCompleteRunnable, - final boolean fadeOut) { + final boolean fadeOut, View anchorView) { // Calculate the duration of the animation based on the object's distance final float dist = (float) Math.sqrt(Math.pow(to.left - from.left, 2) + Math.pow(to.top - from.top, 2)); @@ -548,6 +554,11 @@ public class DragLayer extends FrameLayout { mDropAnim.setInterpolator(mCubicEaseOutInterpolator); } + if (anchorView != null) { + mAnchorViewInitialScrollX = anchorView.getScrollX(); + } + mAnchorView = anchorView; + mDropAnim.setDuration(duration); mDropAnim.setFloatValues(0.0f, 1.0f); mDropAnim.removeAllUpdateListeners(); @@ -662,7 +673,8 @@ public class DragLayer extends FrameLayout { // We are animating an item that was just dropped on the home screen. // Render its View in the current animation position. canvas.save(Canvas.MATRIX_SAVE_FLAG); - final int xPos = mDropViewPos[0] - mDropView.getScrollX(); + final int xPos = mDropViewPos[0] - mDropView.getScrollX() + (mAnchorView != null + ? (mAnchorViewInitialScrollX - mAnchorView.getScrollX()) : 0); final int yPos = mDropViewPos[1] - mDropView.getScrollY(); int width = mDropView.getMeasuredWidth(); int height = mDropView.getMeasuredHeight(); diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index 695604454..f5bd7dbbb 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -375,7 +375,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); - + oa.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java index 3c0829d4a..2a711f88b 100644 --- a/src/com/android/launcher2/FolderIcon.java +++ b/src/com/android/launcher2/FolderIcon.java @@ -362,7 +362,7 @@ public class FolderIcon extends LinearLayout implements FolderListener { dragLayer.animateView(animateView, from, to, finalAlpha, scale * scaleRelativeToDragLayer, DROP_IN_ANIMATION_DURATION, new DecelerateInterpolator(2), new AccelerateInterpolator(2), - postAnimationRunnable, false); + postAnimationRunnable, false, null); postDelayed(new Runnable() { public void run() { addItem(item); diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index f3720836a..290637126 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -2287,10 +2287,8 @@ public class Workspace extends SmoothPagedView mAnimatingViewIntoPlace = true; if (d.dragView.hasDrawn()) { int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION; - setFinalScrollForPageChange(snapScreen); mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, - disableHardwareLayersRunnable); - resetFinalScrollForPageChange(snapScreen); + disableHardwareLayersRunnable, this); } else { cell.setVisibility(VISIBLE); } -- cgit v1.2.3