Add View.getResolvedLayoutDirection()
- update Callback2 interface
- update Gravity.getAbsoluteGravity() and Gravity.apply() to be more generic
by changing "boolean isRtl" parameter to "int layoutDirection"
- fix BiDiTests for RTL FrameLayout
Change-Id: I97bb456c22d5fd3ecb34f08564ce4dbed37e7459
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 071905c..1dfb858 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4272,6 +4272,7 @@
* {@link #LAYOUT_DIRECTION_INHERIT} or
* {@link #LAYOUT_DIRECTION_LOCALE}.
* @attr ref android.R.styleable#View_layoutDirection
+ *
* @hide
*/
@ViewDebug.ExportedProperty(category = "layout", mapping = {
@@ -4292,6 +4293,7 @@
* {@link #LAYOUT_DIRECTION_INHERIT} or
* {@link #LAYOUT_DIRECTION_LOCALE}.
* @attr ref android.R.styleable#View_layoutDirection
+ *
* @hide
*/
@RemotableViewMethod
@@ -4300,6 +4302,37 @@
}
/**
+ * Returns the resolved layout direction for this view.
+ *
+ * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns
+ * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL.
+ *
+ * @hide
+ */
+ @ViewDebug.ExportedProperty(category = "layout", mapping = {
+ @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"),
+ @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
+ })
+ public int getResolvedLayoutDirection() {
+ resolveLayoutDirection();
+ return ((mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL) ?
+ LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
+ }
+
+ /**
+ * <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.
+ *
+ * @hide
+ */
+ @ViewDebug.ExportedProperty(category = "layout")
+ public boolean isLayoutRtl() {
+ return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL);
+ }
+
+ /**
* 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.
@@ -8713,8 +8746,9 @@
switch (getLayoutDirection()) {
case LAYOUT_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()) {
+ if (mParent != null &&
+ mParent instanceof ViewGroup &&
+ ((ViewGroup) mParent).getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
mPrivateFlags2 |= RESOLVED_LAYOUT_RTL;
}
break;
@@ -10237,17 +10271,6 @@
}
/**
- * <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.
- */
- @ViewDebug.ExportedProperty(category = "layout")
- public boolean isLayoutRtl() {
- return (mPrivateFlags2 & RESOLVED_LAYOUT_RTL) == RESOLVED_LAYOUT_RTL;
- }
-
- /**
* Assign a size and position to a view and all of its
* descendants
*
@@ -10459,13 +10482,15 @@
}
}
- /**
- * Check if a given Drawable is in RTL layout direction.
- *
- * @param who the recipient of the action
- */
- public boolean isLayoutRtl(Drawable who) {
- return (who == mBGDrawable) && isLayoutRtl();
+ /**
+ * Return the layout direction of a given Drawable.
+ *
+ * @param who the Drawable to query
+ *
+ * @hide
+ */
+ public int getResolvedLayoutDirection(Drawable who) {
+ return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT;
}
/**