Merge changes from topic "siyamed_maxlines" into oc-mr1-dev

* changes:
  StaticLayout capped height should be 0 when maxLines=0
  Reset StaticLayout.mEllipsized during generate()
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index a8c6aa6..a03a4fb 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -608,6 +608,8 @@
         b.setLocales(paint.getTextLocales());
 
         mLineCount = 0;
+        mEllipsized = false;
+        mMaxLineHeight = mMaximumVisibleLineCount < 1 ? 0 : DEFAULT_MAX_LINE_HEIGHT;
 
         int v = 0;
         boolean needMultiply = (spacingmult != 1 || spacingadd != 0);
@@ -1366,7 +1368,7 @@
      * The value is the same as getLineTop(maxLines) for ellipsized version where structurally no
      * more than maxLines is contained.
      */
-    private int mMaxLineHeight = -1;
+    private int mMaxLineHeight = DEFAULT_MAX_LINE_HEIGHT;
 
     private static final int COLUMNS_NORMAL = 4;
     private static final int COLUMNS_ELLIPSIZE = 6;
@@ -1394,6 +1396,8 @@
 
     private static final double EXTRA_ROUNDING = 0.5;
 
+    private static final int DEFAULT_MAX_LINE_HEIGHT = -1;
+
     // This is used to return three arrays from a single JNI call when
     // performing line breaking
     /*package*/ static class LineBreaks {
diff --git a/core/tests/coretests/src/android/text/StaticLayoutTest.java b/core/tests/coretests/src/android/text/StaticLayoutTest.java
index fb60e38..f1c4e56 100644
--- a/core/tests/coretests/src/android/text/StaticLayoutTest.java
+++ b/core/tests/coretests/src/android/text/StaticLayoutTest.java
@@ -746,4 +746,15 @@
             assertEquals(numEnglishLines, numPrivateLocaleLines);
         }
     }
+
+    @Test
+    public void testGetHeight_zeroMaxLines() {
+        final String text = "a\nb";
+        final TextPaint paint = new TextPaint();
+        final StaticLayout layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint,
+                Integer.MAX_VALUE).setMaxLines(0).build();
+
+        assertEquals(0, layout.getHeight(true));
+        assertEquals(2, layout.getLineCount());
+    }
 }