Merge "Mirror background_image's background in RTL." into qt-car-dev am: a171b3faff

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Car/libs/+/11829856

Change-Id: I26aae0c544a173e17e3c207786d521004bed1587
diff --git a/car-apps-common/res/drawable-ldrtl/background_image_scrim.xml b/car-apps-common/res/drawable-ldrtl/background_image_scrim.xml
new file mode 100644
index 0000000..9035a65
--- /dev/null
+++ b/car-apps-common/res/drawable-ldrtl/background_image_scrim.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape>
+            <gradient
+                android:angle="270"
+                android:startColor="#F5000000"
+                android:centerColor="@android:color/transparent"
+                android:endColor="#F5000000"/>
+        </shape>
+    </item>
+    <item>
+        <shape>
+            <gradient
+                android:angle="180"
+                android:centerX="0.52"
+                android:startColor="@android:color/transparent"
+                android:centerColor="@android:color/black"
+                android:endColor="@android:color/black" />
+        </shape>
+    </item>
+    <item>
+        <shape>
+            <gradient
+                android:angle="180"
+                android:centerX="0.62"
+                android:startColor="@android:color/transparent"
+                android:centerColor="#B3000000"
+                android:endColor="#B3000000" />
+        </shape>
+    </item>
+    <item>
+        <shape>
+            <solid android:color="@color/background_image_30p_black"/>
+        </shape>
+    </item>
+</layer-list>
diff --git a/car-apps-common/res/layout-port/background_image.xml b/car-apps-common/res/layout-port/background_image.xml
index e7c547c..7e4ee8e 100644
--- a/car-apps-common/res/layout-port/background_image.xml
+++ b/car-apps-common/res/layout-port/background_image.xml
@@ -22,11 +22,11 @@
         android:id="@+id/background_image_image"
         android:layout_width="0dp"
         android:layout_height="0dp"
-        app:align_horizontal="left"
+        app:align_horizontal="start"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"/>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"/>
 
     <View
         android:layout_width="0dp"
@@ -34,8 +34,8 @@
         android:background="@drawable/background_image_scrim"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"/>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"/>
 
     <View
         android:id="@+id/background_image_darkening_scrim"
@@ -45,6 +45,6 @@
         android:visibility="gone"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toRightOf="parent"
-        app:layout_constraintRight_toRightOf="parent"/>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"/>
 </merge>
diff --git a/car-apps-common/res/layout/background_image.xml b/car-apps-common/res/layout/background_image.xml
index f230600..bb889ea 100644
--- a/car-apps-common/res/layout/background_image.xml
+++ b/car-apps-common/res/layout/background_image.xml
@@ -29,11 +29,11 @@
         android:id="@+id/background_image_image"
         android:layout_width="0dp"
         android:layout_height="0dp"
-        app:align_horizontal="right"
+        app:align_horizontal="end"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toLeftOf="@+id/background_image_guideline"/>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toStartOf="@+id/background_image_guideline"/>
 
     <View
         android:layout_width="0dp"
@@ -41,8 +41,8 @@
         android:background="@drawable/background_image_scrim"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"/>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"/>
 
     <View
         android:id="@+id/background_image_darkening_scrim"
@@ -52,6 +52,6 @@
         android:visibility="gone"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toRightOf="parent"
-        app:layout_constraintRight_toRightOf="parent"/>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"/>
 </merge>
diff --git a/car-apps-common/res/values/attrs.xml b/car-apps-common/res/values/attrs.xml
index 3c3c40e..0f953ee 100644
--- a/car-apps-common/res/values/attrs.xml
+++ b/car-apps-common/res/values/attrs.xml
@@ -40,8 +40,8 @@
     <declare-styleable name="CrossfadeImageView">
         <attr name="align_horizontal" format="enum">
             <enum name="center" value="0"/>
-            <enum name="left" value="1"/>
-            <enum name="right" value="2"/>
+            <enum name="start" value="1"/>
+            <enum name="end" value="2"/>
         </attr>
     </declare-styleable>
 
diff --git a/car-apps-common/src/com/android/car/apps/common/CropAlignedImageView.java b/car-apps-common/src/com/android/car/apps/common/CropAlignedImageView.java
index f11f33b..0adbcf6 100644
--- a/car-apps-common/src/com/android/car/apps/common/CropAlignedImageView.java
+++ b/car-apps-common/src/com/android/car/apps/common/CropAlignedImageView.java
@@ -19,9 +19,13 @@
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Matrix;
+import android.text.TextUtils;
 import android.util.AttributeSet;
+import android.view.View;
 import android.widget.ImageView;
 
+import java.util.Locale;
+
 /**
  * A {@link ImageView} that scales in a similar way as {@link ScaleType#CENTER_CROP} but aligning
  * the image to the specified edge of the view.
@@ -29,8 +33,8 @@
 public class CropAlignedImageView extends ImageView {
 
     private static final int ALIGN_HORIZONTAL_CENTER = 0;
-    private static final int ALIGN_HORIZONTAL_LEFT = 1;
-    private static final int ALIGN_HORIZONTAL_RIGHT = 2;
+    private static final int ALIGN_HORIZONTAL_START = 1;
+    private static final int ALIGN_HORIZONTAL_END = 2;
 
     private int mAlignHorizontal;
     private float mAdditionalScale = 1f;
@@ -82,6 +86,8 @@
             float fitHorizontallyScaleFactor = mFrameWidth / originalImageWidth;
             float fitVerticallyScaleFactor = mFrameHeight / originalImageHeight;
             float usedScaleFactor = Math.max(fitHorizontallyScaleFactor, fitVerticallyScaleFactor);
+            int layoutDirection = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault());
+            boolean isRTL = layoutDirection == View.LAYOUT_DIRECTION_RTL;
 
             // mAdditionalScale isn't factored into the fittedImageWidth
             // because we want to scale from the center of the fitted image, so our translations
@@ -97,11 +103,11 @@
                 case ALIGN_HORIZONTAL_CENTER:
                     dx = mFrameWidth / 2f;
                     break;
-                case ALIGN_HORIZONTAL_LEFT:
-                    dx = fittedImageWidth / 2f;
+                case ALIGN_HORIZONTAL_START:
+                    dx = isRTL ? (mFrameWidth - fittedImageWidth / 2f) : fittedImageWidth / 2f;
                     break;
-                case ALIGN_HORIZONTAL_RIGHT:
-                    dx = (mFrameWidth - fittedImageWidth / 2f);
+                case ALIGN_HORIZONTAL_END:
+                    dx = isRTL ? fittedImageWidth / 2f : (mFrameWidth - fittedImageWidth / 2f);
                     break;
             }
             matrix.postTranslate(dx, mFrameHeight / 2f);
diff --git a/car-media-common/res/layout/playback_fragment.xml b/car-media-common/res/layout/playback_fragment.xml
index 7123be2..17e10b0 100644
--- a/car-media-common/res/layout/playback_fragment.xml
+++ b/car-media-common/res/layout/playback_fragment.xml
@@ -63,6 +63,7 @@
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:singleLine="true"
             android:includeFontPadding="false"
+            android:textAlignment="viewStart"
             app:layout_constraintStart_toEndOf="@+id/app_icon"
             app:layout_constraintEnd_toStartOf="@+id/app_selector_container"
             app:layout_constraintTop_toTopOf="parent"/>
diff --git a/car-media-common/res/values/attrs.xml b/car-media-common/res/values/attrs.xml
index 75ff716..04e2dbb 100644
--- a/car-media-common/res/values/attrs.xml
+++ b/car-media-common/res/values/attrs.xml
@@ -34,8 +34,8 @@
     <declare-styleable name="CrossfadeImageView">
         <attr name="align_horizontal" format="enum">
             <enum name="center" value="0"/>
-            <enum name="left" value="1"/>
-            <enum name="right" value="2"/>
+            <enum name="start" value="1"/>
+            <enum name="end" value="2"/>
         </attr>
     </declare-styleable>
 </resources>