From 35e7e64d4b98e42c760e5e91489b7014a6ba9073 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Sun, 17 Jul 2011 14:47:18 -0700 Subject: Bounding folders into their associated cell layout area, excluding dock Change-Id: I220ccf1d8b08f9962c63efc92265e3c7acc137f9 --- src/com/android/launcher2/DragLayer.java | 27 +++++++++++++++++++++------ src/com/android/launcher2/Folder.java | 32 ++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java index 9997c2957..8563be9f2 100644 --- a/src/com/android/launcher2/DragLayer.java +++ b/src/com/android/launcher2/DragLayer.java @@ -169,6 +169,13 @@ public class DragLayer extends FrameLayout { return mDragController.onTouchEvent(ev); } + /** + * Determine the rect of the descendant in this DragLayer's coordinates + * + * @param descendant The descendant whose coordinates we want to find. + * @param r The rect into which to place the results. + * @return The factor by which this descendant is scaled relative to this DragLayer. + */ public float getDescendantRectRelativeToSelf(View descendant, Rect r) { mTmpXY[0] = 0; mTmpXY[1] = 0; @@ -178,6 +185,20 @@ public class DragLayer extends FrameLayout { return scale; } + public void getLocationInDragLayer(View child, int[] loc) { + loc[0] = 0; + loc[1] = 0; + getDescendantCoordRelativeToSelf(child, loc); + } + + /** + * Given a coordinate relative to the descendant, find the coordinate in this DragLayer's + * coordinates. + * + * @param descendant The descendant to which the passed coordinate is relative. + * @param coord The coordinate that we want mapped. + * @return The factor by which this descendant is scaled relative to this DragLayer. + */ public float getDescendantCoordRelativeToSelf(View descendant, int[] coord) { float scale = 1.0f; float[] pt = {coord[0], coord[1]}; @@ -199,12 +220,6 @@ public class DragLayer extends FrameLayout { return scale; } - public void getLocationInDragLayer(View child, int[] loc) { - loc[0] = 0; - loc[1] = 0; - getDescendantCoordRelativeToSelf(child, loc); - } - public void getViewRectRelativeToSelf(View v, Rect r) { int[] loc = new int[2]; getLocationInWindow(loc); diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index dd0bffda6..ef02de6bc 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -730,20 +730,24 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; - int parentWidth = 0; - int parentHeight = 0; - if (parent != null) { - parentWidth = parent.getMeasuredWidth(); - parentHeight = parent.getMeasuredHeight(); - } - - int left = Math.min(Math.max(0, centeredLeft), parentWidth - width); - int top = Math.min(Math.max(0, centeredTop), parentHeight - height); - if (width >= parentWidth) { - left = (parentWidth - width) / 2; - } - if (height >= parentHeight) { - top = (parentHeight - height) / 2; + // We first fetch the currently visible CellLayoutChildren + int page = mLauncher.getWorkspace().getCurrentPage(); + CellLayout currentPage = (CellLayout) mLauncher.getWorkspace().getChildAt(page); + CellLayoutChildren boundingLayout = currentPage.getChildrenLayout(); + Rect bounds = new Rect(); + parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); + + // We need to bound the folder to the currently visible CellLayoutChildren + int left = Math.min(Math.max(bounds.left, centeredLeft), + bounds.left + bounds.width() - width); + int top = Math.min(Math.max(bounds.top, centeredTop), + bounds.top + bounds.height() - height); + // If the folder doesn't fit within the bounds, center it about the desired bounds + if (width >= bounds.width()) { + left = bounds.left + (bounds.width() - width) / 2; + } + if (height >= bounds.height()) { + top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); -- cgit v1.2.3