From fed87296db4b2caf765aa00528734d3924060fb4 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Tue, 24 May 2022 17:12:50 +0000 Subject: [PATCH] Fix the pointer position when displayed in RTL When displaying in RTL, the pointer translates from the opposite side of the screen than the code assumes. This CL changes the math for the pointer position when displaying in RTL. Test: manual - test landscape / portrait on tablet / phone in LTR and RTL: have a couple of bubbles, expand the stack and select each bubble ensuring that the pointer is centered on the selection. Bug: 230579507 Bug: 233950592 Change-Id: I71a6f64a43c1b7bb5e0a30773d4cc5ae55c63b6a Merged-In: I71a6f64a43c1b7bb5e0a30773d4cc5ae55c63b6a --- .../wm/shell/bubbles/BubbleExpandedView.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleExpandedView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleExpandedView.java index a089585a5a004..b8bf1a8e497e7 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleExpandedView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleExpandedView.java @@ -706,6 +706,8 @@ public class BubbleExpandedView extends LinearLayout { * @param animate whether the pointer should animate to this position. */ public void setPointerPosition(float bubblePosition, boolean onLeft, boolean animate) { + final boolean isRtl = mContext.getResources().getConfiguration().getLayoutDirection() + == LAYOUT_DIRECTION_RTL; // Pointer gets drawn in the padding final boolean showVertically = mPositioner.showBubblesVertically(); final float paddingLeft = (showVertically && onLeft) @@ -732,12 +734,22 @@ public class BubbleExpandedView extends LinearLayout { float pointerX; if (showVertically) { pointerY = bubbleCenter - (mPointerWidth / 2f); - pointerX = onLeft - ? -mPointerHeight + mPointerOverlap - : getWidth() - mPaddingRight - mPointerOverlap; + if (!isRtl) { + pointerX = onLeft + ? -mPointerHeight + mPointerOverlap + : getWidth() - mPaddingRight - mPointerOverlap; + } else { + pointerX = onLeft + ? -(getWidth() - mPaddingLeft - mPointerOverlap) + : mPointerHeight - mPointerOverlap; + } } else { pointerY = mPointerOverlap; - pointerX = bubbleCenter - (mPointerWidth / 2f); + if (!isRtl) { + pointerX = bubbleCenter - (mPointerWidth / 2f); + } else { + pointerX = -(getWidth() - mPaddingLeft - bubbleCenter) + (mPointerWidth / 2f); + } } if (animate) { mPointerView.animate().translationX(pointerX).translationY(pointerY).start();