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

Commit 07af3b06 authored by Jordan Silva's avatar Jordan Silva Committed by Android (Google) Code Review
Browse files

Merge "Update responsive grid spec cell size remainderSpace logic" into main

parents 040f9e94 2de6a277
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -189,6 +189,10 @@
         defaults to 2 * numAllAppsColumns -->
        <attr name="numExtendedAllAppsColumns" format="integer" />

        <!-- Number of rows to calculate the cell height for all apps when it's necessary.
          Defaults to numRows. Requires FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE to be enabled. -->
        <attr name="numAllAppsRowsForCellHeightCalculation" format="integer" />

        <!-- numHotseatIcons defaults to numColumns, if not specified -->
        <attr name="numHotseatIcons" format="integer" />
        <!-- Number of icons to use when extending the hotseat size,
+3 −3
Original line number Diff line number Diff line
@@ -640,8 +640,8 @@ public class DeviceProfile {
                    DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
                    mResponsiveWorkspaceWidthSpec);
            mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
                    DimensionType.HEIGHT, inv.numRows,  heightPx - mInsets.top,
                    mResponsiveWorkspaceHeightSpec);
                    DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
                    heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec);

            ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
                    new ResourceHelper(context,
@@ -1334,7 +1334,7 @@ public class DeviceProfile {

        if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
            if (isVerticalBarLayout()) {
                if (allAppsCellHeightPx < iconSizePx) {
                if (allAppsCellHeightPx < allAppsIconSizePx) {
                    cellContentDimensions.setIconSizePx(
                            mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
                }
+9 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public class InvariantDeviceProfile {
     * Number of columns in the all apps list.
     */
    public int numAllAppsColumns;
    public int numAllAppsRowsForCellHeightCalculation;
    public int numDatabaseAllAppsColumns;
    public @StyleRes int allAppsStyle;

@@ -393,6 +394,8 @@ public class InvariantDeviceProfile {
        workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
        allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
        allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
        numAllAppsRowsForCellHeightCalculation =
                closestProfile.mNumAllAppsRowsForCellHeightCalculation;
        this.deviceType = deviceType;

        inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
@@ -423,6 +426,7 @@ public class InvariantDeviceProfile {
        allAppsStyle = closestProfile.allAppsStyle;

        numAllAppsColumns = closestProfile.numAllAppsColumns;

        numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
                ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;

@@ -821,6 +825,7 @@ public class InvariantDeviceProfile {

        private final @StyleRes int allAppsStyle;
        private final int numAllAppsColumns;
        private final int mNumAllAppsRowsForCellHeightCalculation;
        private final int numDatabaseAllAppsColumns;
        private final int numHotseatIcons;
        private final int numDatabaseHotseatIcons;
@@ -971,6 +976,9 @@ public class InvariantDeviceProfile {
                mAllAppsCellSpecsTwoPanelId = a.getResourceId(
                        R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
                        INVALID_RESOURCE_HANDLE);
                mNumAllAppsRowsForCellHeightCalculation = a.getInt(
                        R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
                        numRows);
            } else {
                mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
                mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
@@ -984,6 +992,7 @@ public class InvariantDeviceProfile {
                mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
                mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
                mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
                mNumAllAppsRowsForCellHeightCalculation = numRows;
            }

            int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
+10 −9
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ data class ResponsiveSpec(
    val cellSize: SizeSpec,
) : IResponsiveSpec {
    init {
        check(isValid()) { "Invalid ResponsiveSpec found." }
        check(isValid()) { "Invalid ResponsiveSpec found. $this" }
    }

    constructor(
@@ -106,7 +106,7 @@ data class ResponsiveSpec(
        }

        if (!isValidRemainderSpace()) {
            logError("The total Remainder Space used must be lower or equal to 100%.")
            logError("The total Remainder Space used must be equal to 0 or 1.")
            return false
        }

@@ -131,11 +131,12 @@ data class ResponsiveSpec(
    }

    private fun isValidRemainderSpace(): Boolean {
        // TODO(b/313621277): This validation must be update do accept only 0 or 1 instead of <= 1f.
        return startPadding.ofRemainderSpace +
        val remainderSpaceUsed =
            startPadding.ofRemainderSpace +
                endPadding.ofRemainderSpace +
                gutter.ofRemainderSpace +
            cellSize.ofRemainderSpace <= 1f
                cellSize.ofRemainderSpace
        return remainderSpaceUsed == 0f || remainderSpaceUsed == 1f
    }

    private fun isValidAvailableSpace(): Boolean {
@@ -254,8 +255,8 @@ class CalculatedResponsiveSpec {

        startPaddingPx = spec.startPadding.getRemainderSpaceValue(remainderSpace, startPaddingPx)
        endPaddingPx = spec.endPadding.getRemainderSpaceValue(remainderSpace, endPaddingPx)
        gutterPx = spec.gutter.getRemainderSpaceValue(remainderSpace, gutterPx)
        cellSizePx = spec.cellSize.getRemainderSpaceValue(remainderSpace, cellSizePx)
        gutterPx = spec.gutter.getRemainderSpaceValue(remainderSpace, gutterPx, gutters)
        cellSizePx = spec.cellSize.getRemainderSpaceValue(remainderSpace, cellSizePx, cells)
    }

    override fun hashCode(): Int {
+7 −2
Original line number Diff line number Diff line
@@ -57,11 +57,16 @@ data class SizeSpec(
    /**
     * Calculates the [SizeSpec] value when remainder space value is defined. If no remainderSpace
     * is 0, returns a default value.
     *
     * @param remainderSpace The remainder space to be used for the calculation
     * @param defaultValue The default value to be returned when no ofRemainderSpace is defined
     * @param factor A number to divide the remainder space. The default value is 1. This property
     *   is used to split equally the remainder space by the number of cells and gutters.
     */
    fun getRemainderSpaceValue(remainderSpace: Int, defaultValue: Int): Int {
    fun getRemainderSpaceValue(remainderSpace: Int, defaultValue: Int, factor: Int = 1): Int {
        val remainderSpaceValue =
            if (ofRemainderSpace > 0) {
                (ofRemainderSpace * remainderSpace).roundToInt()
                (ofRemainderSpace * remainderSpace / factor).roundToInt()
            } else {
                defaultValue
            }
Loading