View horizontalDirection public attribute resolution to an internal var.
Change-Id: Id87ab188faef27ff039cf6a400118707ee74a27d
diff --git a/api/current.txt b/api/current.txt
index 29c6b1a..fb8ff22 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -21235,6 +21235,7 @@
method public boolean isInEditMode();
method public boolean isInTouchMode();
method public boolean isLayoutRequested();
+ method public boolean isLayoutRtl();
method public boolean isLongClickable();
method public boolean isOpaque();
method protected boolean isPaddingOffsetRequired();
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index f8d48da..8aa2b87 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -1709,6 +1709,13 @@
*/
static final int DRAG_HOVERED = 0x00000002;
+ /**
+ * Indicates whether the view is drawn in right-to-left direction.
+ *
+ * @hide
+ */
+ static final int RESOLVED_LAYOUT_RTL = 0x00000004;
+
/* End of masks for mPrivateFlags2 */
static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED;
@@ -8402,6 +8409,21 @@
mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH;
}
jumpDrawablesToCurrentState();
+
+ // Resolving the layout direction. LTR is set initially.
+ mPrivateFlags2 &= ~RESOLVED_LAYOUT_RTL;
+ switch (getHorizontalDirection()) {
+ case HORIZONTAL_DIRECTION_INHERIT:
+ // If this is root view, no need to look at parent's layout dir.
+ if (mParent != null && mParent instanceof ViewGroup &&
+ ((ViewGroup) mParent).isLayoutRtl()) {
+ mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
+ }
+ break;
+ case HORIZONTAL_DIRECTION_RTL:
+ mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
+ break;
+ }
}
/**
@@ -9888,6 +9910,16 @@
}
/**
+ * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from
+ * layout attribute and/or the inherited value from the parent.</p>
+ *
+ * @return true if the layout is right-to-left.
+ */
+ public boolean isLayoutRtl() {
+ return (mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL;
+ }
+
+ /**
* Assign a size and position to a view and all of its
* descendants
*