Merge "Fix mic diclosure in RTL" into rvc-dev
diff --git a/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml b/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml
index cd90efe..1d2340d 100644
--- a/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml
+++ b/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml
@@ -45,7 +45,7 @@
                     android:id="@+id/icon_mic"
                     android:layout_width="35dp"
                     android:layout_height="35dp"
-                    android:layout_marginLeft="6dp"
+                    android:layout_marginStart="6dp"
                     android:layout_marginTop="6dp"
                     android:layout_marginBottom="6dp">
 
@@ -112,7 +112,7 @@
     </FrameLayout>
 
     <View
-        android:id="@+id/bg_right"
+        android:id="@+id/bg_end"
         android:layout_width="12dp"
         android:layout_height="47dp"
         android:background="@drawable/tv_rect_dark_right_rounded"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java
index 8b85a09..36e360d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java
@@ -99,9 +99,10 @@
     private View mIconTextsContainer;
     private View mIconContainerBg;
     private View mIcon;
-    private View mBgRight;
+    private View mBgEnd;
     private View mTextsContainers;
     private TextView mTextView;
+    private boolean mIsLtr;
 
     @State private int mState = STATE_NOT_SHOWN;
 
@@ -232,6 +233,9 @@
             Log.d(TAG, "Showing indicator for " + packageName + " (" + label + ")...");
         }
 
+        mIsLtr = mContext.getResources().getConfiguration().getLayoutDirection()
+                == View.LAYOUT_DIRECTION_LTR;
+
         // Inflate the indicator view
         mIndicatorView = LayoutInflater.from(mContext).inflate(
                 R.layout.tv_audio_recording_indicator,
@@ -241,7 +245,17 @@
         mIcon = mIconTextsContainer.findViewById(R.id.icon_mic);
         mTextsContainers = mIconTextsContainer.findViewById(R.id.texts_container);
         mTextView = mTextsContainers.findViewById(R.id.text);
-        mBgRight = mIndicatorView.findViewById(R.id.bg_right);
+        mBgEnd = mIndicatorView.findViewById(R.id.bg_end);
+
+        // Swap background drawables depending on layout directions (both drawables have rounded
+        // corners only on one side)
+        if (mIsLtr) {
+            mBgEnd.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded);
+            mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_left_rounded);
+        } else {
+            mBgEnd.setBackgroundResource(R.drawable.tv_rect_dark_left_rounded);
+            mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded);
+        }
 
         // Set up the notification text
         mTextView.setText(mContext.getString(R.string.app_accessed_mic, label));
@@ -261,7 +275,8 @@
 
                                 // Now that the width of the indicator has been assigned, we can
                                 // move it in from off the screen.
-                                final int initialOffset = mIndicatorView.getWidth();
+                                final int initialOffset =
+                                        (mIsLtr ? 1 : -1) * mIndicatorView.getWidth();
                                 final AnimatorSet set = new AnimatorSet();
                                 set.setDuration(ANIMATION_DURATION);
                                 set.playTogether(
@@ -294,7 +309,7 @@
                 WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                 PixelFormat.TRANSLUCENT);
-        layoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
+        layoutParams.gravity = Gravity.TOP | (mIsLtr ? Gravity.RIGHT : Gravity.LEFT);
         layoutParams.setTitle(LAYOUT_PARAMS_TITLE);
         layoutParams.packageName = mContext.getPackageName();
         final WindowManager windowManager = (WindowManager) mContext.getSystemService(
@@ -317,7 +332,7 @@
                 ObjectAnimator.ofFloat(mIconTextsContainer, View.TRANSLATION_X, 0),
                 ObjectAnimator.ofFloat(mIconContainerBg, View.ALPHA, 1f),
                 ObjectAnimator.ofFloat(mTextsContainers, View.ALPHA, 1f),
-                ObjectAnimator.ofFloat(mBgRight, View.ALPHA, 1f));
+                ObjectAnimator.ofFloat(mBgEnd, View.ALPHA, 1f));
         set.setDuration(ANIMATION_DURATION);
         set.addListener(
                 new AnimatorListenerAdapter() {
@@ -334,13 +349,13 @@
     @UiThread
     private void minimize() {
         if (DEBUG) Log.d(TAG, "Minimizing...");
-        final int targetOffset = mTextsContainers.getWidth();
+        final int targetOffset = (mIsLtr ? 1 : -1) * mTextsContainers.getWidth();
         final AnimatorSet set = new AnimatorSet();
         set.playTogether(
                 ObjectAnimator.ofFloat(mIconTextsContainer, View.TRANSLATION_X, targetOffset),
                 ObjectAnimator.ofFloat(mIconContainerBg, View.ALPHA, 0f),
                 ObjectAnimator.ofFloat(mTextsContainers, View.ALPHA, 0f),
-                ObjectAnimator.ofFloat(mBgRight, View.ALPHA, 0f));
+                ObjectAnimator.ofFloat(mBgEnd, View.ALPHA, 0f));
         set.setDuration(ANIMATION_DURATION);
         set.addListener(
                 new AnimatorListenerAdapter() {
@@ -357,8 +372,8 @@
     @UiThread
     private void hide() {
         if (DEBUG) Log.d(TAG, "Hiding...");
-        final int targetOffset =
-                mIndicatorView.getWidth() - (int) mIconTextsContainer.getTranslationX();
+        final int targetOffset = (mIsLtr ? 1 : -1) * (mIndicatorView.getWidth()
+                - (int) mIconTextsContainer.getTranslationX());
         final AnimatorSet set = new AnimatorSet();
         set.playTogether(
                 ObjectAnimator.ofFloat(mIndicatorView, View.TRANSLATION_X, targetOffset),
@@ -411,7 +426,7 @@
         mIcon = null;
         mTextsContainers = null;
         mTextView = null;
-        mBgRight = null;
+        mBgEnd = null;
 
         mState = STATE_NOT_SHOWN;