Add taskbarIconSize to GridOption/DisplayOptions

- Renamed variables to make it more clear what they represent
- DeviceProfile will be source of truth for taskbar
  sizes

Bug: 265144213
Test: phone, multi-display, tablet
Change-Id: Id9c19d15a65894fd7645e0f876a4b6527b713c34
Flag: ENABLE_TRANSIENT_TASKBAR=true
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index aca03e3..fcb220e 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -44,6 +44,7 @@
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.core.content.res.ResourcesCompat;
 
 import com.android.launcher3.CellLayout.ContainerType;
 import com.android.launcher3.DevicePaddings.DevicePadding;
@@ -262,10 +263,10 @@
     public boolean isTaskbarPresent;
     // Whether Taskbar will inset the bottom of apps by taskbarSize.
     public boolean isTaskbarPresentInApps;
-    public int taskbarSize;
-    public int transientTaskbarSize;
-    public int stashedTaskbarSize;
-    public int transientTaskbarMargin;
+    public final int taskbarHeight;
+    public final int stashedTaskbarHeight;
+    public final int taskbarBottomMargin;
+    public final int taskbarIconSize;
 
     // DragController
     public int flingToDeleteThresholdVelocity;
@@ -328,17 +329,21 @@
             }
         }
 
-        if (isTaskbarPresent) {
-            transientTaskbarSize = res.getDimensionPixelSize(R.dimen.transient_taskbar_size);
-            transientTaskbarMargin = res.getDimensionPixelSize(R.dimen.transient_taskbar_margin);
-            if (DisplayController.isTransientTaskbar(context)) {
-                taskbarSize = transientTaskbarSize;
-                stashedTaskbarSize =
-                        res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_size);
-            } else {
-                taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
-                stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
-            }
+        if (DisplayController.isTransientTaskbar(context)) {
+            float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
+            taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
+            taskbarHeight = taskbarIconSize
+                    + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
+            stashedTaskbarHeight =
+                    res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
+            taskbarBottomMargin =
+                    res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
+        } else {
+            taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
+                    mMetrics);
+            taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
+            stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
+            taskbarBottomMargin = 0;
         }
 
         edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
@@ -1421,7 +1426,7 @@
      * Returns the number of pixels the taskbar is translated from the bottom of the screen.
      */
     public int getTaskbarOffsetY() {
-        int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
+        int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
         int launcherIconBottomSpace =
                 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
         return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
@@ -1432,7 +1437,7 @@
      */
     public int getOverviewActionsClaimedSpaceBelow() {
         if (isTaskbarPresent) {
-            return transientTaskbarSize + transientTaskbarMargin * 2;
+            return taskbarHeight + taskbarBottomMargin * 2;
         }
         return mInsets.bottom;
     }
@@ -1470,7 +1475,7 @@
                     mInsets.top + availableHeightPx);
         } else {
             // Folders should only appear below the drop target bar and above the hotseat
-            int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
+            int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
             return new Rect(mInsets.left + edgeMarginPx,
                     mInsets.top + dropTargetBarSizePx + edgeMarginPx,
                     mInsets.left + availableWidthPx - edgeMarginPx,
@@ -1671,7 +1676,10 @@
 
         writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
         writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
-        writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
+        writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
+        writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
+        writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
+        writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
 
         writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
                 desiredWorkspaceHorizontalMarginPx));
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index a498323..47396a5 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -149,6 +149,8 @@
     public float[] allAppsIconTextSize;
     public PointF[] allAppsBorderSpaces;
 
+    public float[] transientTaskbarIconSize;
+
     private SparseArray<TypedValue> mExtraAttrs;
 
     /**
@@ -396,6 +398,8 @@
 
         inlineQsb = closestProfile.inlineQsb;
 
+        transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
+
         // If the partner customization apk contains any grid overrides, apply them
         // Supported overrides: numRows, numColumns, iconSize
         applyPartnerDeviceProfileOverrides(context, metrics);
@@ -908,9 +912,13 @@
         private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
         private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
 
+        private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
+
         DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
             this.grid = grid;
 
+            Resources res = context.getResources();
+
             TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
 
             minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
@@ -1101,8 +1109,7 @@
 
             hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
                     R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
-                    ResourcesCompat.getFloat(context.getResources(),
-                            R.dimen.hotseat_bar_bottom_space_default));
+                    ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
             hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
                     R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
                     hotseatBarBottomSpace[INDEX_DEFAULT]);
@@ -1115,8 +1122,7 @@
 
             hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
                     R.styleable.ProfileDisplayOption_hotseatQsbSpace,
-                    ResourcesCompat.getFloat(context.getResources(),
-                            R.dimen.hotseat_qsb_space_default));
+                    ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
             hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
                     R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
                     hotseatQsbSpace[INDEX_DEFAULT]);
@@ -1127,6 +1133,19 @@
                     R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
                     hotseatQsbSpace[INDEX_DEFAULT]);
 
+            transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
+                    R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
+                    ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
+            transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
+                    R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
+                    transientTaskbarIconSize[INDEX_DEFAULT]);
+            transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
+                    R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
+                    transientTaskbarIconSize[INDEX_DEFAULT]);
+            transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
+                    R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
+                    hotseatQsbSpace[INDEX_DEFAULT]);
+
             a.recycle();
         }
 
@@ -1148,6 +1167,7 @@
                 allAppsIconSizes[i] = 0;
                 allAppsIconTextSizes[i] = 0;
                 allAppsBorderSpaces[i] = new PointF();
+                transientTaskbarIconSize[i] = 0;
             }
         }
 
@@ -1168,6 +1188,7 @@
                 allAppsIconTextSizes[i] *= w;
                 allAppsBorderSpaces[i].x *= w;
                 allAppsBorderSpaces[i].y *= w;
+                transientTaskbarIconSize[i] *= w;
             }
 
             return this;
@@ -1190,6 +1211,7 @@
                 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
                 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
                 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
+                transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
             }
 
             return this;
diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java
index 3f2f21d..ca16b24 100644
--- a/src/com/android/launcher3/allapps/WorkModeSwitch.java
+++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java
@@ -15,8 +15,6 @@
  */
 package com.android.launcher3.allapps;
 
-import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WORK_FAB_BUTTON_COLLAPSE;
-import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WORK_FAB_BUTTON_EXTEND;
 import static com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.getTabWidth;
 
 import android.animation.LayoutTransition;
@@ -116,7 +114,7 @@
             }
 
             if (!dp.isGestureMode && dp.isTaskbarPresent) {
-                bottomMargin += dp.taskbarSize;
+                bottomMargin += dp.taskbarHeight;
             }
 
             lp.bottomMargin = bottomMargin;
diff --git a/src/com/android/launcher3/util/DimensionUtils.kt b/src/com/android/launcher3/util/DimensionUtils.kt
index 1922310..9188c2e 100644
--- a/src/com/android/launcher3/util/DimensionUtils.kt
+++ b/src/com/android/launcher3/util/DimensionUtils.kt
@@ -37,7 +37,7 @@
         // Taskbar for large screen
         if (!isPhoneMode) {
             p.x = ViewGroup.LayoutParams.MATCH_PARENT
-            p.y = deviceProfile.taskbarSize
+            p.y = deviceProfile.taskbarHeight
             return p
         }
 
diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java
index 823003c..e4df413 100644
--- a/src/com/android/launcher3/views/BaseDragLayer.java
+++ b/src/com/android/launcher3/views/BaseDragLayer.java
@@ -559,7 +559,7 @@
             DeviceProfile dp = mActivity.getDeviceProfile();
             if (dp.isTaskbarPresent) {
                 // Ignore taskbar gesture insets to avoid interfering with TouchControllers.
-                gestureInsetBottom = Math.max(0, gestureInsetBottom - dp.taskbarSize);
+                gestureInsetBottom = Math.max(0, gestureInsetBottom - dp.taskbarHeight);
             }
             mSystemGestureRegion.set(
                     Math.max(gestureInsets.left, imeInset.left),
diff --git a/src/com/android/launcher3/views/Snackbar.java b/src/com/android/launcher3/views/Snackbar.java
index 86b3419..8d5838e 100644
--- a/src/com/android/launcher3/views/Snackbar.java
+++ b/src/com/android/launcher3/views/Snackbar.java
@@ -101,7 +101,7 @@
         DeviceProfile deviceProfile = activity.getDeviceProfile();
         params.setMargins(0, 0, 0, marginBottom
                 + (deviceProfile.isTaskbarPresent
-                ? deviceProfile.taskbarSize + deviceProfile.getTaskbarOffsetY()
+                ? deviceProfile.taskbarHeight + deviceProfile.getTaskbarOffsetY()
                 : insets.bottom));
 
         TextView labelView = snackbar.findViewById(R.id.label);