Refactor of Launcher drag and drop to use a DragObject

-> DragObject contains a bunch of parameters instead of pssing
   them each individually

Change-Id: I709cf320fe4234d71e19325d5c761dd9a9bba405
This commit is contained in:
Adam Cohen 2011-05-24 14:07:08 -07:00
parent 7d7207f6bc
commit cb3382b1bf
9 changed files with 150 additions and 192 deletions

View File

@ -17,6 +17,7 @@
package com.android.launcher2;
import com.android.launcher.R;
import com.android.launcher2.DropTarget.DragObject;
import android.content.ComponentName;
import android.content.Context;
@ -671,28 +672,16 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
* We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
* to the workspace.
*/
@Override
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public boolean acceptDrop(DragObject d) {
return false;
}
@Override
public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
public DropTarget getDropTargetDelegate(DragObject d) {
return null;
}
@Override
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {}
@Override
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {}
@Override
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {}
@Override
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {}
public void onDragEnter(DragObject d) {}
public void onDragExit(DragObject d) {}
public void onDragOver(DragObject d) {}
public void onDrop(DragObject d) {}
public boolean isDropEnabled() {
return true;

View File

@ -17,6 +17,7 @@
package com.android.launcher2;
import com.android.launcher.R;
import com.android.launcher2.DropTarget.DragObject;
import android.animation.Animator;
import android.animation.AnimatorSet;
@ -61,33 +62,30 @@ public class ApplicationInfoDropTarget extends IconDropTarget {
}
}
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public boolean acceptDrop(DragObject d) {
// acceptDrop is called just before onDrop. We do the work here, rather than
// in onDrop, because it allows us to reject the drop (by returning false)
// so that the object being dragged isn't removed from the home screen.
if (getVisibility() != VISIBLE) return false;
ComponentName componentName = null;
if (dragInfo instanceof ApplicationInfo) {
componentName = ((ApplicationInfo)dragInfo).componentName;
} else if (dragInfo instanceof ShortcutInfo) {
componentName = ((ShortcutInfo)dragInfo).intent.getComponent();
if (d.dragInfo instanceof ApplicationInfo) {
componentName = ((ApplicationInfo) d.dragInfo).componentName;
} else if (d.dragInfo instanceof ShortcutInfo) {
componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
}
mLauncher.startApplicationDetailsActivity(componentName);
return false;
}
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragEnter(DragObject d) {
if (!mDragAndDropEnabled) return;
dragView.setPaint(mHoverPaint);
d.dragView.setPaint(mHoverPaint);
}
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragExit(DragObject d) {
if (!mDragAndDropEnabled) return;
dragView.setPaint(null);
d.dragView.setPaint(null);
}
public void onDragStart(DragSource source, Object info, int dragAction) {

View File

@ -33,6 +33,7 @@ import android.view.View;
import android.view.animation.AccelerateInterpolator;
import com.android.launcher.R;
import com.android.launcher2.DropTarget.DragObject;
public class DeleteZone extends IconDropTarget {
private static final int ORIENTATION_HORIZONTAL = 1;
@ -90,16 +91,14 @@ public class DeleteZone extends IconDropTarget {
mDragTextColor = r.getColor(R.color.workspace_delete_zone_drag_text_color);
}
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public boolean acceptDrop(DragObject d) {
return true;
}
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDrop(DragObject d) {
if (!mDragAndDropEnabled) return;
final ItemInfo item = (ItemInfo) dragInfo;
final ItemInfo item = (ItemInfo) d.dragInfo;
// On x-large screens, you can uninstall an app by dragging from all apps
if (item instanceof ApplicationInfo && LauncherApplication.isScreenLarge()) {
@ -135,21 +134,19 @@ public class DeleteZone extends IconDropTarget {
LauncherModel.deleteItemFromDatabase(mLauncher, item);
}
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragEnter(DragObject d) {
if (mDragAndDropEnabled) {
mTransition.reverseTransition(getTransitionAnimationDuration());
setTextColor(mDragTextColor);
super.onDragEnter(source, x, y, xOffset, yOffset, dragView, dragInfo);
super.onDragEnter(d);
}
}
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragExit(DragObject d) {
if (mDragAndDropEnabled) {
mTransition.reverseTransition(getTransitionAnimationDuration());
setTextColor(mTextColor);
super.onDragExit(source, x, y, xOffset, yOffset, dragView, dragInfo);
super.onDragExit(d);
}
}

View File

@ -35,6 +35,7 @@ import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import com.android.launcher.R;
import com.android.launcher2.DropTarget.DragObject;
/**
* Class for initiating a drag within a view or across multiple views.
@ -84,25 +85,12 @@ public class DragController {
/** Original view that is being dragged. */
private View mOriginator;
/** X offset from the upper-left corner of the cell to where we touched. */
private int mTouchOffsetX;
/** Y offset from the upper-left corner of the cell to where we touched. */
private int mTouchOffsetY;
/** the area at the edge of the screen that makes the workspace go left
* or right while you're dragging.
*/
private int mScrollZone;
/** Where the drag originated */
private DragSource mDragSource;
/** The data associated with the object being dragged */
private Object mDragInfo;
/** The view that moves around while you drag. */
private DragView mDragView;
private DropTarget.DragObject mDragObject = new DropTarget.DragObject();
/** Who can receive drop events */
private ArrayList<DropTarget> mDropTargets = new ArrayList<DropTarget>();
@ -295,17 +283,17 @@ public class DragController {
final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
mTouchOffsetX = mMotionDownX - (screenX + dragRegionLeft);
mTouchOffsetY = mMotionDownY - (screenY + dragRegionTop);
mDragging = true;
mDragSource = source;
mDragInfo = dragInfo;
mDragObject.xOffset = mMotionDownX - (screenX + dragRegionLeft);
mDragObject.yOffset = mMotionDownY - (screenY + dragRegionTop);
mDragObject.dragSource = source;
mDragObject.dragInfo = dragInfo;
mVibrator.vibrate(VIBRATE_DURATION);
DragView dragView = mDragView = new DragView(mContext, b, registrationX, registrationY,
0, 0, b.getWidth(), b.getHeight());
final DragView dragView = mDragObject.dragView = new DragView(mContext, b, registrationX,
registrationY, 0, 0, b.getWidth(), b.getHeight());
final DragSource dragSource = source;
dragView.setOnDrawRunnable(new Runnable() {
@ -386,7 +374,7 @@ public class DragController {
public void cancelDrag() {
if (mDragging) {
// Should we also be calling onDragExit() here?
mDragSource.onDropCompleted(null, mDragInfo, false);
mDragObject.dragSource.onDropCompleted(null, mDragObject.dragInfo, false);
}
endDrag();
}
@ -400,9 +388,9 @@ public class DragController {
for (DragListener listener : mListeners) {
listener.onDragEnd();
}
if (mDragView != null) {
mDragView.remove();
mDragView = null;
if (mDragObject.dragView != null) {
mDragObject.dragView.remove();
mDragObject.dragView = null;
}
}
}
@ -459,33 +447,29 @@ public class DragController {
}
private void handleMoveEvent(int x, int y) {
mDragView.move(x, y);
mDragObject.dragView.move(x, y);
// Drop on someone?
final int[] coordinates = mCoordinatesTemp;
DropTarget dropTarget = findDropTarget(x, y, coordinates);
mDragObject.x = coordinates[0];
mDragObject.y = coordinates[1];
if (dropTarget != null) {
DropTarget delegate = dropTarget.getDropTargetDelegate(
mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
DropTarget delegate = dropTarget.getDropTargetDelegate(mDragObject);
if (delegate != null) {
dropTarget = delegate;
}
if (mLastDropTarget != dropTarget) {
if (mLastDropTarget != null) {
mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
mLastDropTarget.onDragExit(mDragObject);
}
dropTarget.onDragEnter(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
dropTarget.onDragEnter(mDragObject);
}
dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
dropTarget.onDragOver(mDragObject);
} else {
if (mLastDropTarget != null) {
mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
mLastDropTarget.onDragExit(mDragObject);
}
}
mLastDropTarget = dropTarget;
@ -578,18 +562,18 @@ public class DragController {
final int[] coordinates = mCoordinatesTemp;
final DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
mDragObject.x = coordinates[0];
mDragObject.y = coordinates[1];
boolean accepted = false;
if (dropTarget != null) {
dropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
if (dropTarget.acceptDrop(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo)) {
dropTarget.onDrop(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
dropTarget.onDragExit(mDragObject);
if (dropTarget.acceptDrop(mDragObject)) {
dropTarget.onDrop(mDragObject);
accepted = true;
}
}
mDragSource.onDropCompleted((View) dropTarget, mDragInfo, accepted);
mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject.dragInfo, accepted);
}
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
@ -608,9 +592,10 @@ public class DragController {
target.getLocationOnScreen(dropCoordinates);
r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
mDragObject.x = x;
mDragObject.y = y;
if (r.contains(x, y)) {
DropTarget delegate = target.getDropTargetDelegate(mDragSource,
x, y, (int)mTouchOffsetX, (int)mTouchOffsetY, mDragView, mDragInfo);
DropTarget delegate = target.getDropTargetDelegate(mDragObject);
if (delegate != null) {
target = delegate;
target.getLocationOnScreen(dropCoordinates);
@ -701,7 +686,7 @@ public class DragController {
}
DragView getDragView() {
return mDragView;
return mDragObject.dragView;
}
private class ScrollRunnable implements Runnable {

View File

@ -23,6 +23,30 @@ import android.graphics.Rect;
*
*/
public interface DropTarget {
class DragObject {
public int x = -1;
public int y = -1;
/** X offset from the upper-left corner of the cell to where we touched. */
public int xOffset = -1;
/** Y offset from the upper-left corner of the cell to where we touched. */
public int yOffset = -1;
/** The view that moves around while you drag. */
public DragView dragView = null;
/** The data associated with the object being dragged */
public Object dragInfo = null;
/** Where the drag originated */
public DragSource dragSource = null;
public DragObject() {
}
}
/**
* Used to temporarily disable certain drop targets
*
@ -44,17 +68,13 @@ public interface DropTarget {
* @param dragInfo Data associated with the object being dragged
*
*/
void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo);
void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo);
void onDrop(DragObject dragObject);
void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo);
void onDragEnter(DragObject dragObject);
void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo);
void onDragOver(DragObject dragObject);
void onDragExit(DragObject dragObject);
/**
* Allows a DropTarget to delegate drag and drop events to another object.
@ -73,8 +93,7 @@ public interface DropTarget {
*
* @return The DropTarget to delegate to, or null to not delegate to another object.
*/
DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo);
DropTarget getDropTargetDelegate(DragObject dragObject);
/**
* Check if a drop action can occur at, or near, the requested location.
@ -91,8 +110,7 @@ public interface DropTarget {
* @param dragInfo Data associated with the object being dragged
* @return True if the drop will be accepted, false otherwise.
*/
boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo);
boolean acceptDrop(DragObject dragObject);
// These methods are implemented in Views
void getHitRect(Rect outRect);

View File

@ -363,25 +363,23 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
bind(mInfo);
}
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
final ItemInfo item = (ItemInfo) dragInfo;
public boolean acceptDrop(DragObject d) {
final ItemInfo item = (ItemInfo) d.dragInfo;
final int itemType = item.itemType;
return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
!isFull());
}
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDrop(DragObject d) {
ShortcutInfo item;
if (dragInfo instanceof ApplicationInfo) {
if (d.dragInfo instanceof ApplicationInfo) {
// Came from all apps -- make a copy
item = ((ApplicationInfo)dragInfo).makeShortcut();
item = ((ApplicationInfo) d.dragInfo).makeShortcut();
item.spanX = 1;
item.spanY = 1;
} else {
item = (ShortcutInfo)dragInfo;
item = (ShortcutInfo) d.dragInfo;
}
mInfo.add(item);
LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
@ -417,19 +415,16 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
}
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragEnter(DragObject d) {
mContent.onDragEnter();
}
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
float[] r = mapPointFromScreenToContent(x, y, null);
public void onDragOver(DragObject d) {
float[] r = mapPointFromScreenToContent(d.x, d.y, null);
mContent.visualizeDropLocation(null, null, (int) r[0], (int) r[1], 1, 1);
}
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragExit(DragObject d) {
mContent.onDragExit();
}
@ -453,8 +448,7 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL
return true;
}
public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public DropTarget getDropTargetDelegate(DragObject d) {
return null;
}

View File

@ -58,8 +58,6 @@ public class FolderIcon extends FrameLayout implements DropTarget, FolderListene
private int mOriginalWidth = -1;
private int mOriginalHeight = -1;
private int mOriginalX = -1;
private int mOriginalY = -1;
private int mFolderLocX;
private int mFolderLocY;
@ -121,9 +119,8 @@ public class FolderIcon extends FrameLayout implements DropTarget, FolderListene
!mFolder.isFull() && item != mInfo);
}
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
final ItemInfo item = (ItemInfo) dragInfo;
public boolean acceptDrop(DragObject d) {
final ItemInfo item = (ItemInfo) d.dragInfo;
return willAcceptItem(item);
}
@ -132,14 +129,13 @@ public class FolderIcon extends FrameLayout implements DropTarget, FolderListene
LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
}
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDrop(DragObject d) {
ShortcutInfo item;
if (dragInfo instanceof ApplicationInfo) {
if (d.dragInfo instanceof ApplicationInfo) {
// Came from all apps -- make a copy
item = ((ApplicationInfo)dragInfo).makeShortcut();
item = ((ApplicationInfo) d.dragInfo).makeShortcut();
} else {
item = (ShortcutInfo)dragInfo;
item = (ShortcutInfo) d.dragInfo;
}
item.cellX = -1;
item.cellY = -1;
@ -149,8 +145,6 @@ public class FolderIcon extends FrameLayout implements DropTarget, FolderListene
void saveState(CellLayout.LayoutParams lp) {
mOriginalWidth = lp.width;
mOriginalHeight = lp.height;
mOriginalX = lp.x;
mOriginalY = lp.y;
}
private void animateToAcceptState() {
@ -213,27 +207,22 @@ public class FolderIcon extends FrameLayout implements DropTarget, FolderListene
mFolderLocY = tvLocation[1] - wsLocation[1] + getMeasuredHeight() / 2;
}
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
if (!willAcceptItem((ItemInfo) dragInfo)) return;
public void onDragEnter(DragObject d) {
if (!willAcceptItem((ItemInfo) d.dragInfo)) return;
determineFolderLocationInWorkspace();
mLauncher.getWorkspace().showFolderAccept(this);
animateToAcceptState();
}
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragOver(DragObject d) {
}
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
if (!willAcceptItem((ItemInfo) dragInfo)) return;
public void onDragExit(DragObject d) {
if (!willAcceptItem((ItemInfo) d.dragInfo)) return;
animateToNaturalState();
}
@Override
public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public DropTarget getDropTargetDelegate(DragObject d) {
return null;
}

View File

@ -82,32 +82,27 @@ public class IconDropTarget extends TextView implements DropTarget, DragControll
mDragAndDropEnabled = enabled;
}
public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public boolean acceptDrop(DragObject d) {
return false;
}
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDrop(DragObject d) {
// Do nothing
}
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragEnter(DragObject d) {
if (mDragAndDropEnabled) {
dragView.setPaint(mHoverPaint);
d.dragView.setPaint(mHoverPaint);
}
}
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragOver(DragObject d) {
// Do nothing
}
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragExit(DragObject d) {
if (mDragAndDropEnabled) {
dragView.setPaint(null);
d.dragView.setPaint(null);
}
}
@ -135,8 +130,7 @@ public class IconDropTarget extends TextView implements DropTarget, DragControll
}
@Override
public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
public DropTarget getDropTargetDelegate(DragObject d) {
return null;
}
}

View File

@ -2379,11 +2379,10 @@ public class Workspace extends SmoothPagedView
/**
* {@inheritDoc}
*/
public boolean acceptDrop(DragSource source, int x, int y,
int xOffset, int yOffset, DragView dragView, Object dragInfo) {
public boolean acceptDrop(DragObject d) {
// If it's an external drop (e.g. from All Apps), check if it should be accepted
if (source != this) {
if (d.dragSource != this) {
// Don't accept the drop if we're not over a screen at time of drop
if (mDragTargetLayout == null || !mDragTargetLayout.getAcceptsDrops()) {
return false;
@ -2469,10 +2468,9 @@ public class Workspace extends SmoothPagedView
return false;
}
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDrop(DragObject d) {
mDragViewVisualCenter = getDragViewVisualCenter(x, y, xOffset, yOffset, dragView,
mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView,
mDragViewVisualCenter);
// We want the point to be mapped to the dragTarget.
@ -2489,17 +2487,17 @@ public class Workspace extends SmoothPagedView
}
}
if (source != this) {
if (d.dragSource != this) {
final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1] };
if (LauncherApplication.isScreenLarge() && (mIsSmall || mIsInUnshrinkAnimation)
&& !mLauncher.isAllAppsVisible()) {
// When the workspace is shrunk and the drop comes from customize, don't actually
// add the item to the screen -- customize will do this itself
((ItemInfo) dragInfo).dropPos = touchXY;
((ItemInfo) d.dragInfo).dropPos = touchXY;
return;
}
onDropExternal(touchXY, dragInfo, mDragTargetLayout, false, dragView);
onDropExternal(touchXY, d.dragInfo, mDragTargetLayout, false, d.dragView);
} else if (mDragInfo != null) {
final View cell = mDragInfo.cell;
CellLayout dropTargetLayout = mDragTargetLayout;
@ -2592,11 +2590,11 @@ public class Workspace extends SmoothPagedView
final CellLayout parent = (CellLayout) cell.getParent().getParent();
int loc[] = new int[2];
getViewLocationRelativeToSelf(dragView, loc);
getViewLocationRelativeToSelf(d.dragView, loc);
// Prepare it to be animated into its new position
// This must be called after the view has been re-parented
setPositionForDropAnimation(dragView, loc[0], loc[1], parent, cell);
setPositionForDropAnimation(d.dragView, loc[0], loc[1], parent, cell);
boolean animateDrop = !mWasSpringLoadedOnDragExit;
parent.onDropChild(cell, animateDrop);
}
@ -2615,8 +2613,7 @@ public class Workspace extends SmoothPagedView
location[1] = vY - y;
}
public void onDragEnter(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
public void onDragEnter(DragObject d) {
mDragTargetLayout = null; // Reset the drag state
if (!mIsSmall) {
@ -2626,8 +2623,7 @@ public class Workspace extends SmoothPagedView
}
}
public DropTarget getDropTargetDelegate(DragSource source, int x, int y,
int xOffset, int yOffset, DragView dragView, Object dragInfo) {
public DropTarget getDropTargetDelegate(DragObject d) {
if (mIsSmall || mIsInUnshrinkAnimation) {
// If we're shrunken, don't let anyone drag on folders/etc that are on the mini-screens
@ -2637,18 +2633,18 @@ public class Workspace extends SmoothPagedView
// would land in a cell occupied by a DragTarget (e.g. a Folder),
// then drag events should be handled by that child.
ItemInfo item = (ItemInfo) dragInfo;
ItemInfo item = (ItemInfo) d.dragInfo;
CellLayout currentLayout = getCurrentDropLayout();
int dragPointX, dragPointY;
if (item.spanX == 1 && item.spanY == 1) {
// For a 1x1, calculate the drop cell exactly as in onDragOver
dragPointX = x - xOffset;
dragPointY = y - yOffset;
dragPointX = d.x - d.xOffset;
dragPointY = d.y - d.yOffset;
} else {
// Otherwise, use the exact drag coordinates
dragPointX = x;
dragPointY = y;
dragPointX = d.x;
dragPointY = d.y;
}
dragPointX += mScrollX - currentLayout.getLeft();
dragPointY += mScrollY - currentLayout.getTop();
@ -2660,7 +2656,7 @@ public class Workspace extends SmoothPagedView
View child = currentLayout.getChildAt(cellXY[0], cellXY[1]);
if (child instanceof DropTarget) {
DropTarget target = (DropTarget)child;
if (target.acceptDrop(source, x, y, xOffset, yOffset, dragView, dragInfo)) {
if (target.acceptDrop(d)) {
return target;
}
}
@ -2977,25 +2973,24 @@ public class Workspace extends SmoothPagedView
return res;
}
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
public void onDragOver(DragObject d) {
// When touch is inside the scroll area, skip dragOver actions for the current screen
if (!mInScrollArea) {
CellLayout layout;
int left = x - xOffset;
int top = y - yOffset;
int left = d.x - d.xOffset;
int top = d.y - d.yOffset;
mDragViewVisualCenter = getDragViewVisualCenter(x, y, xOffset, yOffset, dragView,
mDragViewVisualCenter);
mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset,
d.dragView, mDragViewVisualCenter);
boolean shrunken = mIsSmall || mIsInUnshrinkAnimation;
if (shrunken) {
mLastDragView = dragView;
mLastDragView = d.dragView;
mLastDragOriginX = left;
mLastDragOriginY = top;
mLastDragXOffset = xOffset;
mLastDragYOffset = yOffset;
layout = findMatchingPageForDragOver(dragView, left, top, xOffset, yOffset);
mLastDragXOffset = d.xOffset;
mLastDragYOffset = d.yOffset;
layout = findMatchingPageForDragOver(d.dragView, left, top, d.xOffset, d.yOffset);
if (layout != null && layout != mDragTargetLayout) {
if (mDragTargetLayout != null) {
@ -3033,9 +3028,9 @@ public class Workspace extends SmoothPagedView
if (!shrunken || mShrinkState == ShrinkState.SPRING_LOADED) {
layout = getCurrentDropLayout();
final ItemInfo item = (ItemInfo)dragInfo;
if (dragInfo instanceof LauncherAppWidgetInfo) {
LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo)dragInfo;
final ItemInfo item = (ItemInfo) d.dragInfo;
if (d.dragInfo instanceof LauncherAppWidgetInfo) {
LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) d.dragInfo;
if (widgetInfo.spanX == -1) {
// Calculate the grid spans needed to fit this widget
@ -3050,7 +3045,7 @@ public class Workspace extends SmoothPagedView
final View child = (mDragInfo == null) ? null : mDragInfo.cell;
// We want the point to be mapped to the dragTarget.
mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null);
ItemInfo info = (ItemInfo) dragInfo;
ItemInfo info = (ItemInfo) d.dragInfo;
if (!willCreateUserFolder(info, mDragTargetLayout,
(int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1])) {
@ -3082,8 +3077,7 @@ public class Workspace extends SmoothPagedView
clearAllHovers();
}
public void onDragExit(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
public void onDragExit(DragObject d) {
doDragExit();
}