Fix issues with RTL support

bug:8148068
Change-Id: I869e1a90686c46f8076a66f94040ad03c7c6ca10
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e7da0be..2c28010 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -42,7 +42,8 @@
             android:logo="@mipmap/ic_launcher_gallery"
             android:hardwareAccelerated="true"
             android:largeHeap="true"
-            android:restoreAnyVersion="true">
+            android:restoreAnyVersion="true"
+            android:supportsRtl="true">
         <uses-library android:name="com.google.android.media.effects" android:required="false" />
         <activity android:name="com.android.gallery3d.app.MovieActivity"
                 android:label="@string/movie_view_label"
diff --git a/res/layout-land/filtershow_grad_ui.xml b/res/layout-land/filtershow_grad_ui.xml
index 63f9418..fd09bee 100644
--- a/res/layout-land/filtershow_grad_ui.xml
+++ b/res/layout-land/filtershow_grad_ui.xml
@@ -102,18 +102,19 @@
                 android:layout_gravity="fill_horizontal"
                 style="@style/FilterShowSlider" />
     </GridLayout>
-    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:columnCount="2"
-                android:orientation="horizontal"
-                android:layout_marginTop="24dp" >
+    <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:layout_marginTop="24dp">
 
-    <ImageButton
+
+        <ImageButton
             android:id="@+id/gradAddButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_gravity="left|center_vertical"
+            android:layout_gravity="start|center_vertical"
+            android:gravity="start"
             android:scaleType="centerInside"
             android:layout_weight="0"
             android:background="@drawable/filtershow_button_background"
@@ -121,16 +122,24 @@
             android:paddingBottom="8dp"
             android:layout_marginLeft="48dp" />
 
-    <ImageButton
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="8dp"
+            android:layout_weight="1"/>
+
+        <ImageButton
             android:id="@+id/gradDelButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_gravity="right|center_vertical"
+            android:layout_gravity="end|center_vertical"
+            android:gravity="end"
             android:scaleType="centerInside"
             android:layout_weight="0"
             android:background="@drawable/filtershow_button_background"
             android:src="@drawable/ic_menu_trash_holo_light"
             android:paddingBottom="8dp"
             android:layout_marginRight="48dp" />
-    </GridLayout>
+
+    </LinearLayout>
+
 </LinearLayout>
diff --git a/res/layout/filtershow_control_action_slider.xml b/res/layout/filtershow_control_action_slider.xml
index a3ef3ed..34eac1e 100644
--- a/res/layout/filtershow_control_action_slider.xml
+++ b/res/layout/filtershow_control_action_slider.xml
@@ -25,7 +25,7 @@
         android:id="@+id/leftActionButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="left|center_vertical"
+        android:layout_gravity="start|center_vertical"
         android:scaleType="centerInside"
         android:layout_weight="0"
         android:background="@drawable/filtershow_button_background"
@@ -44,7 +44,7 @@
         android:id="@+id/rightActionButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="left|center_vertical"
+        android:layout_gravity="end|center_vertical"
         android:scaleType="centerInside"
         android:layout_weight="0"
         android:background="@drawable/filtershow_button_background"
diff --git a/src/com/android/gallery3d/filtershow/state/StateView.java b/src/com/android/gallery3d/filtershow/state/StateView.java
index 56c97ab..a43cd47 100644
--- a/src/com/android/gallery3d/filtershow/state/StateView.java
+++ b/src/com/android/gallery3d/filtershow/state/StateView.java
@@ -166,22 +166,42 @@
     }
 
     private void drawHorizontalPath(float w, float h, float r, float d) {
-        mPath.moveTo(0, 0);
-        if (mType == END) {
-            mPath.lineTo(w, 0);
+        if (this.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
+            mPath.moveTo(w, 0);
+            if (mType == END) {
+                mPath.lineTo(0, 0);
+                mPath.lineTo(0, h);
+            } else {
+                mPath.lineTo(d, 0);
+                mPath.lineTo(d, r);
+                mPath.lineTo(0, r + d);
+                mPath.lineTo(d, r + d + r);
+                mPath.lineTo(d, h);
+            }
             mPath.lineTo(w, h);
+            if (mType != BEGIN) {
+                mPath.lineTo(w, r + d + r);
+                mPath.lineTo(w - d, r + d);
+                mPath.lineTo(w, r);
+            }
         } else {
-            mPath.lineTo(w - d, 0);
-            mPath.lineTo(w - d, r);
-            mPath.lineTo(w, r + d);
-            mPath.lineTo(w - d, r + d + r);
-            mPath.lineTo(w - d, h);
-        }
-        mPath.lineTo(0, h);
-        if (mType != BEGIN) {
-            mPath.lineTo(0, r + d + r);
-            mPath.lineTo(d, r + d);
-            mPath.lineTo(0, r);
+            mPath.moveTo(0, 0);
+            if (mType == END) {
+                mPath.lineTo(w, 0);
+                mPath.lineTo(w, h);
+            } else {
+                mPath.lineTo(w - d, 0);
+                mPath.lineTo(w - d, r);
+                mPath.lineTo(w, r + d);
+                mPath.lineTo(w - d, r + d + r);
+                mPath.lineTo(w - d, h);
+            }
+            mPath.lineTo(0, h);
+            if (mType != BEGIN) {
+                mPath.lineTo(0, r + d + r);
+                mPath.lineTo(d, r + d);
+                mPath.lineTo(0, r);
+            }
         }
         mPath.close();
     }