diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-11-15 01:12:30 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-11-15 01:12:30 +0000 |
commit | 77f7b6682262675f25639c94c205e0ad37334c34 (patch) | |
tree | bc651e4bae92807506fffdca0a3d0a7dd82b8c5e | |
parent | 014d1c0b7621a7c59392cd9b8092a081fade1c1b (diff) | |
parent | ac00cba35c5c8502b051cbbca14f8e9f897c3897 (diff) | |
download | android_packages_apps_Trebuchet-77f7b6682262675f25639c94c205e0ad37334c34.tar.gz android_packages_apps_Trebuchet-77f7b6682262675f25639c94c205e0ad37334c34.tar.bz2 android_packages_apps_Trebuchet-77f7b6682262675f25639c94c205e0ad37334c34.zip |
Merge "Simplifying workspace layout" into ub-launcher3-master
7 files changed, 34 insertions, 190 deletions
diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java index 26f5d5b51..117603480 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java @@ -29,9 +29,6 @@ import com.android.quickstep.RecentsView; */ public class OverviewState extends LauncherState { - // The percent to shrink the workspace during overview mode - public static final float SCALE_FACTOR = 0.7f; - private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE; public OverviewState(int id) { diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index d8c4efaa4..cfb55ccc7 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -53,6 +53,7 @@ import com.android.launcher3.util.Thunk; 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 @@ public abstract class ButtonDropTarget extends TextView 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 60c00fb55..2e930662d 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1065,7 +1065,6 @@ public class Launcher extends BaseActivity // 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 4240a30b4..6c22474fc 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -93,7 +93,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc protected int mMinSnapVelocity; protected boolean mFirstLayout = true; - private int mNormalChildHeight; @ViewDebug.ExportedProperty(category = "launcher") protected int mCurrentPage; @@ -166,8 +165,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc @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 abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } } - public void setMinScale(float f) { - mMinScale = f; - mUseMinScale = true; - requestLayout(); - } - @Override public void setScaleX(float scaleX) { super.setScaleX(scaleX); @@ -597,56 +588,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc 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 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc 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 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc 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; - - 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; - } + int myWidthSpec = MeasureSpec.makeMeasureSpec( + getViewportWidth() - mInsets.left - mInsets.right, MeasureSpec.EXACTLY); + int myHeightSpec = MeasureSpec.makeMeasureSpec( + getViewportHeight() - mInsets.top - mInsets.bottom, MeasureSpec.EXACTLY); - 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 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc 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 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc 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 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc 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 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } 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 93fe17c22..0db5a166c 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -80,7 +80,6 @@ import com.android.launcher3.graphics.DragPreviewProvider; 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 @@ public class Workspace extends PagedView 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 94023833c..818cea76c 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -605,29 +605,32 @@ public class DragController implements DragDriver.EventListener, TouchController } 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) { diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java index c339634f2..dcf7453b9 100644 --- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java @@ -34,7 +34,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; public class OverviewState extends LauncherState { // The percent to shrink the workspace during overview mode - public static final float SCALE_FACTOR = 0.7f; + private static final float SCALE_FACTOR = 0.7f; private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE; |