am 559daf7a: Merge "Include non-zero dimension views in excess space calculation" into mnc-dev

* commit '559daf7a749514065c6c482503a86a528addc985':
  Include non-zero dimension views in excess space calculation
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 4b40501..47e894a 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -722,8 +722,10 @@
             LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams();
 
             totalWeight += lp.weight;
-            
-            if (heightMode == MeasureSpec.EXACTLY && lp.height == 0 && lp.weight > 0) {
+
+            final boolean fillExcessSpace = lp.weight > 0;
+            final boolean hasZeroHeight = lp.height == 0;
+            if (heightMode == MeasureSpec.EXACTLY && fillExcessSpace && hasZeroHeight) {
                 // Optimization: don't bother measuring children who are going to use
                 // leftover space. These views will get measured again down below if
                 // there is any leftover space.
@@ -731,12 +733,12 @@
                 mTotalLength = Math.max(totalLength, totalLength + lp.topMargin + lp.bottomMargin);
                 skippedMeasure = true;
             } else {
-                final boolean fillExcessSpace = lp.height == 0 && lp.weight > 0;
-                if (fillExcessSpace) {
-                    // heightMode is either UNSPECIFIED or AT_MOST, and this
-                    // child wanted to stretch to fill available space.
-                    // Translate that to WRAP_CONTENT so that it does not end up
-                    // with a height of 0.
+                if (fillExcessSpace && hasZeroHeight) {
+                    // The LinearLayout's heightMode is either UNSPECIFIED or
+                    // AT_MOST, and this child wanted to stretch to fill
+                    // available space. Translate the explicit height of 0 to
+                    // WRAP_CONTENT so that we can measure the view's ideal
+                    // height.
                     lp.height = LayoutParams.WRAP_CONTENT;
                 }
 
@@ -751,7 +753,11 @@
                 final int childHeight = child.getMeasuredHeight();
                 if (fillExcessSpace) {
                     usedExcessSpace += childHeight;
-                    lp.height = 0;
+
+                    // Restore original layout height.
+                    if (hasZeroHeight) {
+                        lp.height = 0;
+                    }
                 }
 
                 final int totalLength = mTotalLength;
@@ -1047,8 +1053,10 @@
                     child.getLayoutParams();
 
             totalWeight += lp.weight;
-            
-            if (widthMode == MeasureSpec.EXACTLY && lp.width == 0 && lp.weight > 0) {
+
+            final boolean fillExcessSpace = lp.weight > 0;
+            final boolean hasZeroWidth = lp.width == 0;
+            if (widthMode == MeasureSpec.EXACTLY && fillExcessSpace && hasZeroWidth) {
                 // Optimization: don't bother measuring children who are going to use
                 // leftover space. These views will get measured again down below if
                 // there is any leftover space.
@@ -1075,12 +1083,12 @@
                     skippedMeasure = true;
                 }
             } else {
-                final boolean fillExcessSpace = lp.width == 0 && lp.weight > 0;
-                if (fillExcessSpace) {
-                    // widthMode is either UNSPECIFIED or AT_MOST, and this
-                    // child wanted to stretch to fill available space.
-                    // Translate that to WRAP_CONTENT so that it does not end up
-                    // with a width of 0.
+                if (fillExcessSpace && hasZeroWidth) {
+                    // The LinearLayout's widthMode is either UNSPECIFIED or
+                    // AT_MOST, and this child wanted to stretch to fill
+                    // available space. Translate the explicit height of 0 to
+                    // WRAP_CONTENT so that we can measure the view's ideal
+                    // width.
                     lp.width = LayoutParams.WRAP_CONTENT;
                 }
 
@@ -1095,7 +1103,11 @@
                 final int childWidth = child.getMeasuredWidth();
                 if (fillExcessSpace) {
                     usedExcessSpace += childWidth;
-                    lp.width = 0;
+
+                    // Restore the original layout width.
+                    if (hasZeroWidth) {
+                        lp.width = 0;
+                    }
                 }
 
                 if (isExactly) {