Update the bubble bar offset on Home

This is an initial change that positions the bubble bar aligning it
with the center of the hotseat icons. We still need to center it
with the taskbar when in overview.

This change also fixes the touch issues where sometimes the hotseat
icons don't respond to taps. The fix is twofold:

1. Make sure that taskbar insets are always updated when
   BubbleStashController#setBubblesShowingOnHome is called.
2. Update the touchable region in TaskbarInsetsController to account
   for the Y translation of the bubble bar bounds when the bubble
   bar is visible.

Demo: https://screenshot.googleplex.com/6NRyu2CR7Bjs32x

Bug: 286247080
Test: Manual on a physical device
Change-Id: I00daff8341e4d8f5d141b5e0220726f6c03b437c
diff --git a/quickstep/res/layout/transient_taskbar.xml b/quickstep/res/layout/transient_taskbar.xml
index bf4b811..7a6d16a 100644
--- a/quickstep/res/layout/transient_taskbar.xml
+++ b/quickstep/res/layout/transient_taskbar.xml
@@ -44,7 +44,6 @@
         android:layout_height="@dimen/bubblebar_size"
         android:layout_gravity="bottom|end"
         android:layout_marginEnd="@dimen/transient_taskbar_bottom_margin"
-        android:layout_marginBottom="@dimen/transient_taskbar_bottom_margin"
         android:paddingEnd="@dimen/taskbar_icon_spacing"
         android:paddingStart="@dimen/taskbar_icon_spacing"
         android:visibility="gone"
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
index 07cd8ff..2062e2c 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
@@ -123,9 +123,11 @@
 
         val taskbarTouchableHeight = controllers.taskbarStashController.touchableHeight
         val bubblesTouchableHeight =
-            if (controllers.bubbleControllers.isPresent)
+            if (controllers.bubbleControllers.isPresent) {
                 controllers.bubbleControllers.get().bubbleStashController.touchableHeight
-            else 0
+            } else {
+                0
+            }
         val touchableHeight = Math.max(taskbarTouchableHeight, bubblesTouchableHeight)
 
         if (
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java
index 58c67e3..3c308b5 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java
@@ -71,7 +71,11 @@
 
     private final BubbleBarBackground mBubbleBarBackground;
 
-    // The current bounds of all the bubble bar.
+    /**
+     * The current bounds of all the bubble bar. Note that these bounds may not account for
+     * translation. The bounds should be retrieved using {@link #getBubbleBarBounds()} which
+     * updates the bounds and accounts for translation.
+     */
     private final Rect mBubbleBarBounds = new Rect();
     // The amount the bubbles overlap when they are stacked in the bubble bar
     private final float mIconOverlapAmount;
@@ -175,9 +179,11 @@
     }
 
     /**
-     * Returns the bounds of the bubble bar.
+     * Updates the bounds with translation that may have been applied and returns the result.
      */
     public Rect getBubbleBarBounds() {
+        mBubbleBarBounds.top = getTop() + (int) getTranslationY();
+        mBubbleBarBounds.bottom = getBottom() + (int) getTranslationY();
         return mBubbleBarBounds;
     }
 
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashController.java
index b3c7d41..59b38ea 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashController.java
@@ -15,6 +15,8 @@
  */
 package com.android.launcher3.taskbar.bubbles;
 
+import static java.lang.Math.abs;
+
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
@@ -125,6 +127,10 @@
             mBubblesShowingOnHome = onHome;
             if (mBubblesShowingOnHome) {
                 showBubbleBar(/* expanded= */ false);
+                // If the bubble bar is already unstashed, the taskbar touchable region won't be
+                // updated correctly, so force an update here.
+                mControllers.runAfterInit(() ->
+                        mTaskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged());
             } else if (!mBarViewController.isExpanded()) {
                 stashBubbleBar();
             }
@@ -234,8 +240,14 @@
             secondHalfDurationScale = 0.75f;
 
             // If we're on home, adjust the translation so the bubble bar aligns with hotseat.
-            final float hotseatTransY = mActivity.getDeviceProfile().getTaskbarOffsetY();
-            final float translationY = mBubblesShowingOnHome ? hotseatTransY : 0;
+            // TODO(b/286247080): Update the offset for overview.
+            final float hotseatBottomSpace = mActivity.getDeviceProfile().hotseatBarBottomSpacePx;
+            final float hotseatCellHeight = mActivity.getDeviceProfile().hotseatCellHeightPx;
+
+            final float translationY =
+                    -hotseatBottomSpace - hotseatCellHeight + mUnstashedHeight - abs(
+                            hotseatCellHeight - mUnstashedHeight) / 2;
+
             fullLengthAnimatorSet.playTogether(
                     mIconScaleForStash.animateToValue(1),
                     mIconTranslationYForStash.animateToValue(translationY));
@@ -265,6 +277,7 @@
                     if (isStashed) {
                         mBarViewController.setExpanded(false);
                     }
+                    mTaskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged();
                 });
             }
         });