Other improvements for bug #6427629 Clean up layout direction APIs

- hide isLayoutRtl() from public API

- canResolveXXX() is now smarter: use recursion to get its returned value

- in ViewGroup, if resolution cannot be done then dont ask resolution for
its children

- in ViewGroup, addViewInner() needs to ask to resolve the child. This is
needed for example by ListView which is using the same measurespec before
and after its childs being attached.

It also take care of the general case where a measure pass is done when not
attached to a parent (and thus asking for resolution that will "fail" if we
are using IHNERIT) and never done again. That would lead to never do a
resolution.

- some code refactoring

Change-Id: I120dd2fef7397944f5ba8deff0686b108dc827d2
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 41890d6..f1d0cc0 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -3382,6 +3382,11 @@
             ai.mKeepScreenOn = lastKeepOn;
         }
 
+        if (child.isLayoutDirectionInherited()) {
+            child.resetResolvedLayoutDirection();
+            child.resolveRtlPropertiesIfNeeded();
+        }
+
         onViewAdded(child);
 
         if ((child.mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE) {
@@ -5256,48 +5261,54 @@
      * @hide
      */
     @Override
-    public void resolveLayoutDirection() {
-        super.resolveLayoutDirection();
-
-        int count = getChildCount();
-        for (int i = 0; i < count; i++) {
-            final View child = getChildAt(i);
-            if (child.isLayoutDirectionInherited()) {
-                child.resolveLayoutDirection();
+    public boolean resolveLayoutDirection() {
+        final boolean result = super.resolveLayoutDirection();
+        if (result) {
+            int count = getChildCount();
+            for (int i = 0; i < count; i++) {
+                final View child = getChildAt(i);
+                if (child.isLayoutDirectionInherited()) {
+                    child.resolveLayoutDirection();
+                }
             }
         }
+        return result;
     }
 
     /**
      * @hide
      */
     @Override
-    public void resolveTextDirection() {
-        super.resolveTextDirection();
-
-        int count = getChildCount();
-        for (int i = 0; i < count; i++) {
-            final View child = getChildAt(i);
-            if (child.isTextDirectionInherited()) {
-                child.resolveTextDirection();
+    public boolean resolveTextDirection() {
+        final boolean result = super.resolveTextDirection();
+        if (result) {
+            int count = getChildCount();
+            for (int i = 0; i < count; i++) {
+                final View child = getChildAt(i);
+                if (child.isTextDirectionInherited()) {
+                    child.resolveTextDirection();
+                }
             }
         }
+        return result;
     }
 
     /**
      * @hide
      */
     @Override
-    public void resolveTextAlignment() {
-        super.resolveTextAlignment();
-
-        int count = getChildCount();
-        for (int i = 0; i < count; i++) {
-            final View child = getChildAt(i);
-            if (child.isTextAlignmentInherited()) {
-                child.resolveTextAlignment();
+    public boolean resolveTextAlignment() {
+        final boolean result = super.resolveTextAlignment();
+        if (result) {
+            int count = getChildCount();
+            for (int i = 0; i < count; i++) {
+                final View child = getChildAt(i);
+                if (child.isTextAlignmentInherited()) {
+                    child.resolveTextAlignment();
+                }
             }
         }
+        return result;
     }
 
     /**