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

Verified Commit 2659679e authored by Kshitij's avatar Kshitij Committed by Saalim Quadri
Browse files

feat: Introduce grid transpose and dimension swapping

parent 5def899d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -133,6 +133,8 @@ public class InvariantDeviceProfile implements SafeCloseable, OnSharedPreference
     */
    public int numRows;
    public int numColumns;
    public int numRowsFixed;
    public int numColumnsFixed;
    public int numSearchContainerColumns;

    /**
@@ -430,7 +432,9 @@ public class InvariantDeviceProfile implements SafeCloseable, OnSharedPreference
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        GridOption closestProfile = displayOption.grid;
        numRows = closestProfile.numRows;
        numRowsFixed = closestProfile.numRows;
        numColumns = closestProfile.numColumns;
        numColumnsFixed = closestProfile.numColumns;
        numSearchContainerColumns = closestProfile.numSearchContainerColumns;
        dbFile = closestProfile.dbFile;
        defaultLayoutId = closestProfile.defaultLayoutId;
@@ -838,6 +842,8 @@ public class InvariantDeviceProfile implements SafeCloseable, OnSharedPreference
            if (numRows > 0 && numColumns > 0) {
                this.numRows = numRows;
                this.numColumns = numColumns;
                this.numRowsFixed = numRows;
                this.numColumnsFixed = numColumns;
            }
            if (iconSizePx > 0) {
                this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
+7 −2
Original line number Diff line number Diff line
@@ -883,10 +883,15 @@ public class Launcher extends StatefulActivity<LauncherState>
        onDeviceProfileInitiated();
        if (FOLDABLE_SINGLE_PAGE.get() && mDeviceProfile.isTwoPanels) {
            mCellPosMapper = new TwoPanelCellPosMapper(mDeviceProfile.inv.numColumns);
        } else {
            if (mDeviceProfile.isVerticalBarLayout()) {
                mCellPosMapper = new CellPosMapper.TransposeCellPosMapper(mDeviceProfile.inv,
                        mDeviceProfile.isVerticalBarLayout(), mDeviceProfile.numShownHotseatIcons);
            } else {
                mCellPosMapper = new CellPosMapper(mDeviceProfile.isVerticalBarLayout(),
                        mDeviceProfile.numShownHotseatIcons);
            }
        }
        mModelWriter = mModel.getWriter(true, mCellPosMapper, this);
        updateFixedLandscape();
        return true;
+9 −0
Original line number Diff line number Diff line
@@ -477,6 +477,15 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
                    ? widgetPadding : (padding.left + hotseatLeftCorrection);
            int paddingRight = (cellLayout == mWorkspaceScreens.get(FIRST_SCREEN_ID))
                    ? widgetPadding : (padding.right + hotseatRightCorrection);

            if (grid.isVerticalBarLayout()) {
                grid.inv.numRows = grid.inv.numColumnsFixed;
                grid.inv.numColumns = grid.inv.numRowsFixed;
            } else {
                grid.inv.numRows = grid.inv.numRowsFixed;
                grid.inv.numColumns = grid.inv.numColumnsFixed;
            }

            cellLayout.setSpaceBetweenCellLayoutsPx(getPageSpacing() / 4);
            cellLayout.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
        });
+42 −0
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@
package com.android.launcher3.celllayout;

import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT;

import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.model.data.ItemInfo;

import java.util.Objects;
@@ -55,6 +57,46 @@ public class CellPosMapper {
        return new CellPos(presenterX, presenterY, presenterScreen);
    }


    /**
     * Cell mapper which maps a portrait layout to landscape, maintaining sequence
     */
    public static class TransposeCellPosMapper extends CellPosMapper  {

        private final InvariantDeviceProfile mIDP;

        public TransposeCellPosMapper(InvariantDeviceProfile idp,
                boolean hasVerticalHotseat, int numOfHotseat) {
            super(hasVerticalHotseat, numOfHotseat);
            this.mIDP = idp;
        }

        /**
         * Maps the position in model to the position in view
         */
        public CellPos mapModelToPresenter(ItemInfo info) {
            if (info.container != Favorites.CONTAINER_DESKTOP) {
                return super.mapModelToPresenter(info);
            }
            final int numRows = mIDP.numRowsFixed;
            final int numColumns = mIDP.numColumnsFixed;
            final int index = (info.cellY * numColumns) + info.cellX;
            return new CellPos(index % numRows, index / numRows, info.screenId);
        }

        @Override
        public CellPos mapPresenterToModel(int presenterX, int presenterY, int presenterScreen,
                                           int container) {
            if (container != Favorites.CONTAINER_DESKTOP) {
                super.mapPresenterToModel(presenterX, presenterY, presenterScreen, container);
            }
            final int numRows = mIDP.numRowsFixed;
            final int numColumns = mIDP.numColumnsFixed;
            final int index = (presenterY * numColumns) + presenterX;
            return new CellPos(index % numRows, index / numRows, presenterScreen);
        }
    }

    /**
     * Cell mapper which maps two panels into a single layout
     */
+6 −0
Original line number Diff line number Diff line
@@ -130,11 +130,13 @@ public class ItemInfo {
     * Indicates the X position of the associated cell.
     */
    public int cellX = -1;
    public int cellXFixed = -1;

    /**
     * Indicates the Y position of the associated cell.
     */
    public int cellY = -1;
    public int cellYFixed = -1;

    /**
     * Indicates the X cell span.
@@ -209,6 +211,8 @@ public class ItemInfo {
        title = info.title;
        cellX = info.cellX;
        cellY = info.cellY;
        cellXFixed = info.cellX;
        cellYFixed = info.cellY;
        spanX = info.spanX;
        spanY = info.spanY;
        minSpanX = info.minSpanX;
@@ -274,6 +278,8 @@ public class ItemInfo {
        screenId = values.getAsInteger(LauncherSettings.Favorites.SCREEN);
        cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
        cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
        cellXFixed = values.getAsInteger(LauncherSettings.Favorites.CELLX);
        cellYFixed = values.getAsInteger(LauncherSettings.Favorites.CELLY);
        spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
        spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY);
        rank = values.getAsInteger(LauncherSettings.Favorites.RANK);