summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher/DragLayer.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2009-04-07 21:08:40 -0700
committerJeff Sharkey <jsharkey@android.com>2009-04-08 16:44:27 -0700
commit70864289fba6daf07b8de98524cdfb765a62552d (patch)
tree5660819a8b529322c9c175c54f77be12b070a548 /src/com/android/launcher/DragLayer.java
parentbb760cc21e6e66306a7524ed79454c676a491702 (diff)
downloadandroid_packages_apps_Trebuchet-70864289fba6daf07b8de98524cdfb765a62552d.tar.gz
android_packages_apps_Trebuchet-70864289fba6daf07b8de98524cdfb765a62552d.tar.bz2
android_packages_apps_Trebuchet-70864289fba6daf07b8de98524cdfb765a62552d.zip
Make Launcher more forgiving when dragging desktop items.
This change adds nearby-area searching when dragging desktop items into already-occupied cells. This approach tries harder to find a matching area, instead of strictly rejecting invalid moves. We also draw a "snag" during the drag to show where an item would be dropped, but only if we would drop into an alternative cell. This gives users better feedback about where things will drop. http://b/issue?id=1634887
Diffstat (limited to 'src/com/android/launcher/DragLayer.java')
-rw-r--r--src/com/android/launcher/DragLayer.java84
1 files changed, 80 insertions, 4 deletions
diff --git a/src/com/android/launcher/DragLayer.java b/src/com/android/launcher/DragLayer.java
index b542de62a..b5b84b86e 100644
--- a/src/com/android/launcher/DragLayer.java
+++ b/src/com/android/launcher/DragLayer.java
@@ -113,8 +113,25 @@ public class DragLayer extends FrameLayout implements DragController {
private DropTarget mLastDropTarget;
private final Paint mTrashPaint = new Paint();
+ private final Paint mEstimatedPaint = new Paint();
private Paint mDragPaint;
+ /**
+ * If true, draw a "snag" showing where the object currently being dragged
+ * would end up if dropped from current location.
+ */
+ private static final boolean DRAW_TARGET_SNAG = false;
+
+ private Rect mEstimatedRect = new Rect();
+ private float[] mDragCenter = new float[2];
+ private float[] mEstimatedCenter = new float[2];
+ private boolean mDrawEstimated = false;
+
+ private int mTriggerWidth = -1;
+ private int mTriggerHeight = -1;
+
+ private static final int DISTANCE_DRAW_SNAG = 20;
+
private static final int ANIMATION_STATE_STARTING = 1;
private static final int ANIMATION_STATE_RUNNING = 2;
private static final int ANIMATION_STATE_DONE = 3;
@@ -141,6 +158,13 @@ public class DragLayer extends FrameLayout implements DragController {
final int srcColor = context.getResources().getColor(R.color.delete_color_filter);
mTrashPaint.setColorFilter(new PorterDuffColorFilter(srcColor, PorterDuff.Mode.SRC_ATOP));
+
+ // Make estimated paint area in gray
+ int snagColor = context.getResources().getColor(R.color.snag_callout_color);
+ mEstimatedPaint.setColor(snagColor);
+ mEstimatedPaint.setStrokeWidth(3);
+ mEstimatedPaint.setAntiAlias(true);
+
}
public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
@@ -177,6 +201,9 @@ public class DragLayer extends FrameLayout implements DragController {
int width = viewBitmap.getWidth();
int height = viewBitmap.getHeight();
+ mTriggerWidth = width * 2 / 3;
+ mTriggerHeight = height * 2 / 3;
+
Matrix scale = new Matrix();
float scaleFactor = v.getWidth();
scaleFactor = (scaleFactor + DRAG_SCALE) /scaleFactor;
@@ -252,6 +279,13 @@ public class DragLayer extends FrameLayout implements DragController {
break;
}
} else {
+ // Only draw estimate drop "snag" when requested
+ if (DRAW_TARGET_SNAG && mDrawEstimated) {
+ canvas.drawLine(mDragCenter[0], mDragCenter[1], mEstimatedCenter[0], mEstimatedCenter[1], mEstimatedPaint);
+ canvas.drawCircle(mEstimatedCenter[0], mEstimatedCenter[1], 8, mEstimatedPaint);
+ }
+
+ // Draw actual icon being dragged
canvas.drawBitmap(mDragBitmap,
mScrollX + mLastMotionX - mTouchOffsetX - mBitmapOffsetX,
mScrollY + mLastMotionY - mTouchOffsetY - mBitmapOffsetY, mDragPaint);
@@ -355,8 +389,16 @@ public class DragLayer extends FrameLayout implements DragController {
left = (int) (scrollX + x - touchX - offsetX);
top = (int) (scrollY + y - touchY - offsetY);
+ // Invalidate current icon position
rect.union(left - 1, top - 1, left + width + 1, top + height + 1);
- invalidate(rect);
+
+ mDragCenter[0] = rect.centerX();
+ mDragCenter[1] = rect.centerY();
+
+ // Invalidate any old estimated location
+ if (DRAW_TARGET_SNAG && mDrawEstimated) {
+ rect.union(mEstimatedRect);
+ }
final int[] coordinates = mDropCoordinates;
DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
@@ -378,6 +420,33 @@ public class DragLayer extends FrameLayout implements DragController {
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragInfo);
}
}
+
+ // Render estimated drop "snag" only outside of width
+ mDrawEstimated = false;
+ if (DRAW_TARGET_SNAG && dropTarget != null) {
+ Rect foundEstimate = dropTarget.estimateDropLocation(mDragSource,
+ (int) (scrollX + mLastMotionX), (int) (scrollY + mLastMotionY),
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragInfo, mEstimatedRect);
+
+ if (foundEstimate != null) {
+ mEstimatedCenter[0] = foundEstimate.centerX();
+ mEstimatedCenter[1] = foundEstimate.centerY();
+
+ int deltaX = (int) Math.abs(mEstimatedCenter[0] - mDragCenter[0]);
+ int deltaY = (int) Math.abs(mEstimatedCenter[1] - mDragCenter[1]);
+
+ if (deltaX > mTriggerWidth || deltaY > mTriggerHeight) {
+ mDrawEstimated = true;
+ }
+ }
+ }
+
+ // Include new estimated area in invalidated rectangle
+ if (DRAW_TARGET_SNAG && mDrawEstimated) {
+ rect.union(mEstimatedRect);
+ }
+ invalidate(rect);
+
mLastDropTarget = dropTarget;
boolean inDragRegion = false;
@@ -478,9 +547,15 @@ public class DragLayer extends FrameLayout implements DragController {
}
if (target == null) {
if (child instanceof DropTarget) {
- dropCoordinates[0] = x;
- dropCoordinates[1] = y;
- return (DropTarget) child;
+ // Only consider this child if they will accept
+ DropTarget childTarget = (DropTarget) child;
+ if (childTarget.acceptDrop(mDragSource, x, y, 0, 0, mDragInfo)) {
+ dropCoordinates[0] = x;
+ dropCoordinates[1] = y;
+ return (DropTarget) child;
+ } else {
+ return null;
+ }
}
} else {
return target;
@@ -531,6 +606,7 @@ public class DragLayer extends FrameLayout implements DragController {
public void run() {
if (mDragScroller != null) {
+ mDrawEstimated = false;
if (mDirection == SCROLL_LEFT) {
mDragScroller.scrollLeft();
} else {