From eeb5bbc9409978cc2ae52d48380399fcde3d9f85 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 13 Nov 2013 15:47:05 -0800 Subject: Use the icon bounds for all calculations. - Fixes a drag and drop issue when the dynamic grid scales icons down, due to the drawable bounds not being equal to their bitmap sizes. Change-Id: If7c68b51131de7bac3195a2619e22340f7789432 --- .../android/launcher3/AppsCustomizePagedView.java | 7 ++++++ src/com/android/launcher3/DragController.java | 3 ++- src/com/android/launcher3/DragLayer.java | 10 +++++--- src/com/android/launcher3/DragSource.java | 5 ++++ src/com/android/launcher3/DragView.java | 12 ++++++++++ src/com/android/launcher3/FastBitmapDrawable.java | 28 ++++------------------ src/com/android/launcher3/Folder.java | 5 ++++ src/com/android/launcher3/Workspace.java | 8 ++++++- 8 files changed, 50 insertions(+), 28 deletions(-) (limited to 'src/com/android/launcher3') diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index d9ca1570b..688ff82aa 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -915,6 +915,13 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen return true; } + @Override + public float getIntrinsicIconScaleFactor() { + LauncherAppState app = LauncherAppState.getInstance(); + DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); + return (float) grid.allAppsIconSizePx / grid.iconSizePx; + } + @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); diff --git a/src/com/android/launcher3/DragController.java b/src/com/android/launcher3/DragController.java index ab4823343..1bfaa233b 100644 --- a/src/com/android/launcher3/DragController.java +++ b/src/com/android/launcher3/DragController.java @@ -198,7 +198,7 @@ public class DragController { * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. * Makes dragging feel more precise, e.g. you can clip out a transparent border */ - public void startDrag(Bitmap b, int dragLayerX, int dragLayerY, + public DragView startDrag(Bitmap b, int dragLayerX, int dragLayerY, DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion, float initialDragViewScale) { if (PROFILE_DRAWING_DURING_DRAG) { @@ -245,6 +245,7 @@ public class DragController { mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); dragView.show(mMotionDownX, mMotionDownY); handleMoveEvent(mMotionDownX, mMotionDownY); + return dragView; } /** diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java index 159d7d992..dc0ba903f 100644 --- a/src/com/android/launcher3/DragLayer.java +++ b/src/com/android/launcher3/DragLayer.java @@ -522,14 +522,18 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang scale *= childScale; int toX = coord[0]; int toY = coord[1]; + float toScale = scale; if (child instanceof TextView) { TextView tv = (TextView) child; + // Account for the source scale of the icon (ie. from AllApps to Workspace, in which + // the workspace may have smaller icon bounds). + toScale = scale / dragView.getIntrinsicIconScaleFactor(); // The child may be scaled (always about the center of the view) so to account for it, // we have to offset the position by the scaled size. Once we do that, we can center // the drag view about the scaled child view. - toY += Math.round(scale * tv.getPaddingTop()); - toY -= dragView.getMeasuredHeight() * (1 - scale) / 2; + toY += Math.round(toScale * tv.getPaddingTop()); + toY -= dragView.getMeasuredHeight() * (1 - toScale) / 2; toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2; } else if (child instanceof FolderIcon) { // Account for holographic blur padding on the drag view @@ -555,7 +559,7 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang } } }; - animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, scale, scale, + animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale, onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView); } diff --git a/src/com/android/launcher3/DragSource.java b/src/com/android/launcher3/DragSource.java index 2ef99ae08..cca9ab1a4 100644 --- a/src/com/android/launcher3/DragSource.java +++ b/src/com/android/launcher3/DragSource.java @@ -30,6 +30,11 @@ public interface DragSource { */ boolean supportsFlingToDelete(); + /* + * @return the scale of the icons over the workspace icon size + */ + float getIntrinsicIconScaleFactor(); + /** * A callback specifically made back to the source after an item from this source has been flung * to be deleted on a DropTarget. In such a situation, this method will be called after diff --git a/src/com/android/launcher3/DragView.java b/src/com/android/launcher3/DragView.java index 686cf62ff..b66b55c9d 100644 --- a/src/com/android/launcher3/DragView.java +++ b/src/com/android/launcher3/DragView.java @@ -51,6 +51,9 @@ public class DragView extends View { private float mOffsetX = 0.0f; private float mOffsetY = 0.0f; private float mInitialScale = 1f; + // The intrinsic icon scale factor is the scale factor for a drag icon over the workspace + // size. This is ignored for non-icons. + private float mIntrinsicIconScale = 1f; /** * Construct the drag view. @@ -120,6 +123,15 @@ public class DragView extends View { mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); } + /** Sets the scale of the view over the normal workspace icon size. */ + public void setIntrinsicIconScaleFactor(float scale) { + mIntrinsicIconScale = scale; + } + + public float getIntrinsicIconScaleFactor() { + return mIntrinsicIconScale; + } + public float getOffsetY() { return mOffsetY; } diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java index bce6707da..83be14369 100644 --- a/src/com/android/launcher3/FastBitmapDrawable.java +++ b/src/com/android/launcher3/FastBitmapDrawable.java @@ -27,19 +27,11 @@ import android.graphics.drawable.Drawable; class FastBitmapDrawable extends Drawable { private Bitmap mBitmap; private int mAlpha; - private int mWidth; - private int mHeight; private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); FastBitmapDrawable(Bitmap b) { - mAlpha = 255; + mAlpha = 255; mBitmap = b; - if (b != null) { - mWidth = mBitmap.getWidth(); - mHeight = mBitmap.getHeight(); - } else { - mWidth = mHeight = 0; - } } @Override @@ -76,32 +68,22 @@ class FastBitmapDrawable extends Drawable { @Override public int getIntrinsicWidth() { - return mWidth; + return getBounds().width(); } @Override public int getIntrinsicHeight() { - return mHeight; + return getBounds().height(); } @Override public int getMinimumWidth() { - return mWidth; + return getBounds().width(); } @Override public int getMinimumHeight() { - return mHeight; - } - - public void setBitmap(Bitmap b) { - mBitmap = b; - if (b != null) { - mWidth = mBitmap.getWidth(); - mHeight = mBitmap.getHeight(); - } else { - mWidth = mHeight = 0; - } + return getBounds().height(); } public Bitmap getBitmap() { diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index f26d01f5d..7fe83c54d 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -786,6 +786,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } } + @Override + public float getIntrinsicIconScaleFactor() { + return 1f; + } + @Override public boolean supportsFlingToDelete() { return true; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index f36c815da..9f4f9d918 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2536,8 +2536,9 @@ public class Workspace extends SmoothPagedView icon.clearPressedOrFocusedBackground(); } - mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), + DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); + dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); @@ -4140,6 +4141,11 @@ public class Workspace extends SmoothPagedView } } + @Override + public float getIntrinsicIconScaleFactor() { + return 1f; + } + @Override public boolean supportsFlingToDelete() { return true; -- cgit v1.2.3