Improve resolution of inherited layout direction
allow to resolve it even more lazily: if resolution is asked then do it
only if possible (the View needs to have a parent that can also do its
resolution)
Change-Id: I8e808f0ef392521e59b27b82f86e9058f20af9ba
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index e680d41..f816145 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -5704,7 +5704,7 @@
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
})
public int getResolvedLayoutDirection() {
- // The layout diretion will be resolved only if needed
+ // The layout direction will be resolved only if needed
if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) {
resolveLayoutDirection();
}
@@ -11466,15 +11466,18 @@
// Set resolved depending on layout direction
switch (getLayoutDirection()) {
case LAYOUT_DIRECTION_INHERIT:
- // If this is root view, no need to look at parent's layout dir.
- if (canResolveLayoutDirection()) {
- ViewGroup viewGroup = ((ViewGroup) mParent);
+ // We cannot resolve yet. LTR is by default and let the resolution happen again
+ // later to get the correct resolved value
+ if (!canResolveLayoutDirection()) return;
- if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
- mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
- }
- } else {
- // Nothing to do, LTR by default
+ ViewGroup viewGroup = ((ViewGroup) mParent);
+
+ // We cannot resolve yet on the parent too. LTR is by default and let the
+ // resolution happen again later
+ if (!viewGroup.canResolveLayoutDirection()) return;
+
+ if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
+ mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
}
break;
case LAYOUT_DIRECTION_RTL: