Align workspace and hotseat icons in landscape

Fix: 311381639
Test: Verified on device
Flag: NONE
Change-Id: I4e2c74f59e8492042c3c7f8eccc98921d92d685f
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index baa1ee3..2f0c096 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -213,6 +213,7 @@
         mIsRtl = (getResources().getConfiguration().getLayoutDirection()
                 == View.LAYOUT_DIRECTION_RTL);
         mDeviceProfile = mActivity.getDeviceProfile();
+        mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
 
         mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
         final int defaultIconSize;
@@ -243,7 +244,6 @@
             defaultIconSize = mDeviceProfile.iconSizePx;
         }
 
-        mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
 
         mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
                 defaultIconSize);
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index e9545c8..bf4f6c3 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -1010,7 +1010,7 @@
      * Returns the amount of extra (or unused) vertical space.
      */
     private int updateAvailableDimensions(Resources res) {
-        iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
+        iconCenterVertically = (mIsScalableGrid || mIsResponsiveGrid) && isVerticalBarLayout();
 
         if (mIsResponsiveGrid) {
             iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
@@ -1738,15 +1738,8 @@
             // The hotseat icons will be placed in the middle of the hotseat cells.
             // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
             // in vertical bar layout.
-            // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
-            // is set to account for that difference.
-            float diffOverlapFactor = mIsResponsiveGrid ? 0
-                    : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
-
-            int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
-                    - diffOverlapFactor), 0);
-            int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
-                    + diffOverlapFactor), 0);
+            int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top), 0);
+            int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom), 0);
 
             if (isSeascape()) {
                 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index f058ae4..284b31e 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -29,6 +29,7 @@
 import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
@@ -633,6 +634,20 @@
         }
     }
 
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        boolean shouldCenterIcon = mActivity.getDeviceProfile().iconCenterVertically;
+        if (shouldCenterIcon) {
+            int iconSize = mActivity.getDeviceProfile().iconSizePx;
+            Paint.FontMetrics fm = mFolderName.getPaint().getFontMetrics();
+            int cellHeightPx = iconSize + mFolderName.getCompoundDrawablePadding()
+                    + (int) Math.ceil(fm.bottom - fm.top);
+            setPadding(getPaddingLeft(), (MeasureSpec.getSize(heightMeasureSpec)
+                    - cellHeightPx) / 2, getPaddingRight(), getPaddingBottom());
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+
     /** Sets the visibility of the icon's title text */
     public void setTextVisible(boolean visible) {
         if (visible) {
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt
index 920ba6f..361247b 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt
@@ -80,8 +80,8 @@
 	hotseatQsbSpace: 0.0px (0.0dp)
 	hotseatQsbHeight: 0.0px (0.0dp)
 	springLoadedHotseatBarTopMarginPx: 118.0px (44.95238dp)
-	getHotseatLayoutPadding(context).top: 64.0px (24.380953dp)
-	getHotseatLayoutPadding(context).bottom: 112.0px (42.666668dp)
+	getHotseatLayoutPadding(context).top: 74.0px (28.190475dp)
+	getHotseatLayoutPadding(context).bottom: 103.0px (39.238094dp)
 	getHotseatLayoutPadding(context).left: 42.0px (16.0dp)
 	getHotseatLayoutPadding(context).right: 63.0px (24.0dp)
 	numShownHotseatIcons: 5
@@ -123,8 +123,8 @@
 	dropTargetBarSizePx: 95.0px (36.190475dp)
 	dropTargetBarBottomMarginPx: 16.0px (6.095238dp)
 	getCellLayoutSpringLoadShrunkTop(): 201.0px (76.57143dp)
-	getCellLayoutSpringLoadShrunkBottom(): 952.0px (362.66666dp)
+	getCellLayoutSpringLoadShrunkBottom(): 961.0px (366.09525dp)
 	workspaceSpringLoadedMinNextPageVisiblePx: 63.0px (24.0dp)
-	getWorkspaceSpringLoadScale(): 0.79639447px (0.30338836dp)
+	getWorkspaceSpringLoadScale(): 0.8059385px (0.30702418dp)
 	getCellLayoutHeight(): 943.0px (359.2381dp)
 	getCellLayoutWidth(): 2073.0px (789.7143dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt
index 65460ec..d93ec58 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt
@@ -80,8 +80,8 @@
 	hotseatQsbSpace: 0.0px (0.0dp)
 	hotseatQsbHeight: 0.0px (0.0dp)
 	springLoadedHotseatBarTopMarginPx: 118.0px (44.95238dp)
-	getHotseatLayoutPadding(context).top: 64.0px (24.380953dp)
-	getHotseatLayoutPadding(context).bottom: 49.0px (18.666666dp)
+	getHotseatLayoutPadding(context).top: 74.0px (28.190475dp)
+	getHotseatLayoutPadding(context).bottom: 40.0px (15.238095dp)
 	getHotseatLayoutPadding(context).left: 42.0px (16.0dp)
 	getHotseatLayoutPadding(context).right: 189.0px (72.0dp)
 	numShownHotseatIcons: 5
@@ -123,8 +123,8 @@
 	dropTargetBarSizePx: 95.0px (36.190475dp)
 	dropTargetBarBottomMarginPx: 16.0px (6.095238dp)
 	getCellLayoutSpringLoadShrunkTop(): 201.0px (76.57143dp)
-	getCellLayoutSpringLoadShrunkBottom(): 1008.0px (384.0dp)
+	getCellLayoutSpringLoadShrunkBottom(): 1017.0px (387.42856dp)
 	workspaceSpringLoadedMinNextPageVisiblePx: 63.0px (24.0dp)
-	getWorkspaceSpringLoadScale(): 0.8021869px (0.305595dp)
+	getWorkspaceSpringLoadScale(): 0.8111332px (0.3090031dp)
 	getCellLayoutHeight(): 1006.0px (383.2381dp)
 	getCellLayoutWidth(): 1947.0px (741.7143dp)