Adding horizontalDirection public attribute for View.
Change-Id: Ic8a03447252e4e155c3ee874b1d8c8ac0bc9f7f5
diff --git a/api/current.txt b/api/current.txt
index 1f6d673..29c6b1a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -475,6 +475,7 @@
field public static final int hint = 16843088; // 0x1010150
field public static final int homeAsUpIndicator = 16843531; // 0x101030b
field public static final int homeLayout = 16843549; // 0x101031d
+ field public static final int horizontalDirection = 16843628; // 0x101036c
field public static final int horizontalDivider = 16843053; // 0x101012d
field public static final int horizontalGap = 16843327; // 0x101023f
field public static final int horizontalScrollViewStyle = 16843603; // 0x1010353
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();
+ }
}
/**
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index dac3bd2..a542c3a 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -1913,6 +1913,22 @@
more information. -->
<enum name="hardware" value="2" />
</attr>
+
+ <!-- Defines the direction of layout drawing. This typically is associated with writing
+ direction of the language script used. The possible values are Left-to-Right,
+ Right-to-Left, Locale and Inherit from parent view. If there is nothing to inherit,
+ Locale is used. Locale fallsback to 'en-US'. Left-to-Right is the direction used in
+ 'en-US'. The default for this attribute is 'inherit'. -->
+ <attr name="horizontalDirection">
+ <!-- Left-to-Right -->
+ <enum name="ltr" value="0" />
+ <!-- Right-to-Left -->
+ <enum name="rtl" value="1" />
+ <!-- Inherit from parent -->
+ <enum name="inherit" value="2" />
+ <!-- Locale -->
+ <enum name="locale" value="3" />
+ </attr>
</declare-styleable>
<!-- Attributes that can be used with a {@link android.view.ViewGroup} or any
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 7ca5e98..46db62e 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1667,5 +1667,6 @@
<public type="attr" name="textEditSuggestionsBottomWindowLayout" />
<public type="attr" name="textEditSuggestionsTopWindowLayout" />
<public type="attr" name="textEditSuggestionItemLayout" />
+ <public type="attr" name="horizontalDirection" />
</resources>