Two panel & two page swipe & currentPage fixes

- Pagespacing set to 0 to have similar design to figma
- Added padding to left side of left panel and right side of right panel to match figma
- getPageScrolls changed to support two page scrolling
- validateNewPage changed so that only even indexed pages can be switched to
- getPageWidthSize added for measurements, it returns half screen width when two panel is active
- onMeasure changed to use getPageWidthSize
- panelCount has been increased from 1 to 2 when two panel is active
- add feature flag for two panel home
- shouldConsumeTouch changed so not only currentpage is checked but currentpage+1 screen as well
- add one more extra check for setDropLayoutForDragObject for currentpage + 2, next to right panel
- using new grid option for two panel home screen

Test: manual
Bug: 174464115
Change-Id: I1bad7eecc67f65fb833608744a5aa5aca65373b4
This commit is contained in:
Andras Kloczl 2021-02-11 23:51:19 +01:00
parent 2b30076aba
commit 8e57cce4ee
7 changed files with 129 additions and 24 deletions

View File

@ -29,6 +29,8 @@
<dimen name="dynamic_grid_cell_layout_padding">5.5dp</dimen>
<dimen name="dynamic_grid_cell_padding_x">8dp</dimen>
<dimen name="two_panel_home_side_padding">18dp</dimen>
<!-- Hotseat -->
<dimen name="dynamic_grid_hotseat_top_padding">8dp</dimen>
<dimen name="dynamic_grid_hotseat_bottom_padding">2dp</dimen>

View File

@ -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,

View File

@ -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;
}

View File

@ -282,7 +282,32 @@ public abstract class PagedView<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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<T extends View & PageIndicator> 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();

View File

@ -312,7 +312,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
// 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<WorkspacePageIndicator>
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<WorkspacePageIndicator>
.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<WorkspacePageIndicator>
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<WorkspacePageIndicator>
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);

View File

@ -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");

View File

@ -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();