From 1e4484669d51179afd248e82cc9caa7793fd014e Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Fri, 13 Aug 2021 21:48:35 +0100 Subject: [PATCH] Remove widget panel - Remove all usage of LEFT_PANEL_ID and fixed left panel code - For preview renderer, load screen 0 + screen 1 instead - Added a split display specific default workspace layout, with a placeholder app to pass test before we implement page pairing(b/196376162) - Known issue: If screenId 1 is deleted, right panel will disappear from Wallpaepr & Style because there is no screenId 1. Will be resovled after page pairing(b/196376162) Bug: 175939730 Test: manual and TaplTestsLauncher3#testWorkSpace Change-Id: Icac1c94165c14a49c17897c45355b6cdc4d87e91 --- .../launcher_preview_two_panel_layout.xml | 8 ++--- res/values/attrs.xml | 1 + res/xml/default_workspace_5x5.xml | 10 +++++++ src/com/android/launcher3/DeviceProfile.java | 2 +- .../launcher3/InvariantDeviceProfile.java | 6 ++-- src/com/android/launcher3/Launcher.java | 29 ++----------------- src/com/android/launcher3/PagedView.java | 4 +-- src/com/android/launcher3/Workspace.java | 3 -- .../launcher3/WorkspaceLayoutManager.java | 2 -- .../LauncherAccessibilityDelegate.java | 3 +- .../graphics/LauncherPreviewRenderer.java | 22 +++++++------- .../graphics/PreviewSurfaceRenderer.java | 12 ++++++-- .../model/AddWorkspaceItemsTask.java | 3 +- .../model/GridSizeMigrationTaskV2.java | 4 --- .../android/launcher3/model/LoaderTask.java | 5 ---- 15 files changed, 47 insertions(+), 67 deletions(-) diff --git a/res/layout/launcher_preview_two_panel_layout.xml b/res/layout/launcher_preview_two_panel_layout.xml index 7b227e0345..f76fc5a337 100644 --- a/res/layout/launcher_preview_two_panel_layout.xml +++ b/res/layout/launcher_preview_two_panel_layout.xml @@ -25,24 +25,24 @@ android:layout_height="match_parent"> + diff --git a/res/xml/default_workspace_5x5.xml b/res/xml/default_workspace_5x5.xml index ccdde2ca80..162367be86 100644 --- a/res/xml/default_workspace_5x5.xml +++ b/res/xml/default_workspace_5x5.xml @@ -94,4 +94,14 @@ + + + + + + + diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index eb058e8df4..8f83a15b21 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -790,7 +790,7 @@ public class DeviceProfile { Point padding = getTotalWorkspacePadding(); // availableWidthPx is the screen width of the device. In 2 panels mode, each panel should // only have half of the screen width. In addition, there is only cellLayoutPadding in the - // left side of the left panel and the right side of the right panel. There is no + // left side of the left most panel and the right most side of the right panel. There is no // cellLayoutPadding in the middle. int screenWidthPx = isTwoPanels ? availableWidthPx / 2 - padding.x - cellLayoutPaddingLeftRightPx diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 1fc895822f..2e1482384f 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -653,8 +653,10 @@ public class InvariantDeviceProfile { numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); - defaultLayoutId = a.getResourceId( - R.styleable.GridDisplayOption_defaultLayoutId, 0); + defaultLayoutId = a.getResourceId(isSplitDisplay && a.hasValue( + R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId) + ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId + : R.styleable.GridDisplayOption_defaultLayoutId, 0); demoModeLayoutId = a.getResourceId( R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 1ebfda18ff..4d5cc5ee4a 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -36,7 +36,6 @@ import static com.android.launcher3.LauncherState.NO_OFFSET; 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.WorkspaceLayoutManager.LEFT_PANEL_ID; import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.getSupportedActions; import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND; @@ -2099,19 +2098,12 @@ public class Launcher extends StatefulActivity implements Launche ? mWorkspace.getCurrentPageScreenIds() : mPagesToBindSynchronously; IntArray actualIds = new IntArray(); - if (mDeviceProfile.isTwoPanels) { - actualIds.add(LEFT_PANEL_ID); - } else { - visibleIds.remove(LEFT_PANEL_ID); - } IntSet result = new IntSet(); if (visibleIds.isEmpty()) { return result; } for (int id : orderedScreenIds.toArray()) { - if (id != LEFT_PANEL_ID) { - actualIds.add(id); - } + actualIds.add(id); } int firstId = visibleIds.getArray().get(0); if (actualIds.contains(firstId)) { @@ -2119,7 +2111,7 @@ public class Launcher extends StatefulActivity implements Launche if (mDeviceProfile.isTwoPanels) { int index = actualIds.indexOf(firstId); - int nextIndex = ((int) (index / 2)) * 2; + int nextIndex = (index / 2) * 2; if (nextIndex == index) { nextIndex++; } @@ -2176,12 +2168,7 @@ public class Launcher extends StatefulActivity implements Launche @Override public void bindScreens(IntArray orderedScreenIds) { - // Make sure the first screen is at the start if there's no widget panel, - // or on the second place if the first is the widget panel - boolean isLeftPanelShown = - mWorkspace.mWorkspaceScreens.containsKey(LEFT_PANEL_ID); - int firstScreenPosition = isLeftPanelShown && orderedScreenIds.size() > 1 ? 1 : 0; - + int firstScreenPosition = 0; if (FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != firstScreenPosition) { orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID); @@ -2207,11 +2194,6 @@ public class Launcher extends StatefulActivity implements Launche continue; } - if (screenId == LEFT_PANEL_ID) { - // No need to bind the left panel, as its always bound. - continue; - } - mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId); } } @@ -2287,11 +2269,6 @@ public class Launcher extends StatefulActivity implements Launche continue; } - // Skip if the item is on the left widget panel but the panel is not shown - if (item.screenId == LEFT_PANEL_ID && !getDeviceProfile().isTwoPanels) { - continue; - } - final View view; switch (item.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index eb3f94ce7c..696e89716f 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -289,7 +289,7 @@ public abstract class PagedView extends ViewGrou newPage = Utilities.boundToRange(newPage, 0, getPageCount() - 1); if (getPanelCount() > 1) { - // Always return left panel as new page + // Always return left most panel as new page newPage = getLeftmostVisiblePageForIndex(newPage); } return newPage; @@ -774,7 +774,7 @@ public abstract class PagedView extends ViewGrou 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 + // In case we have multiple panels, always use left most panel's page scroll for all // panels on the screen. int adjustedScroll = outPageScrolls[getLeftmostVisiblePageForIndex(i)]; if (outPageScrolls[i] != adjustedScroll) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 3bfa1e2d2e..d162abdecc 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -550,9 +550,6 @@ public class Workspace extends PagedView if (!FeatureFlags.QSB_ON_FIRST_SCREEN) { return; } - if (isTwoPanelEnabled()) { - insertNewWorkspaceScreen(Workspace.LEFT_PANEL_ID, getChildCount()); - } // Add the first page CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount()); diff --git a/src/com/android/launcher3/WorkspaceLayoutManager.java b/src/com/android/launcher3/WorkspaceLayoutManager.java index 326e3c343a..d6302ce580 100644 --- a/src/com/android/launcher3/WorkspaceLayoutManager.java +++ b/src/com/android/launcher3/WorkspaceLayoutManager.java @@ -32,8 +32,6 @@ public interface WorkspaceLayoutManager { int EXTRA_EMPTY_SCREEN_ID = -201; // The is the first screen. It is always present, even if its empty. int FIRST_SCREEN_ID = 0; - // This panel is shown on the first page if the panel count is greater than 1. - int LEFT_PANEL_ID = -777; /** * At bind time, we use the rank (screenId) to compute x and y for hotseat items. diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index 0fb5e778d0..9faac5b7ef 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -188,8 +188,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme private boolean itemSupportsAccessibleDrag(ItemInfo item) { if (item instanceof WorkspaceItemInfo) { // Support the action unless the item is in a context menu. - return (item.screenId >= 0 || item.screenId == Workspace.LEFT_PANEL_ID) - && item.container != Favorites.CONTAINER_HOTSEAT_PREDICTION; + return item.screenId >= 0 && item.container != Favorites.CONTAINER_HOTSEAT_PREDICTION; } return (item instanceof LauncherAppWidgetInfo) || (item instanceof FolderInfo); diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 55995f2f66..a96de31241 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -266,22 +266,22 @@ public class LauncherPreviewRenderer extends ContextWrapper mHotseat = mRootView.findViewById(R.id.hotseat); mHotseat.resetLayout(false); - if (mDp.isTwoPanels) { - CellLayout leftPanel = mRootView.findViewById(R.id.workspace_left); - leftPanel.setPadding(mDp.workspacePadding.left + mDp.cellLayoutPaddingLeftRightPx, - mDp.workspacePadding.top, - mDp.workspacePadding.right, - mDp.workspacePadding.bottom); - mWorkspaceScreens.put(LEFT_PANEL_ID, leftPanel); - } - CellLayout firstScreen = mRootView.findViewById(R.id.workspace); - firstScreen.setPadding(mDp.workspacePadding.left, + firstScreen.setPadding(mDp.workspacePadding.left + mDp.cellLayoutPaddingLeftRightPx, mDp.workspacePadding.top, - mDp.workspacePadding.right + mDp.cellLayoutPaddingLeftRightPx, + mDp.workspacePadding.right, mDp.workspacePadding.bottom); mWorkspaceScreens.put(FIRST_SCREEN_ID, firstScreen); + if (mDp.isTwoPanels) { + CellLayout rightPanel = mRootView.findViewById(R.id.workspace_right); + rightPanel.setPadding(mDp.workspacePadding.left, + mDp.workspacePadding.top, + mDp.workspacePadding.right + mDp.cellLayoutPaddingLeftRightPx, + mDp.workspacePadding.bottom); + mWorkspaceScreens.put(PreviewSurfaceRenderer.SECOND_SCREEN_ID, rightPanel); + } + if (Utilities.ATLEAST_S) { WallpaperColors wallpaperColors = wallpaperColorsOverride != null ? wallpaperColorsOverride diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index c7448dc00a..f7dd6b217d 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -67,6 +67,9 @@ public class PreviewSurfaceRenderer { private static final int FADE_IN_ANIMATION_DURATION = 200; + // The is the second screen. It is always present in two panel, even if its empty. + static final int SECOND_SCREEN_ID = 1; + private static final String KEY_HOST_TOKEN = "host_token"; private static final String KEY_VIEW_WIDTH = "width"; private static final String KEY_VIEW_HEIGHT = "height"; @@ -164,11 +167,14 @@ public class PreviewSurfaceRenderer { @Override public void run() { DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext); - String query = (deviceProfile.isTwoPanels ? LauncherSettings.Favorites.SCREEN - + " = " + Workspace.LEFT_PANEL_ID + " or " : "") - + LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + String query = + LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT; + if (deviceProfile.isTwoPanels) { + query += " or " + LauncherSettings.Favorites.SCREEN + " = " + + SECOND_SCREEN_ID; + } loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query); diff --git a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java index 4f12d0b8df..a13fa55dff 100644 --- a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java +++ b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java @@ -16,7 +16,6 @@ package com.android.launcher3.model; import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID; -import static com.android.launcher3.WorkspaceLayoutManager.LEFT_PANEL_ID; import android.content.Intent; import android.content.pm.LauncherActivityInfo; @@ -297,7 +296,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask { int screenCount = workspaceScreens.size(); // First check the preferred screen. - IntSet screensToExclude = IntSet.wrap(LEFT_PANEL_ID); + IntSet screensToExclude = new IntSet(); if (FeatureFlags.QSB_ON_FIRST_SCREEN) { screensToExclude.add(FIRST_SCREEN_ID); } diff --git a/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java b/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java index e64b25c0c9..e7d0749e9e 100644 --- a/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java +++ b/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java @@ -38,7 +38,6 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherSettings; import com.android.launcher3.Utilities; -import com.android.launcher3.Workspace; import com.android.launcher3.graphics.LauncherPreviewRenderer; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.pm.InstallSessionHelper; @@ -214,9 +213,6 @@ public class GridSizeMigrationTaskV2 { // Migrate workspace. // First we create a collection of the screens List screens = new ArrayList<>(); - if (idp.getDeviceProfile(mContext).isTwoPanels) { - screens.add(Workspace.LEFT_PANEL_ID); - } for (int screenId = 0; screenId <= mDestReader.mLastScreenId; screenId++) { screens.add(screenId); } diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 41a760b09b..f4a0eb89bd 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -16,7 +16,6 @@ package com.android.launcher3.model; -import static com.android.launcher3.WorkspaceLayoutManager.LEFT_PANEL_ID; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED; @@ -179,11 +178,7 @@ public class LoaderTask implements Runnable { // Screen set is never empty IntArray allScreens = mBgDataModel.collectWorkspaceScreens(); final int firstScreen = allScreens.get(0); - IntSet firstScreens = IntSet.wrap(firstScreen); - if (firstScreen == LEFT_PANEL_ID && allScreens.size() >= 2) { - firstScreens.add(allScreens.get(1)); - } filterCurrentWorkspaceItems(firstScreens, allItems, firstScreenItems, new ArrayList<>() /* otherScreenItems are ignored */);