Merge "Fix bubble translation when released after dragging" into main
diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java
index f3ac1e4..43fe251 100644
--- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java
+++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java
@@ -394,21 +394,24 @@
      * from the internal location that was used during bubble bar layout, translation values are
      * calculated to position the bar at the desired location.
      *
-     * @param initialTranslation initial bubble bar translation at the start of drag
+     * @param initialTranslation initial bubble translation inside the bar at the start of drag
      * @param location           desired location of the bubble bar when drag is released
      * @return point with x and y values representing translation on x and y-axis
      */
     public PointF getDraggedBubbleReleaseTranslation(PointF initialTranslation,
             BubbleBarLocation location) {
-        // Start with bubble bar translation
-        final PointF dragEndTranslation = new PointF(
-                getBubbleBarDragReleaseTranslation(initialTranslation, location));
-        // Apply individual bubble translation, as the order may have changed
-        int viewIndex = indexOfChild(mDraggedBubbleView);
-        dragEndTranslation.x += getExpandedBubbleTranslationX(viewIndex,
-                getChildCount(),
-                location.isOnLeft(isLayoutRtl()));
-        return dragEndTranslation;
+        float dragEndTranslationX = initialTranslation.x;
+        boolean newLocationOnLeft = location.isOnLeft(isLayoutRtl());
+        if (getBubbleBarLocation().isOnLeft(isLayoutRtl()) != newLocationOnLeft) {
+            // Calculate translationX based on bar and bubble translations
+            float bubbleBarTx = getBubbleBarDragReleaseTranslation(initialTranslation, location).x;
+            float bubbleTx =
+                    getExpandedBubbleTranslationX(
+                            indexOfChild(mDraggedBubbleView), getChildCount(), newLocationOnLeft);
+            dragEndTranslationX = bubbleBarTx + bubbleTx;
+        }
+        // translationY does not change during drag and can be reused
+        return new PointF(dragEndTranslationX, initialTranslation.y);
     }
 
     private float getDistanceFromOtherSide() {