Adding horizontalDirection public attribute for View.

Change-Id: Ic8a03447252e4e155c3ee874b1d8c8ac0bc9f7f5
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 791ffb9..f8d48da 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -951,6 +951,43 @@
     static final int PARENT_SAVE_DISABLED_MASK = 0x20000000;
 
     /**
+     * Horizontal direction of this view is from Left to Right.
+     * Use with {@link #setHorizontalDirection}.
+     * {@hide}
+     */
+    public static final int HORIZONTAL_DIRECTION_LTR = 0x00000000;
+
+    /**
+     * Horizontal direction of this view is from Right to Left.
+     * Use with {@link #setHorizontalDirection}.
+     * {@hide}
+     */
+    public static final int HORIZONTAL_DIRECTION_RTL = 0x40000000;
+
+    /**
+     * Horizontal direction of this view is inherited from its parent.
+     * Use with {@link #setHorizontalDirection}.
+     * {@hide}
+     */
+    public static final int HORIZONTAL_DIRECTION_INHERIT = 0x80000000;
+
+    /**
+     * Horizontal direction of this view is from deduced from the default language
+     * script for the locale. Use with {@link #setHorizontalDirection}.
+     * {@hide}
+     */
+    public static final int HORIZONTAL_DIRECTION_LOCALE = 0xC0000000;
+
+    /**
+     * Mask for use with setFlags indicating bits used for horizontalDirection.
+     * {@hide}
+     */
+    static final int HORIZONTAL_DIRECTION_MASK = 0xC0000000;
+
+    private static final int[] HORIZONTAL_DIRECTION_FLAGS = { HORIZONTAL_DIRECTION_LTR,
+            HORIZONTAL_DIRECTION_RTL, HORIZONTAL_DIRECTION_INHERIT, HORIZONTAL_DIRECTION_LOCALE};
+
+    /**
      * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
      * should add all focusable Views regardless if they are focusable in touch mode.
      */
@@ -2598,6 +2635,13 @@
                         viewFlagMasks |= VISIBILITY_MASK;
                     }
                     break;
+                case com.android.internal.R.styleable.View_horizontalDirection:
+                  final int layoutDirection = a.getInt(attr, 0);
+                  if (layoutDirection != 0) {
+                      viewFlagValues |= HORIZONTAL_DIRECTION_FLAGS[layoutDirection];
+                      viewFlagMasks |= HORIZONTAL_DIRECTION_MASK;
+                  }
+                  break;
                 case com.android.internal.R.styleable.View_drawingCacheQuality:
                     final int cacheQuality = a.getInt(attr, 0);
                     if (cacheQuality != 0) {
@@ -3980,6 +4024,41 @@
     }
 
     /**
+     * Returns the horizontal direction for this view.
+     *
+     * @return One of {@link #HORIZONTAL_DIRECTION_LTR},
+     *   {@link #HORIZONTAL_DIRECTION_RTL},
+     *   {@link #HORIZONTAL_DIRECTION_INHERIT} or
+     *   {@link #HORIZONTAL_DIRECTION_LOCALE}.
+     * @attr ref android.R.styleable#View_horizontalDirection
+     * @hide
+     */
+    @ViewDebug.ExportedProperty(mapping = {
+        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_LTR,     to = "LTR"),
+        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_RTL,     to = "RTL"),
+        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_INHERIT, to = "INHERIT"),
+        @ViewDebug.IntToString(from = HORIZONTAL_DIRECTION_LOCALE,  to = "LOCALE")
+    })
+    public int getHorizontalDirection() {
+        return mViewFlags & HORIZONTAL_DIRECTION_MASK;
+    }
+
+    /**
+     * Set the horizontal direction for this view.
+     *
+     * @param horizontalDirection One of {@link #HORIZONTAL_DIRECTION_LTR},
+     *   {@link #HORIZONTAL_DIRECTION_RTL},
+     *   {@link #HORIZONTAL_DIRECTION_INHERIT} or
+     *   {@link #HORIZONTAL_DIRECTION_LOCALE}.
+     * @attr ref android.R.styleable#View_horizontalDirection
+     * @hide
+     */
+    @RemotableViewMethod
+    public void setHorizontalDirection(int horizontalDirection) {
+        setFlags(horizontalDirection, HORIZONTAL_DIRECTION_MASK);
+    }
+
+    /**
      * If this view doesn't do any drawing on its own, set this flag to
      * allow further optimizations. By default, this flag is not set on
      * View, but could be set on some View subclasses such as ViewGroup.
@@ -5789,6 +5868,10 @@
                 mParent.recomputeViewAttributes(this);
             }
         }
+
+        if ((changed & HORIZONTAL_DIRECTION_MASK) != 0) {
+            requestLayout();
+        }
     }
 
     /**