Refactoring Responsive Grid XML specs for more flexibility

It merges portrait and landscape XML specs for responsive grid. This update allows the responsive grid to rely on other properties like aspect ratio and not solely the orientation from resource qualifiers.

Bug: 299889733
Flag: ACONFIG com.android.launcher3.enable_responsive_workspace TEAMFOOD
Test: CalculatedAllAppsSpecTest
Test: CalculatedFolderSpecTest
Test: CalculatedHotseatSpecTest
Test: CalculatedWorkspaceSpecTest
Test: AllAppsSpecsTest
Test: FolderSpecTest
Test: HotseatSpecsTest
Test: WorkspaceSpecsTest
Change-Id: I39ee54d49c9d2a54fcbe91c8a1327a21a8126032
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index f046eca..1a960f5 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -268,6 +268,10 @@
         <attr name="maxAvailableSize" format="dimension" />
     </declare-styleable>
 
+    <declare-styleable name="ResponsiveSpecGroup">
+        <attr name="maxAspectRatio" format="float" />
+    </declare-styleable>
+
     <declare-styleable name="WorkspaceSpec">
         <attr name="specType" />
         <attr name="maxAvailableSize" />
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 73cd8c4..2ed33ec 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -17,6 +17,7 @@
 package com.android.launcher3;
 
 import static com.android.app.animation.Interpolators.LINEAR;
+import static com.android.launcher3.Flags.enableOverviewIconMenu;
 import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
 import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
 import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
@@ -24,7 +25,6 @@
 import static com.android.launcher3.Utilities.dpiFromPx;
 import static com.android.launcher3.Utilities.pxFromSp;
 import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
-import static com.android.launcher3.Flags.enableOverviewIconMenu;
 import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
 import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
 import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
@@ -54,14 +54,12 @@
 import com.android.launcher3.icons.DotRenderer;
 import com.android.launcher3.icons.IconNormalizer;
 import com.android.launcher3.model.data.ItemInfo;
-import com.android.launcher3.responsive.AllAppsSpecs;
-import com.android.launcher3.responsive.CalculatedAllAppsSpec;
-import com.android.launcher3.responsive.CalculatedFolderSpec;
 import com.android.launcher3.responsive.CalculatedHotseatSpec;
-import com.android.launcher3.responsive.CalculatedWorkspaceSpec;
-import com.android.launcher3.responsive.FolderSpecs;
-import com.android.launcher3.responsive.HotseatSpecs;
-import com.android.launcher3.responsive.WorkspaceSpecs;
+import com.android.launcher3.responsive.CalculatedResponsiveSpec;
+import com.android.launcher3.responsive.HotseatSpecsProvider;
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType;
+import com.android.launcher3.responsive.ResponsiveSpec.DimensionType;
+import com.android.launcher3.responsive.ResponsiveSpecsProvider;
 import com.android.launcher3.uioverrides.ApiWrapper;
 import com.android.launcher3.util.CellContentDimensions;
 import com.android.launcher3.util.DisplayController;
@@ -84,7 +82,8 @@
 
     public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
     public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
-    public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
+    public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
+    };
 
     public final InvariantDeviceProfile inv;
     private final Info mInfo;
@@ -119,12 +118,12 @@
 
     // Responsive grid
     private final boolean mIsResponsiveGrid;
-    private CalculatedWorkspaceSpec mResponsiveWidthSpec;
-    private CalculatedWorkspaceSpec mResponsiveHeightSpec;
-    private CalculatedAllAppsSpec mAllAppsResponsiveWidthSpec;
-    private CalculatedAllAppsSpec mAllAppsResponsiveHeightSpec;
-    private CalculatedFolderSpec mResponsiveFolderWidthSpec;
-    private CalculatedFolderSpec mResponsiveFolderHeightSpec;
+    private CalculatedResponsiveSpec mResponsiveWidthSpec;
+    private CalculatedResponsiveSpec mResponsiveHeightSpec;
+    private CalculatedResponsiveSpec mAllAppsResponsiveWidthSpec;
+    private CalculatedResponsiveSpec mAllAppsResponsiveHeightSpec;
+    private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
+    private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
     private CalculatedHotseatSpec mResponsiveHotseatSpec;
 
     /**
@@ -376,7 +375,7 @@
                 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
         int transientTaskbarHeight =
                 Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
-                    + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
+                        + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
         mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin;
 
         if (!isTaskbarPresent) {
@@ -519,12 +518,15 @@
         int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
 
         if (mIsResponsiveGrid) {
-            HotseatSpecs hotseatSpecs =
-                    HotseatSpecs.create(new ResourceHelper(context,
+            float responsiveAspectRatio = (float) widthPx / heightPx;
+            HotseatSpecsProvider hotseatSpecsProvider =
+                    HotseatSpecsProvider.create(new ResourceHelper(context,
                             isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
             mResponsiveHotseatSpec =
-                    isVerticalBarLayout() ? hotseatSpecs.getCalculatedWidthSpec(widthPx)
-                            : hotseatSpecs.getCalculatedHeightSpec(heightPx);
+                    isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
+                            responsiveAspectRatio, DimensionType.WIDTH, widthPx)
+                            : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
+                                    DimensionType.HEIGHT, heightPx);
             hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
             hotseatBarBottomSpace =
                     isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
@@ -587,35 +589,46 @@
         // Needs to be calculated after hotseatBarSizePx is correct,
         // for the available height to be correct
         if (mIsResponsiveGrid) {
-            WorkspaceSpecs workspaceSpecs = WorkspaceSpecs.create(
-                    new ResourceHelper(context,
-                            isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId));
             int availableResponsiveWidth =
                     availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
             int numColumns = getPanelCount() * inv.numColumns;
             // don't use availableHeightPx because it subtracts mInsets.bottom
             int availableResponsiveHeight = heightPx - mInsets.top
-                            - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
-            mResponsiveWidthSpec = workspaceSpecs.getCalculatedWidthSpec(numColumns,
-                    availableResponsiveWidth);
-            mResponsiveHeightSpec = workspaceSpecs.getCalculatedHeightSpec(inv.numRows,
-                    availableResponsiveHeight);
+                    - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
+            float responsiveAspectRatio = (float) widthPx / heightPx;
 
-            AllAppsSpecs allAppsSpecs = AllAppsSpecs.create(
+            ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
                     new ResourceHelper(context,
-                            isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId));
-            mAllAppsResponsiveWidthSpec = allAppsSpecs.getCalculatedWidthSpec(numColumns,
-                    mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
-            mAllAppsResponsiveHeightSpec = allAppsSpecs.getCalculatedHeightSpec(inv.numRows,
-                    mResponsiveHeightSpec.getAvailableSpace(), mResponsiveHeightSpec);
+                            isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
+                    ResponsiveSpecType.Workspace);
+            mResponsiveWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
+                    DimensionType.WIDTH, numColumns, availableResponsiveWidth);
+            mResponsiveHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
+                    DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
 
-            FolderSpecs folderSpecs = FolderSpecs.create(
+            ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
                     new ResourceHelper(context,
-                            isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId));
-            mResponsiveFolderWidthSpec = folderSpecs.getCalculatedWidthSpec(inv.numFolderColumns,
-                    mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
-            mResponsiveFolderHeightSpec = folderSpecs.getCalculatedHeightSpec(inv.numFolderRows,
-                    mResponsiveHeightSpec.getAvailableSpace(), mResponsiveHeightSpec);
+                            isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
+                    ResponsiveSpecType.AllApps);
+            mAllAppsResponsiveWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
+                    DimensionType.WIDTH, numColumns, mResponsiveWidthSpec.getAvailableSpace(),
+                    mResponsiveWidthSpec);
+            mAllAppsResponsiveHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
+                    DimensionType.HEIGHT, inv.numRows, mResponsiveHeightSpec.getAvailableSpace(),
+                    mResponsiveHeightSpec);
+
+            ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
+                    new ResourceHelper(context,
+                            isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
+                    ResponsiveSpecType.Folder);
+            mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
+                    DimensionType.WIDTH, inv.numFolderColumns,
+                    mResponsiveWidthSpec.getAvailableSpace(),
+                    mResponsiveWidthSpec);
+            mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
+                    DimensionType.HEIGHT, inv.numFolderRows,
+                    mResponsiveHeightSpec.getAvailableSpace(),
+                    mResponsiveHeightSpec);
         }
 
         desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
diff --git a/src/com/android/launcher3/responsive/AllAppsSpecs.kt b/src/com/android/launcher3/responsive/AllAppsSpecs.kt
deleted file mode 100644
index 8ed3ffc..0000000
--- a/src/com/android/launcher3/responsive/AllAppsSpecs.kt
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.responsive
-
-import android.content.res.TypedArray
-import com.android.launcher3.R
-import com.android.launcher3.responsive.ResponsiveSpec.SpecType
-import com.android.launcher3.util.ResourceHelper
-
-class AllAppsSpecs(widthSpecs: List<AllAppsSpec>, heightSpecs: List<AllAppsSpec>) :
-    ResponsiveSpecs<AllAppsSpec>(widthSpecs, heightSpecs) {
-
-    fun getCalculatedWidthSpec(
-        columns: Int,
-        availableWidth: Int,
-        calculatedWorkspaceSpec: CalculatedWorkspaceSpec
-    ): CalculatedAllAppsSpec {
-        check(calculatedWorkspaceSpec.spec.specType == SpecType.WIDTH) {
-            "Invalid specType for CalculatedWorkspaceSpec. " +
-                "Expected: ${SpecType.WIDTH} - " +
-                "Found: ${calculatedWorkspaceSpec.spec.specType}}"
-        }
-
-        val spec = getWidthSpec(availableWidth)
-        return CalculatedAllAppsSpec(availableWidth, columns, spec, calculatedWorkspaceSpec)
-    }
-
-    fun getCalculatedHeightSpec(
-        rows: Int,
-        availableHeight: Int,
-        calculatedWorkspaceSpec: CalculatedWorkspaceSpec
-    ): CalculatedAllAppsSpec {
-        check(calculatedWorkspaceSpec.spec.specType == SpecType.HEIGHT) {
-            "Invalid specType for CalculatedWorkspaceSpec. " +
-                "Expected: ${SpecType.HEIGHT} - " +
-                "Found: ${calculatedWorkspaceSpec.spec.specType}}"
-        }
-
-        val spec = getHeightSpec(availableHeight)
-        return CalculatedAllAppsSpec(availableHeight, rows, spec, calculatedWorkspaceSpec)
-    }
-
-    companion object {
-        private const val XML_ALL_APPS_SPEC = "allAppsSpec"
-
-        @JvmStatic
-        fun create(resourceHelper: ResourceHelper): AllAppsSpecs {
-            val parser = ResponsiveSpecsParser(resourceHelper)
-            val specs = parser.parseXML(XML_ALL_APPS_SPEC, ::AllAppsSpec)
-            val (widthSpecs, heightSpecs) = specs.partition { it.specType == SpecType.WIDTH }
-            return AllAppsSpecs(widthSpecs, heightSpecs)
-        }
-    }
-}
-
-data class AllAppsSpec(
-    override val maxAvailableSize: Int,
-    override val specType: SpecType,
-    override val startPadding: SizeSpec,
-    override val endPadding: SizeSpec,
-    override val gutter: SizeSpec,
-    override val cellSize: SizeSpec
-) : ResponsiveSpec(maxAvailableSize, specType, startPadding, endPadding, gutter, cellSize) {
-
-    init {
-        check(isValid()) { "Invalid AllAppsSpec found." }
-    }
-
-    constructor(
-        attrs: TypedArray,
-        specs: Map<String, SizeSpec>
-    ) : this(
-        maxAvailableSize =
-            attrs.getDimensionPixelSize(R.styleable.ResponsiveSpec_maxAvailableSize, 0),
-        specType =
-            SpecType.values()[
-                    attrs.getInt(R.styleable.ResponsiveSpec_specType, SpecType.HEIGHT.ordinal)],
-        startPadding = specs.getOrError(SizeSpec.XmlTags.START_PADDING),
-        endPadding = specs.getOrError(SizeSpec.XmlTags.END_PADDING),
-        gutter = specs.getOrError(SizeSpec.XmlTags.GUTTER),
-        cellSize = specs.getOrError(SizeSpec.XmlTags.CELL_SIZE)
-    )
-}
-
-class CalculatedAllAppsSpec(
-    availableSpace: Int,
-    cells: Int,
-    spec: AllAppsSpec,
-    calculatedWorkspaceSpec: CalculatedWorkspaceSpec
-) : CalculatedResponsiveSpec(availableSpace, cells, spec, calculatedWorkspaceSpec)
diff --git a/src/com/android/launcher3/responsive/FolderSpecs.kt b/src/com/android/launcher3/responsive/FolderSpecs.kt
deleted file mode 100644
index bc2db28..0000000
--- a/src/com/android/launcher3/responsive/FolderSpecs.kt
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.responsive
-
-import android.content.res.TypedArray
-import com.android.launcher3.R
-import com.android.launcher3.responsive.ResponsiveSpec.SpecType
-import com.android.launcher3.util.ResourceHelper
-
-class FolderSpecs(widthSpecs: List<FolderSpec>, heightSpecs: List<FolderSpec>) :
-    ResponsiveSpecs<FolderSpec>(widthSpecs, heightSpecs) {
-
-    fun getCalculatedWidthSpec(
-        columns: Int,
-        availableWidth: Int,
-        calculatedWorkspaceSpec: CalculatedWorkspaceSpec
-    ): CalculatedFolderSpec {
-        check(calculatedWorkspaceSpec.spec.specType == SpecType.WIDTH) {
-            "Invalid specType for CalculatedWorkspaceSpec. " +
-                "Expected: ${SpecType.WIDTH} - " +
-                "Found: ${calculatedWorkspaceSpec.spec.specType}}"
-        }
-
-        val spec = getWidthSpec(availableWidth)
-        return CalculatedFolderSpec(availableWidth, columns, spec, calculatedWorkspaceSpec)
-    }
-
-    fun getCalculatedHeightSpec(
-        rows: Int,
-        availableHeight: Int,
-        calculatedWorkspaceSpec: CalculatedWorkspaceSpec
-    ): CalculatedFolderSpec {
-        check(calculatedWorkspaceSpec.spec.specType == SpecType.HEIGHT) {
-            "Invalid specType for CalculatedWorkspaceSpec. " +
-                "Expected: ${SpecType.HEIGHT} - " +
-                "Found: ${calculatedWorkspaceSpec.spec.specType}}"
-        }
-
-        val spec = getHeightSpec(availableHeight)
-        return CalculatedFolderSpec(availableHeight, rows, spec, calculatedWorkspaceSpec)
-    }
-
-    companion object {
-
-        private const val XML_FOLDER_SPEC = "folderSpec"
-
-        @JvmStatic
-        fun create(resourceHelper: ResourceHelper): FolderSpecs {
-            val parser = ResponsiveSpecsParser(resourceHelper)
-            val specs = parser.parseXML(XML_FOLDER_SPEC, ::FolderSpec)
-            val (widthSpecs, heightSpecs) = specs.partition { it.specType == SpecType.WIDTH }
-            return FolderSpecs(widthSpecs, heightSpecs)
-        }
-    }
-}
-
-data class FolderSpec(
-    override val maxAvailableSize: Int,
-    override val specType: SpecType,
-    override val startPadding: SizeSpec,
-    override val endPadding: SizeSpec,
-    override val gutter: SizeSpec,
-    override val cellSize: SizeSpec
-) : ResponsiveSpec(maxAvailableSize, specType, startPadding, endPadding, gutter, cellSize) {
-
-    init {
-        check(isValid()) { "Invalid FolderSpec found." }
-    }
-
-    constructor(
-        attrs: TypedArray,
-        specs: Map<String, SizeSpec>
-    ) : this(
-        maxAvailableSize =
-            attrs.getDimensionPixelSize(R.styleable.ResponsiveSpec_maxAvailableSize, 0),
-        specType =
-            SpecType.values()[
-                    attrs.getInt(R.styleable.ResponsiveSpec_specType, SpecType.HEIGHT.ordinal)],
-        startPadding = specs.getOrError(SizeSpec.XmlTags.START_PADDING),
-        endPadding = specs.getOrError(SizeSpec.XmlTags.END_PADDING),
-        gutter = specs.getOrError(SizeSpec.XmlTags.GUTTER),
-        cellSize = specs.getOrError(SizeSpec.XmlTags.CELL_SIZE)
-    )
-}
-
-class CalculatedFolderSpec(
-    availableSpace: Int,
-    cells: Int,
-    spec: FolderSpec,
-    calculatedWorkspaceSpec: CalculatedWorkspaceSpec
-) : CalculatedResponsiveSpec(availableSpace, cells, spec, calculatedWorkspaceSpec)
diff --git a/src/com/android/launcher3/responsive/HotseatSpecs.kt b/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
similarity index 70%
rename from src/com/android/launcher3/responsive/HotseatSpecs.kt
rename to src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
index 37a682f..7f7f2f1 100644
--- a/src/com/android/launcher3/responsive/HotseatSpecs.kt
+++ b/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
@@ -19,67 +19,65 @@
 import android.content.res.TypedArray
 import android.util.Log
 import com.android.launcher3.R
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
+import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
 import com.android.launcher3.util.ResourceHelper
 
-class HotseatSpecs(widthSpecs: List<HotseatSpec>, heightSpecs: List<HotseatSpec>) {
+class HotseatSpecsProvider(private val groupOfSpecs: List<ResponsiveSpecGroup<HotseatSpec>>) {
+    fun getSpecsByAspectRatio(aspectRatio: Float): ResponsiveSpecGroup<HotseatSpec> {
+        check(aspectRatio > 0f) { "Invalid aspect ratio! The value should be bigger than 0." }
 
-    val widthSpecs: List<HotseatSpec>
-    val heightSpecs: List<HotseatSpec>
+        val specsGroup = groupOfSpecs.firstOrNull { aspectRatio <= it.aspectRatio }
+        check(specsGroup != null) { "No available spec with aspectRatio within $aspectRatio." }
 
-    init {
-        this.widthSpecs = widthSpecs.sortedBy { it.maxAvailableSize }
-        this.heightSpecs = heightSpecs.sortedBy { it.maxAvailableSize }
+        return specsGroup
     }
 
-    fun getCalculatedHeightSpec(availableHeight: Int): CalculatedHotseatSpec {
-        val spec = heightSpecs.firstOrNull { availableHeight <= it.maxAvailableSize }
-        check(spec != null) { "No available height spec found within $availableHeight." }
-        return CalculatedHotseatSpec(availableHeight, spec)
-    }
-
-    fun getCalculatedWidthSpec(availableWidth: Int): CalculatedHotseatSpec {
-        val spec = widthSpecs.firstOrNull { availableWidth <= it.maxAvailableSize }
-        check(spec != null) { "No available width spec found within $availableWidth." }
-        return CalculatedHotseatSpec(availableWidth, spec)
+    fun getCalculatedSpec(
+        aspectRatio: Float,
+        dimensionType: DimensionType,
+        availableSpace: Int
+    ): CalculatedHotseatSpec {
+        val specsGroup = getSpecsByAspectRatio(aspectRatio)
+        val spec = specsGroup.getSpec(dimensionType, availableSpace)
+        return CalculatedHotseatSpec(availableSpace, spec)
     }
 
     companion object {
-        private const val XML_HOTSEAT_SPEC = "hotseatSpec"
-
         @JvmStatic
-        fun create(resourceHelper: ResourceHelper): HotseatSpecs {
+        fun create(resourceHelper: ResourceHelper): HotseatSpecsProvider {
             val parser = ResponsiveSpecsParser(resourceHelper)
-            val specs = parser.parseXML(XML_HOTSEAT_SPEC, ::HotseatSpec)
-            val (widthSpecs, heightSpecs) =
-                specs.partition { it.specType == ResponsiveSpec.SpecType.WIDTH }
-            return HotseatSpecs(widthSpecs, heightSpecs)
+            val specs = parser.parseXML(ResponsiveSpecType.Hotseat, ::HotseatSpec)
+            return HotseatSpecsProvider(specs)
         }
     }
 }
 
 data class HotseatSpec(
-    val maxAvailableSize: Int,
-    val specType: ResponsiveSpec.SpecType,
+    override val maxAvailableSize: Int,
+    override val dimensionType: DimensionType,
+    override val specType: ResponsiveSpecType,
     val hotseatQsbSpace: SizeSpec,
     val edgePadding: SizeSpec
-) {
-
+) : IResponsiveSpec {
     init {
         check(isValid()) { "Invalid HotseatSpec found." }
     }
 
     constructor(
+        responsiveSpecType: ResponsiveSpecType,
         attrs: TypedArray,
         specs: Map<String, SizeSpec>
     ) : this(
         maxAvailableSize =
             attrs.getDimensionPixelSize(R.styleable.ResponsiveSpec_maxAvailableSize, 0),
-        specType =
-            ResponsiveSpec.SpecType.values()[
+        dimensionType =
+            DimensionType.entries[
                     attrs.getInt(
                         R.styleable.ResponsiveSpec_specType,
-                        ResponsiveSpec.SpecType.HEIGHT.ordinal
+                        DimensionType.HEIGHT.ordinal
                     )],
+        specType = responsiveSpecType,
         hotseatQsbSpace = specs.getOrError(SizeSpec.XmlTags.HOTSEAT_QSB_SPACE),
         edgePadding = specs.getOrError(SizeSpec.XmlTags.EDGE_PADDING)
     )
diff --git a/src/com/android/launcher3/responsive/ResponsiveSpecs.kt b/src/com/android/launcher3/responsive/ResponsiveSpec.kt
similarity index 64%
rename from src/com/android/launcher3/responsive/ResponsiveSpecs.kt
rename to src/com/android/launcher3/responsive/ResponsiveSpec.kt
index a43c44a..cf70ad2 100644
--- a/src/com/android/launcher3/responsive/ResponsiveSpecs.kt
+++ b/src/com/android/launcher3/responsive/ResponsiveSpec.kt
@@ -16,75 +16,84 @@
 
 package com.android.launcher3.responsive
 
+import android.content.res.TypedArray
 import android.util.Log
+import com.android.launcher3.R
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
 
 /**
- * Base class for responsive specs that holds a list of width and height specs.
+ * Interface for responsive grid specs
  *
- * @param widthSpecs List of width responsive specifications
- * @param heightSpecs List of height responsive specifications
+ * @property maxAvailableSize indicates the breakpoint to use this specification.
+ * @property dimensionType indicates whether the paddings and gutters will be applied vertically or
+ *   horizontally.
+ * @property specType a [ResponsiveSpecType] that indicates the type of the spec.
  */
-abstract class ResponsiveSpecs<T : ResponsiveSpec>(widthSpecs: List<T>, heightSpecs: List<T>) {
-    val widthSpecs: List<T>
-    val heightSpecs: List<T>
-
-    init {
-        check(widthSpecs.isNotEmpty() && heightSpecs.isNotEmpty()) {
-            "${this::class.simpleName} is incomplete - " +
-                "width list size = ${widthSpecs.size}; " +
-                "height list size = ${heightSpecs.size}."
-        }
-
-        this.widthSpecs = widthSpecs.sortedBy { it.maxAvailableSize }
-        this.heightSpecs = heightSpecs.sortedBy { it.maxAvailableSize }
-    }
-
-    /**
-     * Get a [ResponsiveSpec] for width within the breakpoint.
-     *
-     * @param availableWidth The width breakpoint for the spec
-     * @return A [ResponsiveSpec] for width.
-     */
-    fun getWidthSpec(availableWidth: Int): T {
-        val spec = widthSpecs.firstOrNull { availableWidth <= it.maxAvailableSize }
-        check(spec != null) { "No available width spec found within $availableWidth." }
-        return spec
-    }
-
-    /**
-     * Get a [ResponsiveSpec] for height within the breakpoint.
-     *
-     * @param availableHeight The height breakpoint for the spec
-     * @return A [ResponsiveSpec] for height.
-     */
-    fun getHeightSpec(availableHeight: Int): T {
-        val spec = heightSpecs.firstOrNull { availableHeight <= it.maxAvailableSize }
-        check(spec != null) { "No available height spec found within $availableHeight." }
-        return spec
-    }
+interface IResponsiveSpec {
+    val maxAvailableSize: Int
+    val dimensionType: ResponsiveSpec.DimensionType
+    val specType: ResponsiveSpecType
 }
 
 /**
- * Base class for a responsive specification that is used to calculate the paddings, gutter and cell
+ * Class for a responsive specification that is used to calculate the paddings, gutter and cell
  * size.
  *
  * @param maxAvailableSize indicates the breakpoint to use this specification.
- * @param specType indicates whether the paddings and gutters will be applied vertically or
+ * @param dimensionType indicates whether the paddings and gutters will be applied vertically or
  *   horizontally.
+ * @param specType a [ResponsiveSpecType] that indicates the type of the spec.
  * @param startPadding padding used at the top or left (right in RTL) in the workspace folder.
  * @param endPadding padding used at the bottom or right (left in RTL) in the workspace folder.
- * @param gutter the space between the cells vertically or horizontally depending on the [specType].
- * @param cellSize height or width of the cell depending on the [specType].
+ * @param gutter the space between the cells vertically or horizontally depending on the
+ *   [dimensionType].
+ * @param cellSize height or width of the cell depending on the [dimensionType].
  */
-abstract class ResponsiveSpec(
-    open val maxAvailableSize: Int,
-    open val specType: SpecType,
-    open val startPadding: SizeSpec,
-    open val endPadding: SizeSpec,
-    open val gutter: SizeSpec,
-    open val cellSize: SizeSpec
-) {
-    open fun isValid(): Boolean {
+data class ResponsiveSpec(
+    override val maxAvailableSize: Int,
+    override val dimensionType: DimensionType,
+    override val specType: ResponsiveSpecType,
+    val startPadding: SizeSpec,
+    val endPadding: SizeSpec,
+    val gutter: SizeSpec,
+    val cellSize: SizeSpec,
+) : IResponsiveSpec {
+    init {
+        check(isValid()) { "Invalid ResponsiveSpec found." }
+    }
+
+    constructor(
+        responsiveSpecType: ResponsiveSpecType,
+        attrs: TypedArray,
+        specs: Map<String, SizeSpec>
+    ) : this(
+        maxAvailableSize =
+            attrs.getDimensionPixelSize(R.styleable.ResponsiveSpec_maxAvailableSize, 0),
+        dimensionType =
+            DimensionType.entries[
+                    attrs.getInt(
+                        R.styleable.ResponsiveSpec_specType,
+                        DimensionType.HEIGHT.ordinal
+                    )],
+        specType = responsiveSpecType,
+        startPadding = specs.getOrError(SizeSpec.XmlTags.START_PADDING),
+        endPadding = specs.getOrError(SizeSpec.XmlTags.END_PADDING),
+        gutter = specs.getOrError(SizeSpec.XmlTags.GUTTER),
+        cellSize = specs.getOrError(SizeSpec.XmlTags.CELL_SIZE)
+    )
+
+    fun isValid(): Boolean {
+        if (
+            (specType == ResponsiveSpecType.Workspace) &&
+                (startPadding.matchWorkspace ||
+                    endPadding.matchWorkspace ||
+                    gutter.matchWorkspace ||
+                    cellSize.matchWorkspace)
+        ) {
+            Log.e(LOG_TAG, "WorkspaceSpec#isValid - workspace shouldn't contain matchWorkspace!")
+            return false
+        }
+
         if (maxAvailableSize <= 0) {
             Log.e(LOG_TAG, "${this::class.simpleName}#isValid - maxAvailableSize <= 0")
             return false
@@ -106,13 +115,20 @@
             cellSize.isValid()
     }
 
-    enum class SpecType {
+    enum class DimensionType {
         HEIGHT,
         WIDTH
     }
 
     companion object {
         private const val LOG_TAG = "ResponsiveSpec"
+
+        enum class ResponsiveSpecType(val xmlTag: String) {
+            AllApps("allAppsSpec"),
+            Folder("folderSpec"),
+            Workspace("workspaceSpec"),
+            Hotseat("hotseatSpec")
+        }
     }
 }
 
@@ -120,7 +136,7 @@
  * Calculated responsive specs contains the final paddings, gutter and cell size in pixels after
  * they are calculated from the available space, cells and workspace specs.
  */
-sealed class CalculatedResponsiveSpec {
+class CalculatedResponsiveSpec {
     var availableSpace: Int = 0
         private set
 
@@ -146,7 +162,7 @@
         availableSpace: Int,
         cells: Int,
         spec: ResponsiveSpec,
-        calculatedWorkspaceSpec: CalculatedWorkspaceSpec
+        calculatedWorkspaceSpec: CalculatedResponsiveSpec
     ) {
         this.availableSpace = availableSpace
         this.cells = cells
@@ -181,6 +197,8 @@
         updateRemainderSpaces(availableSpace, cells, spec)
     }
 
+    fun isResponsiveSpecType(type: ResponsiveSpecType) = spec.specType == type
+
     private fun updateRemainderSpaces(availableSpace: Int, cells: Int, spec: ResponsiveSpec) {
         val gutters = cells - 1
         val usedSpace = startPaddingPx + endPaddingPx + (gutterPx * gutters) + (cellSizePx * cells)
@@ -215,10 +233,10 @@
     }
 
     override fun toString(): String {
-        return "${this::class.simpleName}(" +
+        return "Calculated${spec.specType}Spec(" +
             "availableSpace=$availableSpace, cells=$cells, startPaddingPx=$startPaddingPx, " +
             "endPaddingPx=$endPaddingPx, gutterPx=$gutterPx, cellSizePx=$cellSizePx, " +
-            "${spec::class.simpleName}.maxAvailableSize=${spec.maxAvailableSize}" +
+            "${spec.specType}Spec.maxAvailableSize=${spec.maxAvailableSize}" +
             ")"
     }
 }
diff --git a/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt b/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt
new file mode 100644
index 0000000..b233d7c
--- /dev/null
+++ b/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.responsive
+
+import android.content.res.TypedArray
+import com.android.launcher3.R
+import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
+
+/**
+ * Base class for responsive specs that holds a list of width and height specs.
+ *
+ * @param widthSpecs List of width responsive specifications
+ * @param heightSpecs List of height responsive specifications
+ */
+class ResponsiveSpecGroup<T : IResponsiveSpec>(
+    val aspectRatio: Float,
+    widthSpecs: List<T>,
+    heightSpecs: List<T>
+) {
+    val widthSpecs: List<T>
+    val heightSpecs: List<T>
+
+    init {
+        check(aspectRatio > 0f) { "Invalid aspect ratio! Aspect ratio should be bigger than zero." }
+        this.widthSpecs = widthSpecs.sortedBy { it.maxAvailableSize }
+        this.heightSpecs = heightSpecs.sortedBy { it.maxAvailableSize }
+    }
+
+    /**
+     * Get a [ResponsiveSpec] within the breakpoint.
+     *
+     * @param type Type of the spec to be retrieved (width or height)
+     * @param availableSize The breakpoint for the spec
+     * @return A [ResponsiveSpec].
+     */
+    fun getSpec(type: DimensionType, availableSize: Int): T {
+        val spec =
+            if (type == DimensionType.WIDTH) {
+                widthSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
+            } else {
+                heightSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
+            }
+        check(spec != null) { "No available $type spec found within $availableSize." }
+        return spec
+    }
+
+    companion object {
+        const val XML_GROUP_NAME = "specs"
+
+        fun <T : IResponsiveSpec> create(
+            attrs: TypedArray,
+            specs: List<T>
+        ): ResponsiveSpecGroup<T> {
+            val (widthSpecs, heightSpecs) =
+                specs.partition { it.dimensionType == DimensionType.WIDTH }
+            val aspectRatio = attrs.getFloat(R.styleable.ResponsiveSpecGroup_maxAspectRatio, 0f)
+            return ResponsiveSpecGroup(aspectRatio, widthSpecs, heightSpecs)
+        }
+    }
+}
diff --git a/src/com/android/launcher3/responsive/ResponsiveSpecsParser.kt b/src/com/android/launcher3/responsive/ResponsiveSpecsParser.kt
index a89b619..d782cd5 100644
--- a/src/com/android/launcher3/responsive/ResponsiveSpecsParser.kt
+++ b/src/com/android/launcher3/responsive/ResponsiveSpecsParser.kt
@@ -20,6 +20,7 @@
 import android.content.res.XmlResourceParser
 import android.util.Xml
 import com.android.launcher3.R
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
 import com.android.launcher3.util.ResourceHelper
 import java.io.IOException
 import org.xmlpull.v1.XmlPullParser
@@ -27,6 +28,80 @@
 
 class ResponsiveSpecsParser(private val resourceHelper: ResourceHelper) {
 
+    fun <T : IResponsiveSpec> parseXML(
+        responsiveSpecType: ResponsiveSpecType,
+        map:
+            (
+                responsiveSpecType: ResponsiveSpecType,
+                attributes: TypedArray,
+                sizeSpecs: Map<String, SizeSpec>
+            ) -> T
+    ): List<ResponsiveSpecGroup<T>> {
+        val parser: XmlResourceParser = resourceHelper.getXml()
+
+        try {
+            val groups = mutableListOf<ResponsiveSpecGroup<T>>()
+            val specs = mutableListOf<T>()
+            var groupAttrs: TypedArray? = null
+
+            var eventType = parser.eventType
+            while (eventType != XmlPullParser.END_DOCUMENT) {
+                // Parsing Group
+                when {
+                    parser starts ResponsiveSpecGroup.XML_GROUP_NAME -> {
+                        groupAttrs =
+                            resourceHelper.obtainStyledAttributes(
+                                Xml.asAttributeSet(parser),
+                                R.styleable.ResponsiveSpecGroup
+                            )
+                    }
+                    parser ends ResponsiveSpecGroup.XML_GROUP_NAME -> {
+                        checkNotNull(groupAttrs)
+                        groups += ResponsiveSpecGroup.create(groupAttrs, specs)
+                        specs.clear()
+                        groupAttrs.recycle()
+                        groupAttrs = null
+                    }
+                    // Mapping Spec to WorkspaceSpec, AllAppsSpec, FolderSpecs, HotseatSpec
+                    parser starts responsiveSpecType.xmlTag -> {
+                        val attrs =
+                            resourceHelper.obtainStyledAttributes(
+                                Xml.asAttributeSet(parser),
+                                R.styleable.ResponsiveSpec
+                            )
+
+                        val sizeSpecs = parseSizeSpecs(parser)
+                        specs += map(responsiveSpecType, attrs, sizeSpecs)
+                        attrs.recycle()
+                    }
+                }
+
+                eventType = parser.next()
+            }
+
+            parser.close()
+
+            // All the specs should have been linked to a group, otherwise the XML is invalid
+            check(specs.isEmpty()) {
+                throw InvalidResponsiveGridSpec(
+                    "Invalid XML. ${specs.size} specs not linked to a group."
+                )
+            }
+
+            return groups
+        } catch (e: Exception) {
+            when (e) {
+                is NoSuchFieldException,
+                is IOException,
+                is XmlPullParserException ->
+                    throw RuntimeException("Failure parsing specs file.", e)
+                else -> throw e
+            }
+        } finally {
+            parser.close()
+        }
+    }
+
     private fun parseSizeSpecs(parser: XmlResourceParser): Map<String, SizeSpec> {
         val parentName = parser.name
         parser.next()
@@ -42,49 +117,15 @@
         return result
     }
 
-    fun <T> parseXML(
-        tagName: String,
-        map: (attributes: TypedArray, sizeSpecs: Map<String, SizeSpec>) -> T
-    ): List<T> {
-        val parser: XmlResourceParser = resourceHelper.getXml()
+    private infix fun XmlResourceParser.starts(tag: String): Boolean =
+        name == tag && eventType == XmlPullParser.START_TAG
 
-        try {
-            val list = mutableListOf<T>()
-
-            var eventType = parser.eventType
-            while (eventType != XmlPullParser.END_DOCUMENT) {
-                if (eventType == XmlResourceParser.START_TAG && parser.name == tagName) {
-                    val attrs =
-                        resourceHelper.obtainStyledAttributes(
-                            Xml.asAttributeSet(parser),
-                            R.styleable.ResponsiveSpec
-                        )
-
-                    val sizeSpecs = parseSizeSpecs(parser)
-                    list += map(attrs, sizeSpecs)
-                    attrs.recycle()
-                }
-
-                eventType = parser.next()
-            }
-
-            parser.close()
-
-            return list
-        } catch (e: Exception) {
-            when (e) {
-                is NoSuchFieldException,
-                is IOException,
-                is XmlPullParserException ->
-                    throw RuntimeException("Failure parsing specs file.", e)
-                else -> throw e
-            }
-        } finally {
-            parser.close()
-        }
-    }
+    private infix fun XmlResourceParser.ends(tag: String): Boolean =
+        name == tag && eventType == XmlPullParser.END_TAG
 }
 
 fun Map<String, SizeSpec>.getOrError(key: String): SizeSpec {
     return this.getOrElse(key) { error("Attr '$key' must be defined.") }
 }
+
+class InvalidResponsiveGridSpec(message: String) : Exception(message)
diff --git a/src/com/android/launcher3/responsive/ResponsiveSpecsProvider.kt b/src/com/android/launcher3/responsive/ResponsiveSpecsProvider.kt
new file mode 100644
index 0000000..bc2f4c5
--- /dev/null
+++ b/src/com/android/launcher3/responsive/ResponsiveSpecsProvider.kt
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.responsive
+
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
+import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
+import com.android.launcher3.util.ResourceHelper
+
+/**
+ * A class to provide responsive grid specs for workspace, folder and all apps.
+ *
+ * This class is responsible for provide width and height [CalculatedResponsiveSpec] to be used for
+ * the correct placement of the workspace, all apps and folders.
+ *
+ * @param type A [ResponsiveSpecType] to indicates the type of the spec.
+ * @param groupOfSpecs Groups of responsive specifications
+ */
+class ResponsiveSpecsProvider(
+    val type: ResponsiveSpecType,
+    groupOfSpecs: List<ResponsiveSpecGroup<ResponsiveSpec>>
+) {
+    private val groupOfSpecs: List<ResponsiveSpecGroup<ResponsiveSpec>>
+
+    init {
+        this.groupOfSpecs =
+            groupOfSpecs
+                .onEach { group ->
+                    check(group.widthSpecs.isNotEmpty() && group.heightSpecs.isNotEmpty()) {
+                        "${this::class.simpleName} is incomplete - " +
+                            "width list size = ${group.widthSpecs.size}; " +
+                            "height list size = ${group.heightSpecs.size}."
+                    }
+                }
+                .sortedBy { it.aspectRatio }
+    }
+
+    fun getSpecsByAspectRatio(aspectRatio: Float): ResponsiveSpecGroup<ResponsiveSpec> {
+        check(aspectRatio > 0f) { "Invalid aspect ratio! The value should be bigger than 0." }
+
+        val specsGroup = groupOfSpecs.firstOrNull { aspectRatio <= it.aspectRatio }
+        checkNotNull(specsGroup) { "No available spec with aspectRatio within $aspectRatio." }
+
+        return specsGroup
+    }
+
+    /**
+     * Retrieves a responsive grid specification that matches the number of [numCells],
+     * * [availableSpace] and [aspectRatio].
+     *
+     * @param aspectRatio the device width divided by device height (aspect ratio) to filter the
+     *   specifications
+     * @param dimensionType the grid axis of the spec width is x axis, height is y axis.
+     * @param numCells number of rows/columns in the grid
+     * @param availableSpace available width to filter the specifications
+     * @return A [CalculatedResponsiveSpec] that matches the parameters provided.
+     */
+    fun getCalculatedSpec(
+        aspectRatio: Float,
+        dimensionType: DimensionType,
+        numCells: Int,
+        availableSpace: Int,
+    ): CalculatedResponsiveSpec {
+        val specsGroup = getSpecsByAspectRatio(aspectRatio)
+        val spec = specsGroup.getSpec(dimensionType, availableSpace)
+        return CalculatedResponsiveSpec(availableSpace, numCells, spec)
+    }
+
+    /**
+     * Retrieves a responsive grid specification that matches the number of [numCells],
+     * * [availableSpace] and [aspectRatio]. This function uses a [CalculatedResponsiveSpec] to
+     *   match workspace when its true.
+     *
+     * @param aspectRatio the device width divided by device height (aspect ratio) to filter the
+     *   specifications
+     * @param dimensionType the grid axis of the spec width is x axis, height is y axis.
+     * @param numCells number of rows/columns in the grid
+     * @param availableSpace available width to filter the specifications
+     * @param calculatedWorkspaceSpec the calculated workspace specification to use its values as
+     *   base when matchWorkspace is true.
+     * @return A [CalculatedResponsiveSpec] that matches the parameters provided.
+     */
+    fun getCalculatedSpec(
+        aspectRatio: Float,
+        dimensionType: DimensionType,
+        numCells: Int,
+        availableSpace: Int,
+        calculatedWorkspaceSpec: CalculatedResponsiveSpec
+    ): CalculatedResponsiveSpec {
+        check(calculatedWorkspaceSpec.spec.dimensionType == dimensionType) {
+            "Invalid specType for CalculatedWorkspaceSpec. " +
+                "Expected: $dimensionType - " +
+                "Found: ${calculatedWorkspaceSpec.spec.dimensionType}}"
+        }
+
+        check(calculatedWorkspaceSpec.isResponsiveSpecType(ResponsiveSpecType.Workspace)) {
+            "Invalid specType for CalculatedWorkspaceSpec. " +
+                "Expected: ${ResponsiveSpecType.Workspace} - " +
+                "Found: ${calculatedWorkspaceSpec.spec.specType}}"
+        }
+
+        val specsGroup = getSpecsByAspectRatio(aspectRatio)
+        val spec = specsGroup.getSpec(dimensionType, availableSpace)
+        return CalculatedResponsiveSpec(availableSpace, numCells, spec, calculatedWorkspaceSpec)
+    }
+
+    companion object {
+        @JvmStatic
+        fun create(
+            resourceHelper: ResourceHelper,
+            type: ResponsiveSpecType
+        ): ResponsiveSpecsProvider {
+            val parser = ResponsiveSpecsParser(resourceHelper)
+            val specs = parser.parseXML(type, ::ResponsiveSpec)
+            return ResponsiveSpecsProvider(type, specs)
+        }
+    }
+}
diff --git a/src/com/android/launcher3/responsive/WorkspaceSpecs.kt b/src/com/android/launcher3/responsive/WorkspaceSpecs.kt
deleted file mode 100644
index 0da7026..0000000
--- a/src/com/android/launcher3/responsive/WorkspaceSpecs.kt
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.responsive
-
-import android.content.res.TypedArray
-import android.util.Log
-import com.android.launcher3.R
-import com.android.launcher3.responsive.ResponsiveSpec.SpecType
-import com.android.launcher3.util.ResourceHelper
-
-private const val TAG = "WorkspaceSpecs"
-
-class WorkspaceSpecs(widthSpecs: List<WorkspaceSpec>, heightSpecs: List<WorkspaceSpec>) :
-    ResponsiveSpecs<WorkspaceSpec>(widthSpecs, heightSpecs) {
-
-    fun getCalculatedWidthSpec(columns: Int, availableWidth: Int): CalculatedWorkspaceSpec {
-        val spec = getWidthSpec(availableWidth)
-        return CalculatedWorkspaceSpec(availableWidth, columns, spec)
-    }
-
-    fun getCalculatedHeightSpec(rows: Int, availableHeight: Int): CalculatedWorkspaceSpec {
-        val spec = getHeightSpec(availableHeight)
-        return CalculatedWorkspaceSpec(availableHeight, rows, spec)
-    }
-
-    companion object {
-        private const val XML_WORKSPACE_SPEC = "workspaceSpec"
-
-        @JvmStatic
-        fun create(resourceHelper: ResourceHelper): WorkspaceSpecs {
-            val parser = ResponsiveSpecsParser(resourceHelper)
-            val specs = parser.parseXML(XML_WORKSPACE_SPEC, ::WorkspaceSpec)
-            val (widthSpecs, heightSpecs) = specs.partition { it.specType == SpecType.WIDTH }
-            return WorkspaceSpecs(widthSpecs, heightSpecs)
-        }
-    }
-}
-
-data class WorkspaceSpec(
-    override val maxAvailableSize: Int,
-    override val specType: SpecType,
-    override val startPadding: SizeSpec,
-    override val endPadding: SizeSpec,
-    override val gutter: SizeSpec,
-    override val cellSize: SizeSpec
-) : ResponsiveSpec(maxAvailableSize, specType, startPadding, endPadding, gutter, cellSize) {
-
-    init {
-        check(isValid()) { "Invalid WorkspaceSpec found." }
-    }
-
-    constructor(
-        attrs: TypedArray,
-        specs: Map<String, SizeSpec>
-    ) : this(
-        maxAvailableSize =
-            attrs.getDimensionPixelSize(R.styleable.ResponsiveSpec_maxAvailableSize, 0),
-        specType =
-            SpecType.values()[
-                    attrs.getInt(R.styleable.ResponsiveSpec_specType, SpecType.HEIGHT.ordinal)],
-        startPadding = specs.getOrError(SizeSpec.XmlTags.START_PADDING),
-        endPadding = specs.getOrError(SizeSpec.XmlTags.END_PADDING),
-        gutter = specs.getOrError(SizeSpec.XmlTags.GUTTER),
-        cellSize = specs.getOrError(SizeSpec.XmlTags.CELL_SIZE)
-    )
-
-    override fun isValid(): Boolean {
-        // Workspace spec should not match workspace
-        if (
-            startPadding.matchWorkspace ||
-                endPadding.matchWorkspace ||
-                gutter.matchWorkspace ||
-                cellSize.matchWorkspace
-        ) {
-            Log.e(TAG, "WorkspaceSpec#isValid - workspace shouldn't contain matchWorkspace!")
-            return false
-        }
-
-        return super.isValid()
-    }
-}
-
-class CalculatedWorkspaceSpec(availableSpace: Int, cells: Int, spec: WorkspaceSpec) :
-    CalculatedResponsiveSpec(availableSpace, cells, spec)