summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2016-10-05 09:05:42 -0700
committerTony Wickham <twickham@google.com>2016-11-02 15:07:57 -0700
commitea62fe0be19c54f8fbb434c6334418b96626f70d (patch)
treef9d9c9794f37f8f60e9eb8c1f6ee79e4bb53a005 /src/com/android
parentdf3bc52ca9c4271398d35b17cf550ca9099b8249 (diff)
downloadandroid_packages_apps_Trebuchet-ea62fe0be19c54f8fbb434c6334418b96626f70d.tar.gz
android_packages_apps_Trebuchet-ea62fe0be19c54f8fbb434c6334418b96626f70d.tar.bz2
android_packages_apps_Trebuchet-ea62fe0be19c54f8fbb434c6334418b96626f70d.zip
Animate icons back to where they were picked up.
We do this for pre-dragged icons instead of calling onDrop(). - Removes need for special logic in onDrop() to check if mIsInPreDrag - Dropping from pre-drag in all apps also animates instead of jumping We also do this when dropping an icon while still transitioning to spring-loaded mode, to avoid having a janky jump at the end - Bug: 27135377 Change-Id: I4548c3e2fef3423d1ba36057fb53807b1b4ad0fc
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/launcher3/Workspace.java18
-rw-r--r--src/com/android/launcher3/dragndrop/DragController.java29
-rw-r--r--src/com/android/launcher3/dragndrop/DragView.java16
-rw-r--r--src/com/android/launcher3/folder/Folder.java14
4 files changed, 52 insertions, 25 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 2161e3970..016079de2 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2528,6 +2528,7 @@ public class Workspace extends PagedView
onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d);
} else if (mDragInfo != null) {
final View cell = mDragInfo.cell;
+ boolean droppedOnOriginalCellDuringTransition = false;
if (dropTargetLayout != null && !d.cancelled) {
// Move internally
@@ -2570,6 +2571,10 @@ public class Workspace extends PagedView
minSpanY = item.minSpanY;
}
+ droppedOnOriginalCellDuringTransition = mIsSwitchingState
+ && item.screenId == screenId && item.container == container
+ && item.cellX == mTargetCell[0] && item.cellY == mTargetCell[1];
+
int[] resultSpan = new int[2];
mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell,
@@ -2627,7 +2632,7 @@ public class Workspace extends PagedView
&& !d.accessibleDrag) {
mDelayedResizeRunnable = new Runnable() {
public void run() {
- if (!isPageInTransition() && !mIsSwitchingState) {
+ if (!isPageInTransition()) {
DragLayer dragLayer = mLauncher.getDragLayer();
dragLayer.addResizeFrame(hostView, cellLayout);
}
@@ -2662,6 +2667,17 @@ public class Workspace extends PagedView
};
mAnimatingViewIntoPlace = true;
if (d.dragView.hasDrawn()) {
+ if (droppedOnOriginalCellDuringTransition) {
+ // Animate the item to its original position, while simultaneously exiting
+ // spring-loaded mode so the page meets the icon where it was picked up.
+ mLauncher.getDragController().animateDragViewToOriginalPosition(
+ mDelayedResizeRunnable, cell,
+ mStateTransitionAnimation.mSpringLoadedTransitionTime);
+ mLauncher.exitSpringLoadedDragMode();
+ mLauncher.getDropTargetBar().onDragEnd();
+ parent.onDropChild(cell);
+ return;
+ }
final ItemInfo info = (ItemInfo) cell.getTag();
boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
|| info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index e11bfc682..67ef5fc3c 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -295,10 +295,6 @@ public class DragController implements DragDriver.EventListener, TouchController
mIsInPreDrag = false;
}
- public boolean isInPreDrag() {
- return mIsInPreDrag;
- }
-
/**
* Call this from a drag source view like this:
*
@@ -361,6 +357,8 @@ public class DragController implements DragDriver.EventListener, TouchController
isDeferred = mDragObject.deferDragViewCleanupPostAnimation;
if (!isDeferred) {
mDragObject.dragView.remove();
+ } else if (mIsInPreDrag) {
+ animateDragViewToOriginalPosition(null, null, -1);
}
mDragObject.dragView = null;
}
@@ -374,6 +372,22 @@ public class DragController implements DragDriver.EventListener, TouchController
releaseVelocityTracker();
}
+ public void animateDragViewToOriginalPosition(final Runnable onComplete,
+ final View originalIcon, int duration) {
+ Runnable onCompleteRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if (originalIcon != null) {
+ originalIcon.setVisibility(View.VISIBLE);
+ }
+ if (onComplete != null) {
+ onComplete.run();
+ }
+ }
+ };
+ mDragObject.dragView.animateTo(mMotionDownX, mMotionDownY, onCompleteRunnable, duration);
+ }
+
private void callOnDragEnd() {
if (mIsInPreDrag && mOptions.preDragCondition != null) {
mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/);
@@ -738,7 +752,7 @@ public class DragController implements DragDriver.EventListener, TouchController
if (dropTarget.acceptDrop(mDragObject)) {
if (flingVel != null) {
dropTarget.onFlingToDelete(mDragObject, flingVel);
- } else {
+ } else if (!mIsInPreDrag) {
dropTarget.onDrop(mDragObject);
}
accepted = true;
@@ -749,11 +763,6 @@ public class DragController implements DragDriver.EventListener, TouchController
if (!mIsInPreDrag) {
mDragObject.dragSource.onDropCompleted(
dropTargetAsView, mDragObject, flingVel != null, accepted);
- } else {
- // Only defer the drag view cleanup if the drag source handles the drop.
- if (!(mDragObject.dragSource instanceof DropTarget)) {
- mDragObject.deferDragViewCleanupPostAnimation = false;
- }
}
}
diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java
index 8a2ae94f6..22e077bb1 100644
--- a/src/com/android/launcher3/dragndrop/DragView.java
+++ b/src/com/android/launcher3/dragndrop/DragView.java
@@ -23,7 +23,6 @@ import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
-import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -38,12 +37,10 @@ import android.view.animation.DecelerateInterpolator;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
+import com.android.launcher3.R;
import com.android.launcher3.Utilities;
-import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.Thunk;
-import com.android.launcher3.R;
-
import java.util.Arrays;
public class DragView extends View {
@@ -57,6 +54,8 @@ public class DragView extends View {
@Thunk Paint mPaint;
private final int mRegistrationX;
private final int mRegistrationY;
+ private final float mInitialScale;
+ private final int[] mTempLoc = new int[2];
private Point mDragVisualizeOffset = null;
private Rect mDragRegion = null;
@@ -138,6 +137,8 @@ public class DragView extends View {
mRegistrationX = registrationX;
mRegistrationY = registrationY;
+ mInitialScale = initialScale;
+
// Force a measure, because Workspace uses getMeasuredHeight() before the layout pass
int ms = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
measure(ms, ms);
@@ -356,6 +357,13 @@ public class DragView extends View {
applyTranslation();
}
+ public void animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration) {
+ mTempLoc[0] = toTouchX - mRegistrationX;
+ mTempLoc[1] = toTouchY - mRegistrationY;
+ mDragLayer.animateViewIntoPosition(this, mTempLoc, 1f, mInitialScale, mInitialScale,
+ DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
+ }
+
public void animateShift(final int shiftX, final int shiftY) {
if (mAnim.isStarted()) {
return;
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 2952196fa..53c12b5b1 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -1331,10 +1331,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mIsExternalDrag = false;
} else {
currentDragView = mCurrentDragView;
- // The view was never removed from this folder if we are still in the pre-drag.
- if (!mDragController.isInPreDrag()) {
- mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
- }
+ mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
}
if (d.dragView.hasDrawn()) {
@@ -1355,12 +1352,9 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
mItemsInvalidated = true;
rearrangeChildren();
- // The ShortcutInfo was never removed if we are still in the pre-drag.
- if (!mDragController.isInPreDrag()) {
- // Temporarily suppress the listener, as we did all the work already here.
- try (SuppressInfoChanges s = new SuppressInfoChanges()) {
- mInfo.add(si, false);
- }
+ // Temporarily suppress the listener, as we did all the work already here.
+ try (SuppressInfoChanges s = new SuppressInfoChanges()) {
+ mInfo.add(si, false);
}
// Clear the drag info, as it is no longer being dragged.