From d4d7aa551ffdc80d810ff970fa72a6509960401e Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Tue, 19 Jul 2011 21:47:37 -0700 Subject: Adding animations when dropping on delete / uninstall drop target -> issue 5043661 Change-Id: I4e4830acc15e006e637b35c3d0dcc72c23414b95 --- .../android/launcher2/AppsCustomizePagedView.java | 3 +- src/com/android/launcher2/ButtonDropTarget.java | 8 ++++- src/com/android/launcher2/DeleteDropTarget.java | 41 ++++++++++++++++++++-- src/com/android/launcher2/InfoDropTarget.java | 1 - src/com/android/launcher2/SearchDropTargetBar.java | 24 +++++++++---- 5 files changed, 66 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index f05946941..c127ecd82 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -449,7 +449,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } private void endDragging(View target, boolean success) { mLauncher.getWorkspace().onDragStopped(success); - if (!success || target != mLauncher.getWorkspace()) { + if (!success || (target != mLauncher.getWorkspace() && + !(target instanceof DeleteDropTarget))) { // Exit spring loaded mode if we have not successfully dropped or have not handled the // drop in Workspace mLauncher.exitSpringLoadedDragMode(); diff --git a/src/com/android/launcher2/ButtonDropTarget.java b/src/com/android/launcher2/ButtonDropTarget.java index edc5acf21..138770a2e 100644 --- a/src/com/android/launcher2/ButtonDropTarget.java +++ b/src/com/android/launcher2/ButtonDropTarget.java @@ -21,6 +21,7 @@ import android.content.res.Resources; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.FrameLayout; +import android.widget.TextView; import com.android.launcher.R; @@ -34,6 +35,8 @@ public class ButtonDropTarget extends FrameLayout implements DropTarget, DragCon protected Launcher mLauncher; private int mBottomDragPadding; + protected TextView mText; + protected SearchDropTargetBar mSearchDropTargetBar; /** Whether this drop target is active for the current drag */ protected boolean mActive; @@ -61,8 +64,11 @@ public class ButtonDropTarget extends FrameLayout implements DropTarget, DragCon return false; } + public void setSearchDropTargetBar(SearchDropTargetBar searchDropTargetBar) { + mSearchDropTargetBar = searchDropTargetBar; + } + public void onDrop(DragObject d) { - // Do nothing } public void onDragEnter(DragObject d) { diff --git a/src/com/android/launcher2/DeleteDropTarget.java b/src/com/android/launcher2/DeleteDropTarget.java index ffe453319..2c84c78e9 100644 --- a/src/com/android/launcher2/DeleteDropTarget.java +++ b/src/com/android/launcher2/DeleteDropTarget.java @@ -22,16 +22,19 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; +import android.graphics.Rect; import android.graphics.drawable.TransitionDrawable; import android.util.AttributeSet; import android.view.View; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.DecelerateInterpolator; import android.widget.TextView; import com.android.launcher.R; public class DeleteDropTarget extends ButtonDropTarget { - private TextView mText; + private static int DELETE_ANIMATION_DURATION = 220; private ColorStateList mOriginalTextColor; private TransitionDrawable mDrawable; private int mHoverColor = 0xFFFF0000; @@ -147,7 +150,37 @@ public class DeleteDropTarget extends ButtonDropTarget { } } - public void onDrop(DragObject d) { + private void animateToTrashAndCompleteDrop(final DragObject d) { + DragLayer dragLayer = mLauncher.getDragLayer(); + Rect from = new Rect(); + Rect to = new Rect(); + dragLayer.getViewRectRelativeToSelf(d.dragView, from); + dragLayer.getViewRectRelativeToSelf(mText, to); + + int width = mDrawable.getIntrinsicWidth(); + int height = mDrawable.getIntrinsicHeight(); + to.set(to.left, to.top, to.left + width, to.bottom); + + // Center the destination rect about the trash icon + int xOffset = (int) -(d.dragView.getMeasuredWidth() - width) / 2; + int yOffset = (int) -(d.dragView.getMeasuredHeight() - height) / 2; + to.offset(xOffset, yOffset); + + mSearchDropTargetBar.deferOnDragEnd(); + Runnable onAnimationEndRunnable = new Runnable() { + @Override + public void run() { + mSearchDropTargetBar.onDragEnd(); + mLauncher.exitSpringLoadedDragMode(); + completeDrop(d); + } + }; + dragLayer.animateView(d.dragView, from, to, 0f, 0.1f, + DELETE_ANIMATION_DURATION, new DecelerateInterpolator(2), + new AccelerateInterpolator(2), onAnimationEndRunnable, false); + } + + private void completeDrop(DragObject d) { ItemInfo item = (ItemInfo) d.dragInfo; if (isAllAppsApplication(d.dragSource, item)) { @@ -178,4 +211,8 @@ public class DeleteDropTarget extends ButtonDropTarget { } } } + + public void onDrop(DragObject d) { + animateToTrashAndCompleteDrop(d); + } } diff --git a/src/com/android/launcher2/InfoDropTarget.java b/src/com/android/launcher2/InfoDropTarget.java index 6ad7630ed..3507181e2 100644 --- a/src/com/android/launcher2/InfoDropTarget.java +++ b/src/com/android/launcher2/InfoDropTarget.java @@ -32,7 +32,6 @@ import com.android.launcher.R; public class InfoDropTarget extends ButtonDropTarget { - private TextView mText; private ColorStateList mOriginalTextColor; private TransitionDrawable mDrawable; private int mHoverColor = 0xFF0000FF; diff --git a/src/com/android/launcher2/SearchDropTargetBar.java b/src/com/android/launcher2/SearchDropTargetBar.java index 201daabc3..ee3ab18fd 100644 --- a/src/com/android/launcher2/SearchDropTargetBar.java +++ b/src/com/android/launcher2/SearchDropTargetBar.java @@ -50,6 +50,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D private ButtonDropTarget mInfoDropTarget; private ButtonDropTarget mDeleteDropTarget; private int mBarHeight; + private boolean mDeferOnDragEnd = false; public SearchDropTargetBar(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -80,6 +81,9 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target); mBarHeight = getResources().getDimensionPixelSize(R.dimen.qsb_bar_height); + mInfoDropTarget.setSearchDropTargetBar(this); + mDeleteDropTarget.setSearchDropTargetBar(this); + boolean enableDropDownDropTargets = getResources().getBoolean(R.bool.config_useDropTargetDownTransition); @@ -191,14 +195,22 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D } } + public void deferOnDragEnd() { + mDeferOnDragEnd = true; + } + @Override public void onDragEnd() { - // Restore the QSB search bar, and animate out the drop target bar - mDropTargetBarFadeInAnim.cancel(); - mDropTargetBarFadeOutAnim.start(); - if (!mIsSearchBarHidden) { - mQSBSearchBarFadeOutAnim.cancel(); - mQSBSearchBarFadeInAnim.start(); + if (!mDeferOnDragEnd) { + // Restore the QSB search bar, and animate out the drop target bar + mDropTargetBarFadeInAnim.cancel(); + mDropTargetBarFadeOutAnim.start(); + if (!mIsSearchBarHidden) { + mQSBSearchBarFadeOutAnim.cancel(); + mQSBSearchBarFadeInAnim.start(); + } + } else { + mDeferOnDragEnd = false; } } } -- cgit v1.2.3