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

Commit 6cda0122 authored by Kshitij's avatar Kshitij
Browse files

feat: Introduce grid transpose and dimension swapping

parent 521d9677
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
     */
    public int numRows;
    public int numColumns;
    public int numRowsFixed;
    public int numColumnsFixed;
    public int numSearchContainerColumns;

    /**
@@ -364,7 +366,9 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
        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;
@@ -634,6 +638,8 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
            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] =
+5 −1
Original line number Diff line number Diff line
@@ -800,9 +800,13 @@ 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);
            } else {
                mCellPosMapper = CellPosMapper.DEFAULT;
            }
        }
        mModelWriter = mModel.getWriter(getDeviceProfile().isVerticalBarLayout(), true,
                mCellPosMapper, this);
        return true;
+7 −0
Original line number Diff line number Diff line
@@ -458,6 +458,13 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
                    ? widgetPadding : (padding.left + hotseatLeftCorrection);
            int paddingRight = (s == 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;
            }
            s.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
        });
    }
+39 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.celllayout;

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

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

import java.util.Objects;
@@ -45,6 +46,44 @@ 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) {
            this.mIDP = idp;
        }

        /**
         * Maps the position in model to the position in view
         */
        public CellPos mapModelToPresenter(ItemInfo info) {
            if (info.container != 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 != 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
@@ -120,11 +120,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.
@@ -186,6 +188,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;
@@ -245,6 +249,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);