From 1f4d56c01eb80ae853eb936e7a05aab604c869d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Franco?= Date: Tue, 8 Aug 2023 03:29:10 +0000 Subject: [PATCH] Revert "Remove flags ENABLE_TWO_PANEL_HOME FOLDABLE_WORKSPACE_REORDE and FOLDABLE_SINGLE_PAGE" This reverts commit 76a1ceb5f2554c839ca27d3df2787719ac33afb2. Reason for revert: Add flag back to turn it off for further testing Bug: 270395274 Merged-In: I10b9e99734b14cbbe8d1190300493099a1f28a24 Change-Id: I10b9e99734b14cbbe8d1190300493099a1f28a24 --- .../launcher3/AppWidgetResizeFrame.java | 46 ++++++++++++ .../launcher3/InvariantDeviceProfile.java | 3 +- src/com/android/launcher3/Launcher.java | 3 +- src/com/android/launcher3/Workspace.java | 71 ++++++++++++++++--- .../launcher3/config/FeatureFlags.java | 11 +++ .../testing/TestInformationHandler.java | 4 +- 6 files changed, 127 insertions(+), 11 deletions(-) diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java index 9a1ccd0e1f..71314525bb 100644 --- a/src/com/android/launcher3/AppWidgetResizeFrame.java +++ b/src/com/android/launcher3/AppWidgetResizeFrame.java @@ -360,6 +360,37 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O lp.y = sTmpRect.top; } + // Handle invalid resize across CellLayouts in the two panel UI. + if (mCellLayout.getParent() instanceof Workspace) { + Workspace workspace = (Workspace) mCellLayout.getParent(); + CellLayout pairedCellLayout = workspace.getScreenPair(mCellLayout); + if (pairedCellLayout != null) { + Rect focusedCellLayoutBound = sTmpRect; + mDragLayerRelativeCoordinateHelper.viewToRect(mCellLayout, focusedCellLayoutBound); + Rect resizeFrameBound = sTmpRect2; + findViewById(R.id.widget_resize_frame).getGlobalVisibleRect(resizeFrameBound); + float progress = 1f; + if (workspace.indexOfChild(pairedCellLayout) < workspace.indexOfChild(mCellLayout) + && mDeltaX < 0 + && resizeFrameBound.left < focusedCellLayoutBound.left) { + // Resize from right to left. + progress = (mDragAcrossTwoPanelOpacityMargin + mDeltaX) + / mDragAcrossTwoPanelOpacityMargin; + } else if (workspace.indexOfChild(pairedCellLayout) + > workspace.indexOfChild(mCellLayout) + && mDeltaX > 0 + && resizeFrameBound.right > focusedCellLayoutBound.right) { + // Resize from left to right. + progress = (mDragAcrossTwoPanelOpacityMargin - mDeltaX) + / mDragAcrossTwoPanelOpacityMargin; + } + float alpha = Math.max(MIN_OPACITY_FOR_CELL_LAYOUT_DURING_INVALID_RESIZE, progress); + float springLoadedProgress = Math.min(1f, 1f - progress); + updateInvalidResizeEffect(mCellLayout, pairedCellLayout, alpha, + springLoadedProgress); + } + } + requestLayout(); } @@ -516,6 +547,13 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O } final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); + final CellLayout pairedCellLayout; + if (mCellLayout.getParent() instanceof Workspace) { + Workspace workspace = (Workspace) mCellLayout.getParent(); + pairedCellLayout = workspace.getScreenPair(mCellLayout); + } else { + pairedCellLayout = null; + } if (!animate) { lp.width = newWidth; lp.height = newHeight; @@ -524,6 +562,10 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O for (int i = 0; i < HANDLE_COUNT; i++) { mDragHandles[i].setAlpha(1f); } + if (pairedCellLayout != null) { + updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */ 1f, + /* springLoadedProgress= */ 0f); + } requestLayout(); } else { ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, @@ -539,6 +581,10 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O set.play(mFirstFrameAnimatorHelper.addTo( ObjectAnimator.ofFloat(mDragHandles[i], ALPHA, 1f))); } + if (pairedCellLayout != null) { + updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */ 1f, + /* springLoadedProgress= */ 0f, /* animatorSet= */ set); + } set.setDuration(SNAP_DURATION); set.start(); } diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index dac6120e1b..a4d77bd64e 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -18,6 +18,7 @@ package com.android.launcher3; import static com.android.launcher3.LauncherPrefs.GRID_NAME; import static com.android.launcher3.Utilities.dpiFromPx; +import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME; import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE; import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; @@ -311,7 +312,7 @@ public class InvariantDeviceProfile { int type = displayInfo.supportedBounds.stream() .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone) .reduce(0, (a, b) -> a | b); - if ((type == (flagPhone | flagTablet))) { + if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) { // device has profiles supporting both phone and table modes return TYPE_MULTI_DISPLAY; } else if (type == flagTablet) { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index c7370746e4..d0a25765c4 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -44,6 +44,7 @@ import static com.android.launcher3.LauncherState.NO_SCALE; import static com.android.launcher3.LauncherState.SPRING_LOADED; import static com.android.launcher3.Utilities.postAsyncCallback; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.getSupportedActions; +import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE; import static com.android.launcher3.config.FeatureFlags.MULTI_SELECT_EDIT_MODE; import static com.android.launcher3.config.FeatureFlags.SHOW_DOT_PAGINATION; import static com.android.launcher3.logging.StatsLogManager.EventEnum; @@ -766,7 +767,7 @@ public class Launcher extends StatefulActivity } onDeviceProfileInitiated(); - if (mDeviceProfile.isTwoPanels) { + if (FOLDABLE_SINGLE_PAGE.get() && mDeviceProfile.isTwoPanels) { mCellPosMapper = new TwoPanelCellPosMapper(mDeviceProfile.inv.numColumns); } else { mCellPosMapper = CellPosMapper.DEFAULT; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index b141e18823..adaf20f86f 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -28,6 +28,7 @@ import static com.android.launcher3.LauncherState.NORMAL; import static com.android.launcher3.LauncherState.SPRING_LOADED; import static com.android.launcher3.MotionEventsUtils.isTrackpadMultiFingerSwipe; import static com.android.launcher3.anim.AnimatorListeners.forSuccessCallback; +import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPELEFT; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPERIGHT; @@ -126,6 +127,7 @@ import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverla import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.function.Consumer; import java.util.function.Predicate; @@ -501,14 +503,19 @@ public class Workspace extends PagedView .log(LauncherEvent.LAUNCHER_ITEM_DRAG_STARTED); } - public void deferRemoveExtraEmptyScreen() { - mDeferRemoveExtraEmptyScreen = true; + private boolean isTwoPanelEnabled() { + return !FOLDABLE_SINGLE_PAGE.get() && mLauncher.mDeviceProfile.isTwoPanels; } @Override public int getPanelCount() { - return super.getPanelCount(); + return isTwoPanelEnabled() ? 2 : super.getPanelCount(); } + + public void deferRemoveExtraEmptyScreen() { + mDeferRemoveExtraEmptyScreen = true; + } + @Override public void onDragEnd() { if (ENFORCE_DRAG_EVENT_ORDER) { @@ -661,7 +668,7 @@ public class Workspace extends PagedView // created CellLayout. DeviceProfile dp = mLauncher.getDeviceProfile(); CellLayout newScreen; - if (dp.isTwoPanels) { + if (FOLDABLE_SINGLE_PAGE.get() && dp.isTwoPanels) { newScreen = (CellLayout) LayoutInflater.from(getContext()).inflate( R.layout.workspace_screen_foldable, this, false /* attachToRoot */); } else { @@ -686,6 +693,15 @@ public class Workspace extends PagedView if (mDragSourceInternal != null) { int dragSourceChildCount = mDragSourceInternal.getChildCount(); + + // If the icon was dragged from Hotseat, there is no page pair + if (isTwoPanelEnabled() && !(mDragSourceInternal.getParent() instanceof Hotseat)) { + int pagePairScreenId = getScreenPair(getCellPosMapper().mapModelToPresenter( + dragObject.dragInfo).screenId); + CellLayout pagePair = mWorkspaceScreens.get(pagePairScreenId); + dragSourceChildCount += pagePair.getShortcutsAndWidgets().getChildCount(); + } + // When the drag view content is a LauncherAppWidgetHostView, we should increment the // drag source child count by 1 because the widget in drag has been detached from its // original parent, ShortcutAndWidgetContainer, and reattached to the DragView. @@ -696,6 +712,11 @@ public class Workspace extends PagedView if (dragSourceChildCount == 1) { lastChildOnScreen = true; } + CellLayout cl = (CellLayout) mDragSourceInternal.getParent(); + if (!FOLDABLE_SINGLE_PAGE.get() && getLeftmostVisiblePageForIndex(indexOfChild(cl)) + == getLeftmostVisiblePageForIndex(getPageCount() - 1)) { + childOnFinalScreen = true; + } } // If this is the last item on the final screen @@ -730,6 +751,9 @@ public class Workspace extends PagedView */ private void forEachExtraEmptyPageId(Consumer callback) { callback.accept(EXTRA_EMPTY_SCREEN_ID); + if (isTwoPanelEnabled()) { + callback.accept(EXTRA_EMPTY_SCREEN_SECOND_ID); + } } /** @@ -843,7 +867,9 @@ public class Workspace extends PagedView public boolean hasExtraEmptyScreens() { return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) - && getChildCount() > getPanelCount(); + && getChildCount() > getPanelCount() + && (!isTwoPanelEnabled() + || mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_SECOND_ID)); } /** @@ -949,7 +975,14 @@ public class Workspace extends PagedView */ @Nullable public CellLayout getScreenPair(CellLayout cellLayout) { - return null; + if (!isTwoPanelEnabled()) { + return null; + } + int screenId = getIdForScreen(cellLayout); + if (screenId == -1) { + return null; + } + return getScreenWithId(getScreenPair(screenId)); } public void stripEmptyScreens() { @@ -977,6 +1010,22 @@ public class Workspace extends PagedView } } + // When two panel home is enabled we only remove an empty page if both visible pages are + // empty. + if (isTwoPanelEnabled()) { + // We go through all the pages that were marked as removable and check their page pair + Iterator removeScreensIterator = removeScreens.iterator(); + while (removeScreensIterator.hasNext()) { + int pageToRemove = removeScreensIterator.next(); + int pagePair = getScreenPair(pageToRemove); + if (!removeScreens.contains(pagePair)) { + // The page pair isn't empty so we want to remove the current page from the + // removable pages' collection + removeScreensIterator.remove(); + } + } + } + // We enforce at least one page (two pages on two panel home) to add new items to. // In the case that we remove the last such screen(s), we convert the last screen(s) // to the empty screen(s) @@ -997,7 +1046,12 @@ public class Workspace extends PagedView removeView(cl); } else { // The last page(s) should be converted into extra empty page(s) - int extraScreenId = EXTRA_EMPTY_SCREEN_ID; + int extraScreenId = isTwoPanelEnabled() && id % 2 == 1 + // This is the right panel in a two panel scenario + ? EXTRA_EMPTY_SCREEN_SECOND_ID + // This is either the last screen in a one panel scenario, or the left panel + // in a two panel scenario when there are only two empty pages left + : EXTRA_EMPTY_SCREEN_ID; mWorkspaceScreens.put(extraScreenId, cl); mScreenOrder.add(extraScreenId); } @@ -2518,7 +2572,8 @@ public class Workspace extends PagedView // Go through the pages and check if the dragged item is inside one of them. This block // is responsible for determining whether we need to snap to a different screen. int nextPage = getNextPage(); - IntSet pageIndexesToVerify = IntSet.wrap(nextPage - 1, nextPage + 1); + IntSet pageIndexesToVerify = IntSet.wrap(nextPage - 1, + nextPage + (isTwoPanelEnabled() ? 2 : 1)); for (int pageIndex : pageIndexesToVerify) { // When deciding whether to perform a page switch, we need to consider the most diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 39d5f9a49a..e530070179 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -183,6 +183,17 @@ public final class FeatureFlags { "Enables predictive back animation from all apps and widgets to home"); // TODO(Block 11): Clean up flags + public static final BooleanFlag ENABLE_TWO_PANEL_HOME = getDebugFlag(270392643, + "ENABLE_TWO_PANEL_HOME", ENABLED, + "Uses two panel on home screen. Only applicable on large screen devices."); + + public static final BooleanFlag FOLDABLE_WORKSPACE_REORDER = getDebugFlag(270395070, + "FOLDABLE_WORKSPACE_REORDER", DISABLED, + "In foldables, when reordering the icons and widgets, is now going to use both sides"); + + public static final BooleanFlag FOLDABLE_SINGLE_PAGE = getDebugFlag(270395274, + "FOLDABLE_SINGLE_PAGE", ENABLED, "Use a single page for the workspace"); + public static final BooleanFlag ENABLE_PARAMETRIZE_REORDER = getDebugFlag(289420844, "ENABLE_PARAMETRIZE_REORDER", DISABLED, "Enables generating the reorder using a set of parameters"); diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 438a4a02e7..5306932f76 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -17,6 +17,7 @@ package com.android.launcher3.testing; import static com.android.launcher3.allapps.AllAppsStore.DEFER_UPDATES_TEST; import static com.android.launcher3.config.FeatureFlags.ENABLE_TRACKPAD_GESTURE; +import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import android.annotation.TargetApi; @@ -156,7 +157,8 @@ public class TestInformationHandler implements ResourceBasedOverride { return response; case TestProtocol.REQUEST_IS_TWO_PANELS: - response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, false); + response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, + FOLDABLE_SINGLE_PAGE.get() ? false : mDeviceProfile.isTwoPanels); return response; case TestProtocol.REQUEST_GET_HAD_NONTEST_EVENTS: