Adding animations when dropping on delete / uninstall drop target
-> issue 5043661 Change-Id: I4e4830acc15e006e637b35c3d0dcc72c23414b95
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user