Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dbf577af authored by Andras Kloczl's avatar Andras Kloczl
Browse files

Add left widget panel to Launcher home when unfolded

Test: manual
Bug: 175939730
Change-Id: I9831e7fa95084db12953ec7cb2eb725e7549e01d
parent 024262cc
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -1180,6 +1180,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
        // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
        // default state, otherwise we will update to the wrong offsets in RTL
        mWorkspace.lockWallpaperToDefaultPage();
        mWorkspace.bindAndInitLeftPanel();
        mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
        mDragController.addDragListener(mWorkspace);

@@ -2091,11 +2092,16 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche

    @Override
    public void bindScreens(IntArray orderedScreenIds) {
        // Make sure the first screen is always at the start.
        // 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(Workspace.LEFT_PANEL_ID);
        int firstScreenPosition = isLeftPanelShown && orderedScreenIds.size() > 1 ? 1 : 0;

        if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
                orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
                orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != firstScreenPosition) {
            orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
            orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
            orderedScreenIds.add(firstScreenPosition, Workspace.FIRST_SCREEN_ID);
        } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
            // If there are no screens, we need to have an empty screen
            mWorkspace.addExtraEmptyScreen();
@@ -2112,10 +2118,17 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
        int count = orderedScreenIds.size();
        for (int i = 0; i < count; i++) {
            int screenId = orderedScreenIds.get(i);
            if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
            if (FeatureFlags.QSB_ON_FIRST_SCREEN && screenId == Workspace.FIRST_SCREEN_ID) {
                // No need to bind the first screen, as its always bound.
                mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
                continue;
            }

            if (screenId == Workspace.LEFT_PANEL_ID) {
                // No need to bind the left panel, as its always bound.
                continue;
            }

            mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
        }
    }

@@ -2190,6 +2203,11 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
                continue;
            }

            // Skip if the item is on the left widget panel but the panel is not shown
            if (item.screenId == Workspace.LEFT_PANEL_ID && !getDeviceProfile().isTwoPanels) {
                continue;
            }

            final View view;
            switch (item.itemType) {
                case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3;

import static androidx.annotation.VisibleForTesting.PACKAGE_PRIVATE;

import static com.android.launcher3.anim.Interpolators.SCROLL;
import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled;
import static com.android.launcher3.compat.AccessibilityManagerCompat.isObservedEventType;
+54 −11
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3;

import static androidx.annotation.VisibleForTesting.PROTECTED;

import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
import static com.android.launcher3.LauncherState.ALL_APPS;
@@ -315,9 +316,17 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        // Increase our bottom insets so we don't overlap with the taskbar.
        mInsets.bottom += grid.nonOverlappingTaskbarInset;

        if (isTwoPanelEnabled()) {
        if (grid.isTwoPanels) {
            setPageSpacing(0); // we have two pages and we don't want any spacing
        } else if (mWorkspaceFadeInAdjacentScreens) {

            // Add left widget panel if it isn't already there
            if (!mWorkspaceScreens.containsKey(LEFT_PANEL_ID)) {
                int newCurrentPage = mCurrentPage + 1;
                bindAndInitLeftPanel();
                setCurrentPage(newCurrentPage);
            }
        } else {
            if (mWorkspaceFadeInAdjacentScreens) {
                // In landscape mode the page spacing is set to the default.
                setPageSpacing(grid.edgeMarginPx);
            } else {
@@ -329,6 +338,14 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
                setPageSpacing(Math.max(maxInsets, maxPadding));
            }

            // Remove left widget panel if it is present
            if (mWorkspaceScreens.containsKey(LEFT_PANEL_ID)) {
                int newCurrentPage = mCurrentPage - 1;
                removeLeftPanel();
                setCurrentPage(newCurrentPage);
            }
        }

        int paddingLeftRight = grid.cellLayoutPaddingLeftRightPx;
        int paddingBottom = grid.cellLayoutBottomPaddingPx;
        int twoPanelLandscapeSidePadding = paddingLeftRight * 2;
@@ -557,7 +574,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
            return;
        }
        // Add the first page
        CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, 0);
        CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount());
        // Always add a QSB on the first screen.
        if (qsb == null) {
            // In transposed layout, we add the QSB in the Grid. As workspace does not touch the
@@ -576,6 +593,19 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        }
    }

    /**
     * Initializes and binds the left panel
     */
    public void bindAndInitLeftPanel() {
        if (!FeatureFlags.QSB_ON_FIRST_SCREEN || !isTwoPanelEnabled()
                || mWorkspaceScreens.containsKey(Workspace.LEFT_PANEL_ID)) {
            return;
        }

        insertNewWorkspaceScreen(Workspace.LEFT_PANEL_ID, getChildCount());
        mLauncher.getModelWriter().setLeftPanelShown(true);
    }

    public void removeAllWorkspaceScreens() {
        // Disable all layout transitions before removing all pages to ensure that we don't get the
        // transition animations competing with us changing the scroll when we add pages
@@ -597,6 +627,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);

        // Ensure that the first page is always present
        bindAndInitLeftPanel();
        bindAndInitFirstWorkspaceScreen(qsb);

        // Re-enable the layout transitions
@@ -617,6 +648,18 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        insertNewWorkspaceScreen(screenId, getChildCount());
    }

    private void removeLeftPanel() {
        if (!mWorkspaceScreens.containsKey(LEFT_PANEL_ID)) {
            return;
        }
        mLauncher.getModelWriter().setLeftPanelShown(false);
        CellLayout leftPanel = mWorkspaceScreens.get(LEFT_PANEL_ID);
        mWorkspaceScreens.remove(LEFT_PANEL_ID);
        removeView(leftPanel);
        mScreenOrder.removeValue(LEFT_PANEL_ID);
        updatePageScrollValues();
    }

    public CellLayout insertNewWorkspaceScreen(int screenId, int insertIndex) {
        if (mWorkspaceScreens.containsKey(screenId)) {
            throw new RuntimeException("Screen id " + screenId + " already exists!");
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ 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.
+13 −0
Original line number Diff line number Diff line
@@ -116,6 +116,11 @@ public class BgDataModel {
     */
    public int lastBindId = 0;

    /**
     * Value that indicates if left widget panel is shown or not.
     */
    public boolean isLeftPanelShown = false;

    /**
     * Clears all the data
     */
@@ -141,6 +146,14 @@ public class BgDataModel {
        if (FeatureFlags.QSB_ON_FIRST_SCREEN || screenSet.isEmpty()) {
            screenSet.add(Workspace.FIRST_SCREEN_ID);
        }

        if (isLeftPanelShown) {
            // We should add it even though there are no items on it.
            screenSet.add(Workspace.LEFT_PANEL_ID);
        } else {
            // We should NOT add it even though there are items on it.
            screenSet.remove(Workspace.LEFT_PANEL_ID);
        }
        return screenSet.getArray();
    }

Loading