Revert "Update workspace, cell layout, shortcut and widget, and cell size calculations."

This reverts commit b45d6c421d78eadfc0dff85a5a831179c646c27c.

Reason for revert: b/231283023

Change-Id: Ic4941ea9ecd382348aae8e099e5a7ebf4ed0bba3
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 561f9b9..88030ae 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -501,7 +501,7 @@
      */
     private int calculateQsbWidth() {
         if (isQsbInline) {
-            int columns = getPanelCount() * inv.numColumns;
+            int columns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
             return getIconToIconWidthForColumns(columns)
                     - iconSizePx * numShownHotseatIcons
                     - hotseatBorderSpace * numShownHotseatIcons;
@@ -665,10 +665,11 @@
         updateIconSize(1f, res);
 
         updateWorkspacePadding();
+        Point workspacePadding = getTotalWorkspacePadding();
 
         // Check to see if the icons fit within the available height.
         float usedHeight = getCellLayoutHeightSpecification();
-        final int maxHeight = getCellLayoutHeight();
+        final int maxHeight = getWorkspaceHeight(workspacePadding);
         float extraHeight = Math.max(0, maxHeight - usedHeight);
         float scaleY = maxHeight / usedHeight;
         boolean shouldScale = scaleY < 1f;
@@ -701,7 +702,7 @@
     }
 
     private int getCellLayoutWidthSpecification() {
-        int numColumns = getPanelCount() * inv.numColumns;
+        int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
         return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
                 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
     }
@@ -901,18 +902,16 @@
             result = new Point();
         }
 
-        result.x = calculateCellWidth(getShortcutAndWidgetContainerWidth(),
-                cellLayoutBorderSpacePx.x, inv.numColumns);
-        result.y = calculateCellHeight(getShortcutAndWidgetContainerHeight(),
-                cellLayoutBorderSpacePx.y, inv.numRows);
-        return result;
-    }
+        // Since we are only concerned with the overall padding, layout direction does
+        // not matter.
+        Point padding = getTotalWorkspacePadding();
 
-    /**
-     * Gets the number of panels within the workspace.
-     */
-    public int getPanelCount() {
-        return isTwoPanels ? 2 : 1;
+        int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
+        int screenWidthPx = getWorkspaceWidth(padding);
+        result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns);
+        int screenHeightPx = getWorkspaceHeight(padding);
+        result.y = calculateCellHeight(screenHeightPx, cellLayoutBorderSpacePx.y, inv.numRows);
+        return result;
     }
 
     /**
@@ -933,7 +932,7 @@
     /**
      * Gets the scaled top of the workspace in px for the spring-loaded edit state.
      */
-    public float getCellLayoutSpringLoadShrunkTop() {
+    public float getWorkspaceSpringLoadShrunkTop() {
         workspaceSpringLoadShrunkTop = mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
                 + dropTargetBarBottomMarginPx;
         return workspaceSpringLoadShrunkTop;
@@ -942,7 +941,7 @@
     /**
      * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
      */
-    private float getCellLayoutSpringLoadShrunkBottom() {
+    private float getWorkspaceSpringLoadShrunkBottom() {
         int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
         workspaceSpringLoadShrunkBottom =
                 heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset()
@@ -961,8 +960,9 @@
      * Gets the scale of the workspace for the spring-loaded edit state.
      */
     public float getWorkspaceSpringLoadScale() {
-        float scale = (getCellLayoutSpringLoadShrunkBottom() - getCellLayoutSpringLoadShrunkTop())
-                / getCellLayoutHeight();
+        float cellLayoutHeight = availableHeightPx - workspacePadding.top - workspacePadding.bottom;
+        float scale = (getWorkspaceSpringLoadShrunkBottom() - getWorkspaceSpringLoadShrunkTop())
+                / cellLayoutHeight;
         scale = Math.min(scale, 1f);
 
         // Reduce scale if next pages would not be visible after scaling the workspace
@@ -976,55 +976,19 @@
         return scale;
     }
 
-    /**
-     * Gets the width of the Workspace, aka a scrollable page of the homescreen.
-     */
     public int getWorkspaceWidth() {
-        return availableWidthPx;
+        return getWorkspaceWidth(getTotalWorkspacePadding());
     }
 
-    /**
-     * Gets the height of the Workspace, aka a scrollable page of the homescreen.
-     */
-    public int getWorkspaceHeight() {
-        return availableHeightPx;
+    public int getWorkspaceWidth(Point workspacePadding) {
+        int cellLayoutTotalPadding =
+                (isTwoPanels ? 2 : 1) * (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
+        return availableWidthPx - workspacePadding.x - cellLayoutTotalPadding;
     }
 
-    /**
-     * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
-     *
-     * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
-     * layouts have two Cell Layouts per workspace.
-     */
-    public int getCellLayoutWidth() {
-        return (getWorkspaceWidth() - getTotalWorkspacePadding().x) / getPanelCount();
-    }
-
-    /**
-     * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
-     *
-     * <p>This is the height of a Workspace, less its vertical padding.
-     */
-    public int getCellLayoutHeight() {
-        return getWorkspaceHeight() - getTotalWorkspacePadding().y;
-    }
-
-    /**
-     * Gets the width of the container holding the shortcuts and widgets.
-     *
-     * <p>This is the width of one Cell Layout less its horizontal padding.
-     */
-    public int getShortcutAndWidgetContainerWidth() {
-        return getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
-    }
-
-    /**
-     * Gets the height of the container holding the shortcuts and widgets.
-     *
-     * <p>This is the height of one Cell Layout less its vertical padding.
-     */
-    public int getShortcutAndWidgetContainerHeight() {
-        return getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
+    private int getWorkspaceHeight(Point workspacePadding) {
+        return availableHeightPx - workspacePadding.y - (cellLayoutPaddingPx.top
+                + cellLayoutPaddingPx.bottom);
     }
 
     public Point getTotalWorkspacePadding() {
diff --git a/src/com/android/launcher3/states/SpringLoadedState.java b/src/com/android/launcher3/states/SpringLoadedState.java
index a205ab5..15cdc20 100644
--- a/src/com/android/launcher3/states/SpringLoadedState.java
+++ b/src/com/android/launcher3/states/SpringLoadedState.java
@@ -51,7 +51,7 @@
             return super.getWorkspaceScaleAndTranslation(launcher);
         }
 
-        float shrunkTop = grid.getCellLayoutSpringLoadShrunkTop();
+        float shrunkTop = grid.getWorkspaceSpringLoadShrunkTop();
         float scale = grid.getWorkspaceSpringLoadScale();
 
         float halfHeight = ws.getHeight() / 2;