diff --git a/res/values/dimens.xml b/res/values/dimens.xml index d135b43df9..d25cdb644f 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -29,6 +29,8 @@ 5.5dp 8dp + 18dp + 8dp 2dp diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 90cc384e86..02571a059e 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -251,7 +251,12 @@ public class DeviceProfile { int cellLayoutPadding = isScalableGrid ? 0 : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding); - if (isLandscape) { + + if (FeatureFlags.ENABLE_TWO_PANEL_HOME.get() && isTablet) { + cellLayoutPaddingLeftRightPx = + res.getDimensionPixelSize(R.dimen.two_panel_home_side_padding); + cellLayoutBottomPaddingPx = 0; + } else if (isLandscape) { cellLayoutPaddingLeftRightPx = 0; cellLayoutBottomPaddingPx = cellLayoutPadding; } else { @@ -660,6 +665,10 @@ public class DeviceProfile { - (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding); padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2, availablePaddingX / 2, paddingBottom + availablePaddingY / 2); + + if (FeatureFlags.ENABLE_TWO_PANEL_HOME.get()) { + padding.set(0, padding.top, 0, padding.bottom); + } } else { // Pad the top and bottom of the workspace with search/hotseat bar sizes padding.set(desiredWorkspaceLeftRightMarginPx, diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index bb60557122..348d9eef2c 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -19,6 +19,7 @@ package com.android.launcher3; import static com.android.launcher3.Utilities.getDevicePrefs; import static com.android.launcher3.Utilities.getPointString; import static com.android.launcher3.config.FeatureFlags.ENABLE_FOUR_COLUMNS; +import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter; @@ -235,6 +236,9 @@ public class InvariantDeviceProfile { } public static String getCurrentGridName(Context context) { + if (ENABLE_TWO_PANEL_HOME.get()) { + return ENABLE_TWO_PANEL_HOME.key; + } if (ENABLE_FOUR_COLUMNS.get()) { return ENABLE_FOUR_COLUMNS.key; } diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 50f1e445ed..b084eb1b9b 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -282,7 +282,32 @@ public abstract class PagedView extends ViewGrou private int validateNewPage(int newPage) { newPage = ensureWithinScrollBounds(newPage); // Ensure that it is clamped by the actual set of children in all cases - return Utilities.boundToRange(newPage, 0, getPageCount() - 1); + newPage = Utilities.boundToRange(newPage, 0, getPageCount() - 1); + + if (getPanelCount() > 1) { + // Always return left panel as new page + newPage = getLeftmostVisiblePageForIndex(newPage); + } + return newPage; + } + + private int getLeftmostVisiblePageForIndex(int pageIndex) { + int panelCount = getPanelCount(); + return (pageIndex / panelCount) * panelCount; + } + + /** + * Returns the number of pages that are shown at the same time. + */ + protected int getPanelCount() { + return 1; + } + + /** + * Returns true if the view is on one of the current pages, false otherwise. + */ + public boolean isVisible(View child) { + return getLeftmostVisiblePageForIndex(indexOfChild(child)) == mCurrentPage; } /** @@ -548,6 +573,10 @@ public abstract class PagedView extends ViewGrou super.forceLayout(); } + private int getPageWidthSize(int widthSize) { + return (widthSize - mInsets.left - mInsets.right) / getPanelCount(); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getChildCount() == 0) { @@ -578,7 +607,7 @@ public abstract class PagedView extends ViewGrou if (DEBUG) Log.d(TAG, "PagedView.onMeasure(): " + widthSize + ", " + heightSize); int myWidthSpec = MeasureSpec.makeMeasureSpec( - widthSize - mInsets.left - mInsets.right, MeasureSpec.EXACTLY); + getPageWidthSize(widthSize), MeasureSpec.EXACTLY); int myHeightSpec = MeasureSpec.makeMeasureSpec( heightSize - mInsets.top - mInsets.bottom, MeasureSpec.EXACTLY); @@ -672,9 +701,11 @@ public abstract class PagedView extends ViewGrou // In case the pages are of different width, align the page to left or right edge // based on the orientation. + // In case we have multiple panels on the screen, scrollOffsetEnd is the scroll + // needed for the whole visible area, so we have to divide it by panelCount. final int pageScroll = mIsRtl - ? (childStart - scrollOffsetStart) - : Math.max(0, childPrimaryEnd - scrollOffsetEnd); + ? (childStart - scrollOffsetStart) + : Math.max(0, childPrimaryEnd - scrollOffsetEnd / getPanelCount()); if (outPageScrolls[i] != pageScroll) { pageScrollChanged = true; outPageScrolls[i] = pageScroll; @@ -682,6 +713,19 @@ public abstract class PagedView extends ViewGrou childStart += primaryDimension + mPageSpacing + getChildGap(); } } + + int panelCount = getPanelCount(); + if (panelCount > 1) { + for (int i = 0; i < childCount; i++) { + // In case we have multiple panels, always use left panel's page scroll for all + // panels on the screen. + int adjustedScroll = outPageScrolls[getLeftmostVisiblePageForIndex(i)]; + if (outPageScrolls[i] != adjustedScroll) { + outPageScrolls[i] = adjustedScroll; + pageScrollChanged = true; + } + } + } return pageScrollChanged; } @@ -794,14 +838,16 @@ public abstract class PagedView extends ViewGrou } if (direction == View.FOCUS_LEFT) { if (getCurrentPage() > 0) { - snapToPage(getCurrentPage() - 1); - getChildAt(getCurrentPage() - 1).requestFocus(direction); + int nextPage = validateNewPage(getCurrentPage() - 1); + snapToPage(nextPage); + getChildAt(nextPage).requestFocus(direction); return true; } } else if (direction == View.FOCUS_RIGHT) { if (getCurrentPage() < getPageCount() - 1) { - snapToPage(getCurrentPage() + 1); - getChildAt(getCurrentPage() + 1).requestFocus(direction); + int nextPage = validateNewPage(getCurrentPage() + 1); + snapToPage(nextPage); + getChildAt(nextPage).requestFocus(direction); return true; } } @@ -820,11 +866,13 @@ public abstract class PagedView extends ViewGrou } if (direction == View.FOCUS_LEFT) { if (mCurrentPage > 0) { - getPageAt(mCurrentPage - 1).addFocusables(views, direction, focusableMode); + int nextPage = validateNewPage(mCurrentPage - 1); + getPageAt(nextPage).addFocusables(views, direction, focusableMode); } - } else if (direction == View.FOCUS_RIGHT){ + } else if (direction == View.FOCUS_RIGHT) { if (mCurrentPage < getPageCount() - 1) { - getPageAt(mCurrentPage + 1).addFocusables(views, direction, focusableMode); + int nextPage = validateNewPage(mCurrentPage + 1); + getPageAt(nextPage).addFocusables(views, direction, focusableMode); } } } @@ -1255,12 +1303,14 @@ public abstract class PagedView extends ViewGrou if (((isSignificantMove && !isDeltaLeft && !isFling) || (isFling && !isVelocityLeft)) && mCurrentPage > 0) { - finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1; + finalPage = returnToOriginalPage + ? mCurrentPage : mCurrentPage - getPanelCount(); snapToPageWithVelocity(finalPage, velocity); } else if (((isSignificantMove && isDeltaLeft && !isFling) || (isFling && isVelocityLeft)) && mCurrentPage < getChildCount() - 1) { - finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1; + finalPage = returnToOriginalPage + ? mCurrentPage : mCurrentPage + getPanelCount(); snapToPageWithVelocity(finalPage, velocity); } else { snapToDestination(); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index a089517b65..5aea45a806 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -312,7 +312,9 @@ public class Workspace extends PagedView // Increase our bottom insets so we don't overlap with the taskbar. mInsets.bottom += grid.nonOverlappingTaskbarInset; - if (mWorkspaceFadeInAdjacentScreens) { + if (isTwoPanelEnabled()) { + setPageSpacing(0); // we have two pages and we don't want any spacing + } else if (mWorkspaceFadeInAdjacentScreens) { // In landscape mode the page spacing is set to the default. setPageSpacing(grid.edgeMarginPx); } else { @@ -324,12 +326,30 @@ public class Workspace extends PagedView setPageSpacing(Math.max(maxInsets, maxPadding)); } - int paddingLeftRight = grid.cellLayoutPaddingLeftRightPx; int paddingBottom = grid.cellLayoutBottomPaddingPx; + int twoPanelLandscapeSidePadding = paddingLeftRight * 2; + int twoPanelPortraitSidePadding = paddingLeftRight / 2; + + int panelCount = getPanelCount(); for (int i = mWorkspaceScreens.size() - 1; i >= 0; i--) { - mWorkspaceScreens.valueAt(i) - .setPadding(paddingLeftRight, 0, paddingLeftRight, paddingBottom); + int paddingLeft = paddingLeftRight; + int paddingRight = paddingLeftRight; + if (panelCount > 1) { + if (i % panelCount == 0) { // left side panel + paddingLeft = grid.isLandscape ? twoPanelLandscapeSidePadding + : twoPanelPortraitSidePadding; + paddingRight = 0; + } else if (i % panelCount == panelCount - 1) { // right side panel + paddingLeft = 0; + paddingRight = grid.isLandscape ? twoPanelLandscapeSidePadding + : twoPanelPortraitSidePadding; + } else { // middle panel + paddingLeft = 0; + paddingRight = 0; + } + } + mWorkspaceScreens.valueAt(i).setPadding(paddingLeft, 0, paddingRight, paddingBottom); } } @@ -445,6 +465,15 @@ public class Workspace extends PagedView .log(LauncherEvent.LAUNCHER_ITEM_DRAG_STARTED); } + private boolean isTwoPanelEnabled() { + return mLauncher.mDeviceProfile.isTablet && FeatureFlags.ENABLE_TWO_PANEL_HOME.get(); + } + + @Override + protected int getPanelCount() { + return isTwoPanelEnabled() ? 2 : super.getPanelCount(); + } + public void deferRemoveExtraEmptyScreen() { mDeferRemoveExtraEmptyScreen = true; } @@ -832,7 +861,7 @@ public class Workspace extends PagedView private boolean shouldConsumeTouch(View v) { return !workspaceIconsCanBeDragged() - || (!workspaceInModalState() && indexOfChild(v) != mCurrentPage); + || (!workspaceInModalState() && !isVisible(v)); } public boolean isSwitchingState() { @@ -2259,19 +2288,27 @@ public class Workspace extends PagedView int nextPage = getNextPage(); if (layout == null && !isPageInTransition()) { - // Check if the item is dragged over left page + // Check if the item is dragged over currentPage - 1 page mTempTouchCoordinates[0] = Math.min(centerX, d.x); mTempTouchCoordinates[1] = d.y; layout = verifyInsidePage(nextPage + (mIsRtl ? 1 : -1), mTempTouchCoordinates); } if (layout == null && !isPageInTransition()) { - // Check if the item is dragged over right page + // Check if the item is dragged over currentPage + 1 page mTempTouchCoordinates[0] = Math.max(centerX, d.x); mTempTouchCoordinates[1] = d.y; layout = verifyInsidePage(nextPage + (mIsRtl ? -1 : 1), mTempTouchCoordinates); } + // If two panel is enabled, users can also drag items to currentPage + 2 + if (isTwoPanelEnabled() && layout == null && !isPageInTransition()) { + // Check if the item is dragged over currentPage + 2 page + mTempTouchCoordinates[0] = Math.max(centerX, d.x); + mTempTouchCoordinates[1] = d.y; + layout = verifyInsidePage(nextPage + (mIsRtl ? -2 : 2), mTempTouchCoordinates); + } + // Always pick the current page. if (layout == null && nextPage >= 0 && nextPage < getPageCount()) { layout = (CellLayout) getChildAt(nextPage); diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 48e41d5fda..43123c141d 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -205,6 +205,10 @@ public final class FeatureFlags { "ENABLE_OVERVIEW_GRID", false, "Uses grid overview layout. " + "Only applicable on large screen devices."); + public static final BooleanFlag ENABLE_TWO_PANEL_HOME = getDebugFlag( + "ENABLE_TWO_PANEL_HOME", false, + "Uses two panel on home screen. Only applicable on large screen devices."); + public static final BooleanFlag ENABLE_SPLIT_SELECT = getDebugFlag( "ENABLE_SPLIT_SELECT", false, "Uses new split screen selection overview UI"); diff --git a/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java b/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java index 37200a6a8b..6325877936 100644 --- a/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java +++ b/src/com/android/launcher3/dragndrop/SpringLoadedDragController.java @@ -56,9 +56,8 @@ public class SpringLoadedDragController implements OnAlarmListener { if (mScreen != null) { // Snap to the screen that we are hovering over now Workspace w = mLauncher.getWorkspace(); - int page = w.indexOfChild(mScreen); - if (page != w.getCurrentPage()) { - w.snapToPage(page); + if (!w.isVisible(mScreen)) { + w.snapToPage(w.indexOfChild(mScreen)); } } else { mLauncher.getDragController().cancelDrag();