Fix RTL issue of ImageFloatingTextView

Sometimes, makeSingleLayout() can be invoked before layout direction is resolved.
When not resolved, it indents in LTR layout although it should be RTL.

So, to guarantee the exact indenting, we should re-build the text layout
when the layout direction is changed.

Test: manual - Test BigTextStyle notifications with LargeIcon under RTL configurations.
Fixes: 31633875
Change-Id: Idc6c5d7d41632cb9e1b70d9c67c13852e3f25023
diff --git a/core/java/com/android/internal/widget/ImageFloatingTextView.java b/core/java/com/android/internal/widget/ImageFloatingTextView.java
index 926ebd1..358be60 100644
--- a/core/java/com/android/internal/widget/ImageFloatingTextView.java
+++ b/core/java/com/android/internal/widget/ImageFloatingTextView.java
@@ -40,6 +40,9 @@
     /** Number of lines from the top to indent */
     private int mIndentLines;
 
+    /** Resolved layout direction */
+    private int mResolvedDirection = LAYOUT_DIRECTION_UNDEFINED;
+
     public ImageFloatingTextView(Context context) {
         this(context, null);
     }
@@ -82,7 +85,7 @@
                 margins[i] = endMargin;
             }
         }
-        if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
+        if (mResolvedDirection == LAYOUT_DIRECTION_RTL) {
             builder.setIndents(margins, null);
         } else {
             builder.setIndents(null, margins);
@@ -91,6 +94,19 @@
         return builder.build();
     }
 
+    @Override
+    public void onRtlPropertiesChanged(int layoutDirection) {
+        super.onRtlPropertiesChanged(layoutDirection);
+
+        if (layoutDirection != mResolvedDirection && isLayoutDirectionResolved()) {
+            mResolvedDirection = layoutDirection;
+            if (mIndentLines > 0) {
+                // Invalidate layout.
+                setHint(getHint());
+            }
+        }
+    }
+
     @RemotableViewMethod
     public void setHasImage(boolean hasImage) {
         setNumIndentLines(hasImage ? 2 : 0);