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

Commit 78d00adc authored by Thales Lima's avatar Thales Lima
Browse files

launcher: create more space options

The grid doesn't have a constant space between cells anymore, so we need
new attributes for the different spaces in different situations.

Bug: 191879424
Test: checking cell size and extra space in dumpsys
Change-Id: I4b6aae5b3fea281490c00cd13d0cd3a25372f21b
parent bfb69964
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -191,7 +191,32 @@
        if not specified -->
        <attr name="twoPanelLandscapeMinCellWidthDps" format="float" />

        <attr name="borderSpacingDps" format="float" />
        <!-- These border spaces are only used if GridDisplayOption#isScalable is true -->
        <!-- space to be used horizontally and vertically -->
        <attr name="borderSpaceDps" format="float" />
        <!-- space to the right of the cell, defaults to borderSpaceDps if not specified -->
        <attr name="borderSpaceHorizontalDps" format="float" />
        <!-- space below the cell, defaults to borderSpaceDps if not specified -->
        <attr name="borderSpaceVerticalDps" format="float" />
        <!-- space to be used horizontally and vertically in two panels,
        defaults to borderSpaceDps if not specified -->
        <attr name="twoPanelPortraitBorderSpaceDps" format="float" />
        <!-- space to the right of the cell in two panels, defaults to
        twoPanelPortraitBorderSpaceDps if not specified -->
        <attr name="twoPanelPortraitBorderSpaceHorizontalDps" format="float" />
        <!-- space below the cell in two panels, defaults to twoPanelPortraitBorderSpaceDps
        if not specified -->
        <attr name="twoPanelPortraitBorderSpaceVerticalDps" format="float" />
        <!-- space to be used horizontally and vertically in two panels,
        defaults to borderSpaceDps if not specified -->
        <attr name="twoPanelLandscapeBorderSpaceDps" format="float" />
        <!-- space to the right of the cell in two panels, defaults to
        twoPanelLandscapeBorderSpaceDps if not specified -->
        <attr name="twoPanelLandscapeBorderSpaceHorizontalDps" format="float" />
        <!-- space below the cell in two panels, defaults to twoPanelLandscapeBorderSpaceDps
        if not specified -->
        <attr name="twoPanelLandscapeBorderSpaceVerticalDps" format="float" />


        <attr name="allAppsCellSpacingDps" format="float" />

+4 −4
Original line number Diff line number Diff line
@@ -422,8 +422,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
     */
    private void resizeWidgetIfNeeded(boolean onDismiss) {
        DeviceProfile dp = mLauncher.getDeviceProfile();
        float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacingPx;
        float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacingPx;
        float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
        float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;

        int hSpanInc = getSpanIncrement((mDeltaX + mDeltaXAddOn) / xThreshold - mRunningHInc);
        int vSpanInc = getSpanIncrement((mDeltaY + mDeltaYAddOn) / yThreshold - mRunningVInc);
@@ -508,8 +508,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O

    private void onTouchUp() {
        DeviceProfile dp = mLauncher.getDeviceProfile();
        int xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacingPx;
        int yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacingPx;
        int xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
        int yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;

        mDeltaXAddOn = mRunningHInc * xThreshold;
        mDeltaYAddOn = mRunningVInc * yThreshold;
+31 −31
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class CellLayout extends ViewGroup {
    private int mFixedCellWidth;
    private int mFixedCellHeight;
    @ViewDebug.ExportedProperty(category = "launcher")
    private final int mBorderSpacing;
    private final Point mBorderSpace;

    @ViewDebug.ExportedProperty(category = "launcher")
    private int mCountX;
@@ -236,9 +236,9 @@ public class CellLayout extends ViewGroup {
        mActivity = ActivityContext.lookupContext(context);
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();

        mBorderSpacing = mContainerType == FOLDER
                ? deviceProfile.folderCellLayoutBorderSpacingPx
                : deviceProfile.cellLayoutBorderSpacingPx;
        mBorderSpace = mContainerType == FOLDER
                ? new Point(deviceProfile.folderCellLayoutBorderSpacePx)
                : new Point(deviceProfile.cellLayoutBorderSpacePx);

        mCellWidth = mCellHeight = -1;
        mFixedCellWidth = mFixedCellHeight = -1;
@@ -308,7 +308,7 @@ public class CellLayout extends ViewGroup {

        mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context, mContainerType);
        mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
                mBorderSpacing);
                mBorderSpace);
        addView(mShortcutsAndWidgets);
    }

@@ -368,7 +368,7 @@ public class CellLayout extends ViewGroup {
        mFixedCellWidth = mCellWidth = width;
        mFixedCellHeight = mCellHeight = height;
        mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
                mBorderSpacing);
                mBorderSpace);
    }

    public void setGridSize(int x, int y) {
@@ -378,7 +378,7 @@ public class CellLayout extends ViewGroup {
        mTmpOccupied = new GridOccupancy(mCountX, mCountY);
        mTempRectStack.clear();
        mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
                mBorderSpacing);
                mBorderSpace);
        requestLayout();
    }

@@ -541,9 +541,9 @@ public class CellLayout extends ViewGroup {
        if (mVisualizeCells) {
            for (int i = 0; i < mCountX; i++) {
                for (int j = 0; j < mCountY; j++) {
                    int transX = i * mCellWidth + (i * mBorderSpacing) + getPaddingLeft()
                    int transX = i * mCellWidth + (i * mBorderSpace.x) + getPaddingLeft()
                            + paddingX;
                    int transY = j * mCellHeight + (j * mBorderSpacing) + getPaddingTop()
                    int transY = j * mCellHeight + (j * mBorderSpace.y) + getPaddingTop()
                            + paddingY;

                    mVisualizeGridRect.offsetTo(transX, transY);
@@ -567,12 +567,12 @@ public class CellLayout extends ViewGroup {

                // TODO b/194414754 clean this up, reconcile with cellToRect
                mVisualizeGridRect.set(paddingX, paddingY,
                        mCellWidth * spanX + mBorderSpacing * (spanX - 1) - paddingX,
                        mCellHeight * spanY + mBorderSpacing * (spanY - 1) - paddingY);
                        mCellWidth * spanX + mBorderSpace.x * (spanX - 1) - paddingX,
                        mCellHeight * spanY + mBorderSpace.y * (spanY - 1) - paddingY);

                int transX = x * mCellWidth + (x * mBorderSpacing)
                int transX = x * mCellWidth + (x * mBorderSpace.x)
                        + getPaddingLeft() + paddingX;
                int transY = y * mCellHeight + (y * mBorderSpacing)
                int transY = y * mCellHeight + (y * mBorderSpace.y)
                        + getPaddingTop() + paddingY;

                mVisualizeGridRect.offsetTo(transX, transY);
@@ -858,15 +858,15 @@ public class CellLayout extends ViewGroup {
        int childHeightSize = heightSize - (getPaddingTop() + getPaddingBottom());

        if (mFixedCellWidth < 0 || mFixedCellHeight < 0) {
            int cw = DeviceProfile.calculateCellWidth(childWidthSize, mBorderSpacing,
            int cw = DeviceProfile.calculateCellWidth(childWidthSize, mBorderSpace.x,
                    mCountX);
            int ch = DeviceProfile.calculateCellHeight(childHeightSize, mBorderSpacing,
            int ch = DeviceProfile.calculateCellHeight(childHeightSize, mBorderSpace.y,
                    mCountY);
            if (cw != mCellWidth || ch != mCellHeight) {
                mCellWidth = cw;
                mCellHeight = ch;
                mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY,
                        mBorderSpacing);
                        mBorderSpace);
            }
        }

@@ -920,7 +920,7 @@ public class CellLayout extends ViewGroup {
     */
    public int getUnusedHorizontalSpace() {
        return getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth)
                - ((mCountX - 1) * mBorderSpacing);
                - ((mCountX - 1) * mBorderSpace.x);
    }

    @Override
@@ -2592,11 +2592,11 @@ public class CellLayout extends ViewGroup {
                + (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
        final int vStartPadding = getPaddingTop();

        int x = hStartPadding + (cellX * mBorderSpacing) + (cellX * cellWidth);
        int y = vStartPadding + (cellY * mBorderSpacing) + (cellY * cellHeight);
        int x = hStartPadding + (cellX * mBorderSpace.x) + (cellX * cellWidth);
        int y = vStartPadding + (cellY * mBorderSpace.y) + (cellY * cellHeight);

        int width = cellHSpan * cellWidth + ((cellHSpan - 1) * mBorderSpacing);
        int height = cellVSpan * cellHeight + ((cellVSpan - 1) * mBorderSpacing);
        int width = cellHSpan * cellWidth + ((cellHSpan - 1) * mBorderSpace.x);
        int height = cellVSpan * cellHeight + ((cellVSpan - 1) * mBorderSpace.y);

        resultRect.set(x, y, x + width, y + height);
    }
@@ -2615,12 +2615,12 @@ public class CellLayout extends ViewGroup {

    public int getDesiredWidth() {
        return getPaddingLeft() + getPaddingRight() + (mCountX * mCellWidth)
                + ((mCountX - 1) * mBorderSpacing);
                + ((mCountX - 1) * mBorderSpace.x);
    }

    public int getDesiredHeight()  {
        return getPaddingTop() + getPaddingBottom() + (mCountY * mCellHeight)
                + ((mCountY - 1) * mBorderSpacing);
                + ((mCountY - 1) * mBorderSpace.y);
    }

    public boolean isOccupied(int x, int y) {
@@ -2736,20 +2736,20 @@ public class CellLayout extends ViewGroup {
        }

        public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
                int rowCount, int borderSpacing, @Nullable Rect inset) {
                int rowCount, Point borderSpace, @Nullable Rect inset) {
            setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, 1.0f, 1.0f,
                    borderSpacing, inset);
                    borderSpace, inset);
        }

        /**
         * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, int, Rect)},
         * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, Point, Rect)},
         * if the view needs to be scaled.
         *
         * ie. In multi-window mode, we setup widgets so that they are measured and laid out
         * using their full/invariant device profile sizes.
         */
        public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
                int rowCount, float cellScaleX, float cellScaleY, int borderSpacing,
                int rowCount, float cellScaleX, float cellScaleY, Point borderSpace,
                @Nullable Rect inset) {
            if (isLockedToGrid) {
                final int myCellHSpan = cellHSpan;
@@ -2761,16 +2761,16 @@ public class CellLayout extends ViewGroup {
                    myCellX = colCount - myCellX - cellHSpan;
                }

                int hBorderSpacing = (myCellHSpan - 1) * borderSpacing;
                int vBorderSpacing = (myCellVSpan - 1) * borderSpacing;
                int hBorderSpacing = (myCellHSpan - 1) * borderSpace.x;
                int vBorderSpacing = (myCellVSpan - 1) * borderSpace.y;

                float myCellWidth = ((myCellHSpan * cellWidth) + hBorderSpacing) / cellScaleX;
                float myCellHeight = ((myCellVSpan * cellHeight) + vBorderSpacing) / cellScaleY;

                width = Math.round(myCellWidth) - leftMargin - rightMargin;
                height = Math.round(myCellHeight) - topMargin - bottomMargin;
                x = leftMargin + (myCellX * cellWidth) + (myCellX * borderSpacing);
                y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpacing);
                x = leftMargin + (myCellX * cellWidth) + (myCellX * borderSpace.x);
                y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpace.y);

                if (inset != null) {
                    x -= inset.left;
+62 −27
Original line number Diff line number Diff line
@@ -99,8 +99,8 @@ public class DeviceProfile {
    // Workspace
    public final int desiredWorkspaceHorizontalMarginOriginalPx;
    public int desiredWorkspaceHorizontalMarginPx;
    public final int cellLayoutBorderSpacingOriginalPx;
    public int cellLayoutBorderSpacingPx;
    public Point cellLayoutBorderSpaceOriginalPx;
    public Point cellLayoutBorderSpacePx;
    public final int cellLayoutPaddingLeftRightPx;
    public final int cellLayoutBottomPaddingPx;
    public final int edgeMarginPx;
@@ -137,7 +137,8 @@ public class DeviceProfile {
    public int folderIconOffsetYPx;

    // Folder content
    public int folderCellLayoutBorderSpacingPx;
    public Point folderCellLayoutBorderSpacePx;
    public int folderCellLayoutBorderSpaceOriginalPx;
    public int folderContentPaddingLeftRight;
    public int folderContentPaddingTop;

@@ -281,10 +282,12 @@ public class DeviceProfile {
                res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
        folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);

        setCellLayoutBorderSpacing(pxFromDp(inv.borderSpacing, mMetrics, 1f));
        cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
        allAppsCellSpacingPx = pxFromDp(inv.allAppsCellSpacing, mMetrics, 1f);
        cellLayoutBorderSpacingOriginalPx = cellLayoutBorderSpacingPx;
        folderCellLayoutBorderSpacingPx = cellLayoutBorderSpacingPx;
        cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
        folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics, 1f);
        folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
                folderCellLayoutBorderSpaceOriginalPx);

        int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
                ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
@@ -479,8 +482,33 @@ public class DeviceProfile {
        }
    }

    private void setCellLayoutBorderSpacing(int borderSpacing) {
        cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0;
    private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
        if (!isScalableGrid) {
            return new Point(0, 0);
        }

        int horizontalSpacePx;
        int verticalSpacePx;

        if (isTwoPanels) {
            if (isLandscape) {
                horizontalSpacePx = pxFromDp(idp.twoPanelLandscapeBorderSpace.x, mMetrics);
                verticalSpacePx = pxFromDp(idp.twoPanelLandscapeBorderSpace.y, mMetrics);
            } else {
                horizontalSpacePx = pxFromDp(idp.twoPanelPortraitBorderSpace.x, mMetrics);
                verticalSpacePx = pxFromDp(idp.twoPanelPortraitBorderSpace.y, mMetrics);
            }
        } else {
            horizontalSpacePx = pxFromDp(idp.borderSpace.x, mMetrics);
            verticalSpacePx = pxFromDp(idp.borderSpace.y, mMetrics);
        }

        return new Point(horizontalSpacePx, verticalSpacePx);
    }

    private Point getCellLayoutBorderSpaceScaled(InvariantDeviceProfile idp, float scale) {
        Point original = getCellLayoutBorderSpace(idp);
        return new Point((int) (original.x * scale), (int) (original.y * scale));
    }

    public Info getDisplayInfo() {
@@ -497,10 +525,10 @@ public class DeviceProfile {
        // Check all sides to ensure that the widget won't overlap into another cell, or into
        // status bar.
        return workspaceTopPadding > widgetPadding.top
                && cellLayoutBorderSpacingPx > widgetPadding.left
                && cellLayoutBorderSpacingPx > widgetPadding.top
                && cellLayoutBorderSpacingPx > widgetPadding.right
                && cellLayoutBorderSpacingPx > widgetPadding.bottom;
                && cellLayoutBorderSpacePx.x > widgetPadding.left
                && cellLayoutBorderSpacePx.y > widgetPadding.top
                && cellLayoutBorderSpacePx.x > widgetPadding.right
                && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
    }

    public Builder toBuilder(Context context) {
@@ -600,7 +628,7 @@ public class DeviceProfile {
            // devices.
            int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
            float usedWidth = (cellWidthPx * numColumns)
                    + (cellLayoutBorderSpacingPx * (numColumns - 1))
                    + (cellLayoutBorderSpacePx.x * (numColumns - 1))
                    + (desiredWorkspaceHorizontalMarginPx * 2);
            // We do not subtract padding here, as we also scale the workspace padding if needed.
            scaleX = availableWidthPx / usedWidth;
@@ -618,7 +646,7 @@ public class DeviceProfile {
    }

    private int getCellLayoutHeight() {
        return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacingPx * (inv.numRows - 1));
        return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1));
    }

    /**
@@ -658,7 +686,7 @@ public class DeviceProfile {
        iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
        iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);

        setCellLayoutBorderSpacing((int) (cellLayoutBorderSpacingOriginalPx * scale));
        cellLayoutBorderSpacePx = getCellLayoutBorderSpaceScaled(inv, scale);

        if (isScalableGrid) {
            PointF minCellHeightAndWidth = getMinCellHeightAndWidth();
@@ -757,14 +785,14 @@ public class DeviceProfile {

        // Check if the icons fit within the available height.
        float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
                + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacingPx);
                + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
        int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
                - folderMargin - folderContentPaddingTop;
        float scaleY = contentMaxHeight / contentUsedHeight;

        // Check if the icons fit within the available width.
        float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
                + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacingPx);
                + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
        int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
                - folderContentPaddingLeftRight * 2;
        float scaleX = contentMaxWidth / contentUsedWidth;
@@ -790,10 +818,10 @@ public class DeviceProfile {
            folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
            folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);

            int borderSpacing = (int) (cellLayoutBorderSpacingOriginalPx * scale);
            folderCellLayoutBorderSpacingPx = borderSpacing;
            folderContentPaddingLeftRight = borderSpacing;
            folderContentPaddingTop = borderSpacing;
            int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale);
            folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace);
            folderContentPaddingLeftRight = scaledSpace;
            folderContentPaddingTop = scaledSpace;
        } else {
            int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
                    * scale);
@@ -838,9 +866,9 @@ public class DeviceProfile {
        int cellLayoutTotalPadding =
                isTwoPanels ? 4 * cellLayoutPaddingLeftRightPx : 2 * cellLayoutPaddingLeftRightPx;
        int screenWidthPx = availableWidthPx - padding.x - cellLayoutTotalPadding;
        result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacingPx, numColumns);
        result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns);
        result.y = calculateCellHeight(availableHeightPx - padding.y
                - cellLayoutBottomPaddingPx, cellLayoutBorderSpacingPx, inv.numRows);
                - cellLayoutBottomPaddingPx, cellLayoutBorderSpacePx.y, inv.numRows);
        return result;
    }

@@ -1097,11 +1125,18 @@ public class DeviceProfile {
        writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
        writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
                folderChildDrawablePaddingPx));
        writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacingPx",
                folderCellLayoutBorderSpacingPx));
        writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx",
                folderCellLayoutBorderSpaceOriginalPx));
        writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
                folderCellLayoutBorderSpacePx.x));
        writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
                folderCellLayoutBorderSpacePx.y));

        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
                cellLayoutBorderSpacePx.x));
        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
                cellLayoutBorderSpacePx.y));

        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx",
                cellLayoutBorderSpacingPx));
        writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
                desiredWorkspaceHorizontalMarginPx));

+79 −26

File changed.

Preview size limit exceeded, changes collapsed.

Loading