Simplifying workspace layout
Instead of creating workspace view larger than the screen size (so that it can be
zoomed out), restricting the size to the parent size and bypassing the drag events
directly to Workspace (since the workspace is smaller when zoomed out, it might not
qualify for all events otherwise).
Change-Id: I45e213dd6d16bec5feb6e7cf90bc6f7de4c6d305
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index d8c4efa..cfb55cc 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -53,6 +53,7 @@
public abstract class ButtonDropTarget extends TextView
implements DropTarget, DragController.DragListener, OnClickListener {
+ private static final int[] sTempCords = new int[2];
private static final int DRAG_VIEW_DROP_DURATION = 285;
private final boolean mHideParentOnDisable;
@@ -257,9 +258,9 @@
super.getHitRect(outRect);
outRect.bottom += mBottomDragPadding;
- int[] coords = new int[2];
- mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords);
- outRect.offsetTo(coords[0], coords[1]);
+ sTempCords[0] = sTempCords[1] = 0;
+ mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, sTempCords);
+ outRect.offsetTo(sTempCords[0], sTempCords[1]);
}
public Rect getIconRect(DragObject dragObject) {
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b1b3452..608570a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1064,7 +1064,6 @@
// Setup the drag controller (drop targets have to be added in reverse order in priority)
mDragController.setMoveTarget(mWorkspace);
- mDragController.addDropTarget(mWorkspace);
mDropTargetBar.setup(mDragController);
mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace);
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 4240a30..6c22474 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -93,7 +93,6 @@
protected int mMinSnapVelocity;
protected boolean mFirstLayout = true;
- private int mNormalChildHeight;
@ViewDebug.ExportedProperty(category = "launcher")
protected int mCurrentPage;
@@ -166,8 +165,6 @@
@Thunk static int REORDERING_REORDER_REPOSITION_DURATION = 300;
private static int REORDERING_SIDE_PAGE_HOVER_TIMEOUT = 80;
- private float mMinScale = 1f;
- private boolean mUseMinScale = false;
@Thunk View mDragView;
private Runnable mSidePageHoverRunnable;
@Thunk int mSidePageHoverIndex = -1;
@@ -273,12 +270,6 @@
}
}
- public void setMinScale(float f) {
- mMinScale = f;
- mUseMinScale = true;
- requestLayout();
- }
-
@Override
public void setScaleX(float scaleX) {
super.setScaleX(scaleX);
@@ -597,56 +588,9 @@
computeScrollHelper();
}
- public static class LayoutParams extends ViewGroup.LayoutParams {
- public boolean isFullScreenPage = false;
-
- // If true, the start edge of the page snaps to the start edge of the viewport.
- public boolean matchStartEdge = false;
-
- /**
- * {@inheritDoc}
- */
- public LayoutParams(int width, int height) {
- super(width, height);
- }
-
- public LayoutParams(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public LayoutParams(ViewGroup.LayoutParams source) {
- super(source);
- }
- }
-
- @Override
- public LayoutParams generateLayoutParams(AttributeSet attrs) {
- return new LayoutParams(getContext(), attrs);
- }
-
- @Override
- protected LayoutParams generateDefaultLayoutParams() {
- return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- }
-
- @Override
- protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
- return new LayoutParams(p);
- }
-
- @Override
- protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
- return p instanceof LayoutParams;
- }
-
- public void addFullScreenPage(View page) {
- LayoutParams lp = generateDefaultLayoutParams();
- lp.isFullScreenPage = true;
- super.addView(page, 0, lp);
- }
-
public int getNormalChildHeight() {
- return mNormalChildHeight;
+ return getViewportHeight() - getPaddingTop() - getPaddingBottom()
+ - mInsets.top - mInsets.bottom;
}
@Override
@@ -662,22 +606,7 @@
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
- // NOTE: We multiply by 2f to account for the fact that depending on the offset of the
- // viewport, we can be at most one and a half screens offset once we scale down
- DisplayMetrics dm = getResources().getDisplayMetrics();
- int maxSize = Math.max(dm.widthPixels + mInsets.left + mInsets.right,
- dm.heightPixels + mInsets.top + mInsets.bottom);
- int parentWidthSize = (int) (2f * maxSize);
- int parentHeightSize = (int) (2f * maxSize);
- int scaledWidthSize, scaledHeightSize;
- if (mUseMinScale) {
- scaledWidthSize = (int) (parentWidthSize / mMinScale);
- scaledHeightSize = (int) (parentHeightSize / mMinScale);
- } else {
- scaledWidthSize = widthSize;
- scaledHeightSize = heightSize;
- }
mViewport.set(0, 0, widthSize, heightSize);
if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
@@ -691,71 +620,19 @@
return;
}
- /* Allow the height to be set as WRAP_CONTENT. This allows the particular case
- * of the All apps view on XLarge displays to not take up more space then it needs. Width
- * is still not allowed to be set as WRAP_CONTENT since many parts of the code expect
- * each page to have the same width.
- */
- final int verticalPadding = getPaddingTop() + getPaddingBottom();
- final int horizontalPadding = getPaddingLeft() + getPaddingRight();
-
- int referenceChildWidth = 0;
// The children are given the same width and height as the workspace
// unless they were set to WRAP_CONTENT
if (DEBUG) Log.d(TAG, "PagedView.onMeasure(): " + widthSize + ", " + heightSize);
- if (DEBUG) Log.d(TAG, "PagedView.scaledSize: " + scaledWidthSize + ", " + scaledHeightSize);
- if (DEBUG) Log.d(TAG, "PagedView.parentSize: " + parentWidthSize + ", " + parentHeightSize);
- if (DEBUG) Log.d(TAG, "PagedView.horizontalPadding: " + horizontalPadding);
- if (DEBUG) Log.d(TAG, "PagedView.verticalPadding: " + verticalPadding);
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- // disallowing padding in paged view (just pass 0)
- final View child = getPageAt(i);
- if (child.getVisibility() != GONE) {
- final LayoutParams lp = (LayoutParams) child.getLayoutParams();
- int childWidthMode;
- int childHeightMode;
- int childWidth;
- int childHeight;
+ int myWidthSpec = MeasureSpec.makeMeasureSpec(
+ getViewportWidth() - mInsets.left - mInsets.right, MeasureSpec.EXACTLY);
+ int myHeightSpec = MeasureSpec.makeMeasureSpec(
+ getViewportHeight() - mInsets.top - mInsets.bottom, MeasureSpec.EXACTLY);
- if (!lp.isFullScreenPage) {
- if (lp.width == LayoutParams.WRAP_CONTENT) {
- childWidthMode = MeasureSpec.AT_MOST;
- } else {
- childWidthMode = MeasureSpec.EXACTLY;
- }
-
- if (lp.height == LayoutParams.WRAP_CONTENT) {
- childHeightMode = MeasureSpec.AT_MOST;
- } else {
- childHeightMode = MeasureSpec.EXACTLY;
- }
-
- childWidth = getViewportWidth() - horizontalPadding
- - mInsets.left - mInsets.right;
- childHeight = getViewportHeight() - verticalPadding
- - mInsets.top - mInsets.bottom;
- mNormalChildHeight = childHeight;
- } else {
- childWidthMode = MeasureSpec.EXACTLY;
- childHeightMode = MeasureSpec.EXACTLY;
-
- childWidth = getViewportWidth();
- childHeight = getViewportHeight();
- }
- if (referenceChildWidth == 0) {
- referenceChildWidth = childWidth;
- }
-
- final int childWidthMeasureSpec =
- MeasureSpec.makeMeasureSpec(childWidth, childWidthMode);
- final int childHeightMeasureSpec =
- MeasureSpec.makeMeasureSpec(childHeight, childHeightMode);
- child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
- }
- }
- setMeasuredDimension(scaledWidthSize, scaledHeightSize);
+ // measureChildren takes accounts for content padding, we only need to care about extra
+ // space due to insets.
+ measureChildren(myWidthSpec, myHeightSpec);
+ setMeasuredDimension(widthSize, heightSize);
}
@SuppressLint("DrawAllocation")
@@ -780,10 +657,7 @@
int verticalPadding = getPaddingTop() + getPaddingBottom();
- LayoutParams lp = (LayoutParams) getChildAt(startIndex).getLayoutParams();
- LayoutParams nextLp;
-
- int childLeft = offsetX + (lp.isFullScreenPage ? 0 : getPaddingLeft());
+ int childLeft = offsetX + getPaddingLeft();
if (mPageScrolls == null || childCount != mChildCountOnLastLayout) {
mPageScrolls = new int[childCount];
}
@@ -791,14 +665,9 @@
for (int i = startIndex; i != endIndex; i += delta) {
final View child = getPageAt(i);
if (child.getVisibility() != View.GONE) {
- lp = (LayoutParams) child.getLayoutParams();
- int childTop;
- if (lp.isFullScreenPage) {
- childTop = offsetY;
- } else {
- childTop = offsetY + getPaddingTop() + mInsets.top;
- childTop += (getViewportHeight() - mInsets.top - mInsets.bottom - verticalPadding - child.getMeasuredHeight()) / 2;
- }
+ int childTop = offsetY + getPaddingTop() + mInsets.top;
+ childTop += (getViewportHeight() - mInsets.top - mInsets.bottom - verticalPadding
+ - child.getMeasuredHeight()) / 2;
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
@@ -807,26 +676,10 @@
child.layout(childLeft, childTop,
childLeft + child.getMeasuredWidth(), childTop + childHeight);
- int scrollOffsetLeft = lp.isFullScreenPage ? 0 : getPaddingLeft();
+ int scrollOffsetLeft = getPaddingLeft();
mPageScrolls[i] = childLeft - scrollOffsetLeft - offsetX;
- int pageGap = mPageSpacing;
- int next = i + delta;
- if (next != endIndex) {
- nextLp = (LayoutParams) getPageAt(next).getLayoutParams();
- } else {
- nextLp = null;
- }
-
- // Prevent full screen pages from showing in the viewport
- // when they are not the current page.
- if (lp.isFullScreenPage) {
- pageGap = getPaddingLeft();
- } else if (nextLp != null && nextLp.isFullScreenPage) {
- pageGap = getPaddingRight();
- }
-
- childLeft += childWidth + pageGap + getChildGap();
+ childLeft += childWidth + mPageSpacing + getChildGap();
}
}
@@ -1289,12 +1142,7 @@
} else {
View child = getChildAt(index);
- int scrollOffset = 0;
- LayoutParams lp = (LayoutParams) child.getLayoutParams();
- if (!lp.isFullScreenPage) {
- scrollOffset = mIsRtl ? getPaddingRight() : getPaddingLeft();
- }
-
+ int scrollOffset = scrollOffset = mIsRtl ? getPaddingRight() : getPaddingLeft();
int baselineX = mPageScrolls[index] + scrollOffset + getViewportOffsetX();
return (int) (child.getX() - baselineX);
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 93fe17c..0db5a16 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -80,7 +80,6 @@
import com.android.launcher3.graphics.PreloadIconDrawable;
import com.android.launcher3.popup.PopupContainerWithArrow;
import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider;
-import com.android.launcher3.uioverrides.OverviewState;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -440,10 +439,7 @@
setClipChildren(false);
setClipToPadding(false);
- // TODO: Remove this
- setMinScale(OverviewState.SCALE_FACTOR);
setupLayoutTransition();
-
mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);
// Set the wallpaper dimensions when Launcher starts up
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index 9402383..818cea7 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -605,29 +605,32 @@
}
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
- final Rect r = mRectTemp;
+ mDragObject.x = x;
+ mDragObject.y = y;
+ final Rect r = mRectTemp;
final ArrayList<DropTarget> dropTargets = mDropTargets;
final int count = dropTargets.size();
- for (int i=count-1; i>=0; i--) {
+ for (int i = count - 1; i >= 0; i--) {
DropTarget target = dropTargets.get(i);
if (!target.isDropEnabled())
continue;
target.getHitRectRelativeToDragLayer(r);
-
- mDragObject.x = x;
- mDragObject.y = y;
if (r.contains(x, y)) {
-
dropCoordinates[0] = x;
dropCoordinates[1] = y;
mLauncher.getDragLayer().mapCoordInSelfToDescendant((View) target, dropCoordinates);
-
return target;
}
}
- return null;
+ // Pass all unhandled drag to workspace. Workspace finds the correct
+ // cell layout to drop to in the existing drag/drop logic.
+ dropCoordinates[0] = x;
+ dropCoordinates[1] = y;
+ mLauncher.getDragLayer().mapCoordInSelfToDescendant(mLauncher.getWorkspace(),
+ dropCoordinates);
+ return mLauncher.getWorkspace();
}
public void setWindowToken(IBinder token) {