Bubble v2 RTL language fixes.

- Always use LTR layout direction for root view to avoid jank animation.
- Set menu button icon position (left or right) according to default locale.
- Set bubble default showing position (left or right) according to default locale.

Bug: 67605985
Test: NewBubbleIntegrationTest
PiperOrigin-RevId: 179616379
Change-Id: If418cbbf4747c2b655bc83d7c06fc0139979d94b
diff --git a/java/com/android/newbubble/NewBubble.java b/java/com/android/newbubble/NewBubble.java
index 3378ad8..469c15d 100644
--- a/java/com/android/newbubble/NewBubble.java
+++ b/java/com/android/newbubble/NewBubble.java
@@ -39,6 +39,7 @@
 import android.support.v4.graphics.ColorUtils;
 import android.support.v4.os.BuildCompat;
 import android.support.v4.view.animation.LinearOutSlowInInterpolator;
+import android.text.TextUtils;
 import android.transition.TransitionManager;
 import android.transition.TransitionValues;
 import android.view.ContextThemeWrapper;
@@ -70,6 +71,7 @@
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * Creates and manages a bubble window from information in a {@link NewBubbleInfo}. Before creating,
@@ -406,6 +408,8 @@
 
     hideAfterText = false;
 
+    boolean isRtl =
+        TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
     if (windowParams == null) {
       // Apps targeting O+ must use TYPE_APPLICATION_OVERLAY, which is not available prior to O.
       @SuppressWarnings("deprecation")
@@ -423,7 +427,7 @@
                   | LayoutParams.FLAG_NOT_FOCUSABLE
                   | LayoutParams.FLAG_LAYOUT_NO_LIMITS,
               PixelFormat.TRANSLUCENT);
-      windowParams.gravity = Gravity.TOP | Gravity.LEFT;
+      windowParams.gravity = Gravity.TOP | (isRtl ? Gravity.RIGHT : Gravity.LEFT);
       windowParams.x = leftBoundary;
       windowParams.y = currentInfo.getStartingYPosition();
       windowParams.height = LayoutParams.WRAP_CONTENT;
@@ -441,6 +445,9 @@
       viewHolder.getPrimaryButton().setScaleY(0);
       viewHolder.getPrimaryAvatar().setAlpha(0f);
       viewHolder.getPrimaryIcon().setAlpha(0f);
+      if (isRtl) {
+        onLeftRightSwitch(true);
+      }
     }
 
     viewHolder.setChildClickable(true);
@@ -795,7 +802,13 @@
   }
 
   private void configureButton(Action action, NewCheckableButton button) {
-    button.setCompoundDrawablesWithIntrinsicBounds(action.getIconDrawable(), null, null, null);
+    boolean isRtl =
+        TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
+    if (isRtl) {
+      button.setCompoundDrawablesWithIntrinsicBounds(null, null, action.getIconDrawable(), null);
+    } else {
+      button.setCompoundDrawablesWithIntrinsicBounds(action.getIconDrawable(), null, null, null);
+    }
     button.setChecked(action.isChecked());
     button.setEnabled(action.isEnabled());
     button.setText(action.getName());
diff --git a/java/com/android/newbubble/res/layout/new_bubble_base.xml b/java/com/android/newbubble/res/layout/new_bubble_base.xml
index f83b753..f6ce26d 100644
--- a/java/com/android/newbubble/res/layout/new_bubble_base.xml
+++ b/java/com/android/newbubble/res/layout/new_bubble_base.xml
@@ -21,6 +21,7 @@
     android:layout_height="wrap_content"
     android:clipChildren="true"
     android:clipToPadding="false"
+    android:layoutDirection="ltr"
     tools:theme="@style/Theme.AppCompat">
   <RelativeLayout
       android:id="@+id/bubble_primary_container"