diff options
5 files changed, 41 insertions, 23 deletions
diff --git a/core/java/com/android/internal/widget/ImageFloatingTextView.java b/core/java/com/android/internal/widget/ImageFloatingTextView.java index e86932cf3b29..6b53368c3443 100644 --- a/core/java/com/android/internal/widget/ImageFloatingTextView.java +++ b/core/java/com/android/internal/widget/ImageFloatingTextView.java @@ -169,4 +169,8 @@ public class ImageFloatingTextView extends TextView { } return false; } + + public int getLayoutHeight() { + return getLayout().getHeight(); + } } diff --git a/core/java/com/android/internal/widget/MessagingLinearLayout.java b/core/java/com/android/internal/widget/MessagingLinearLayout.java index 1104318763c0..70473a014c0d 100644 --- a/core/java/com/android/internal/widget/MessagingLinearLayout.java +++ b/core/java/com/android/internal/widget/MessagingLinearLayout.java @@ -138,7 +138,7 @@ public class MessagingLinearLayout extends ViewGroup { first = false; boolean measuredTooSmall = false; if (textChild != null) { - measuredTooSmall = childHeight < textChild.getLayout().getHeight() + measuredTooSmall = childHeight < textChild.getLayoutHeight() + textChild.getPaddingTop() + textChild.getPaddingBottom(); } diff --git a/core/tests/coretests/res/layout/messaging_linear_layout_test.xml b/core/tests/coretests/res/layout/messaging_linear_layout_test.xml index 8ba3e07da22e..9e70ca3fe7e5 100644 --- a/core/tests/coretests/res/layout/messaging_linear_layout_test.xml +++ b/core/tests/coretests/res/layout/messaging_linear_layout_test.xml @@ -19,7 +19,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:maxHeight="300px" android:spacing="5px"> </com.android.internal.widget.MessagingLinearLayout>
\ No newline at end of file diff --git a/core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java b/core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java index 5dc07c235c16..906d7e90cfc1 100644 --- a/core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java +++ b/core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java @@ -16,7 +16,7 @@ package com.android.internal.widget; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import android.content.Context; import android.support.test.InstrumentationRegistry; @@ -111,6 +111,9 @@ public class ImageFloatingTextViewTest { mTextView.measure(widthMeasureSpec, heightMeasureSpec); mView.measure(widthMeasureSpec, heightMeasureSpec); - assertEquals(mTextView.getMeasuredHeight(), mView.getMeasuredHeight()); + // We're at most allowed to be the same height as the regular textview and maybe a bit + // smaller since our layout snaps to full textlines. + assertTrue("The measured view should never be taller then the normal textview!", + mView.getMeasuredHeight() <= mTextView.getMeasuredHeight()); } } diff --git a/core/tests/coretests/src/com/android/internal/widget/MessagingLinearLayoutTest.java b/core/tests/coretests/src/com/android/internal/widget/MessagingLinearLayoutTest.java index 75b2c1d5fd2c..20fd4d3d36f8 100644 --- a/core/tests/coretests/src/com/android/internal/widget/MessagingLinearLayoutTest.java +++ b/core/tests/coretests/src/com/android/internal/widget/MessagingLinearLayoutTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.content.Context; -import android.os.Debug; import android.support.test.InstrumentationRegistry; import android.support.test.espresso.core.deps.guava.base.Function; import android.support.test.filters.SmallTest; @@ -46,8 +45,7 @@ public class MessagingLinearLayoutTest { @Before public void setup() { mContext = InstrumentationRegistry.getTargetContext(); - // maxHeight: 300px - // spacing: 50px + // spacing: 5px mView = (MessagingLinearLayout) LayoutInflater.from(mContext).inflate( R.layout.messaging_linear_layout_test, null); } @@ -81,8 +79,8 @@ public class MessagingLinearLayoutTest { assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); - assertFalse(child1.isHidden()); - assertFalse(child2.isHidden()); + assertFalse("child1 should not be hidden", child1.isHidden()); + assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(205, mView.getMeasuredHeight()); } @@ -100,8 +98,8 @@ public class MessagingLinearLayoutTest { assertEquals(2, child1.getNumIndentLines()); assertEquals(1, child2.getNumIndentLines()); - assertFalse(child1.isHidden()); - assertFalse(child2.isHidden()); + assertFalse("child1 should not be hidden", child1.isHidden()); + assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(105, mView.getMeasuredHeight()); } @@ -118,14 +116,14 @@ public class MessagingLinearLayoutTest { mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertEquals(3, child2.getNumIndentLines()); - assertTrue(child1.isHidden()); - assertFalse(child2.isHidden()); - assertEquals(300, mView.getMeasuredHeight()); + assertTrue("child1 should be hidden", child1.isHidden()); + assertFalse("child2 should not be hidden", child2.isHidden()); + assertEquals(350, mView.getMeasuredHeight()); } @Test - public void testLargeSmall_largeWrapsWith3indentbutnot3_andHitsMax() { - FakeImageFloatingTextView child1 = fakeChild((i) -> i > 2 ? 5 : 4); + public void testLargeSmall_largeWrapsWith3indentbutNotFullHeight_andHitsMax() { + FakeImageFloatingTextView child1 = fakeChild((i) -> i > 2 ? 7 : 6); FakeImageFloatingTextView child2 = fakeChild((i) -> 1); mView.setNumIndentLines(2); @@ -135,10 +133,11 @@ public class MessagingLinearLayoutTest { mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); - assertTrue(child1.isHidden()); - assertFalse(child2.isHidden()); - assertEquals(50, mView.getMeasuredHeight()); - assertEquals(2, child2.getNumIndentLines()); + assertFalse("child1 should not be hidden", child1.isHidden()); + assertFalse("child2 should not be hidden", child2.isHidden()); + assertEquals(355, mView.getMeasuredHeight()); + assertEquals(3, child1.getNumIndentLines()); + assertEquals(0, child2.getNumIndentLines()); } @Test @@ -153,8 +152,8 @@ public class MessagingLinearLayoutTest { mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); - assertFalse(child1.isHidden()); - assertFalse(child2.isHidden()); + assertFalse("child1 should not be hidden", child1.isHidden()); + assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(255, mView.getMeasuredHeight()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); @@ -184,10 +183,23 @@ public class MessagingLinearLayoutTest { } @Override + public int getLayoutHeight() { + return Math.max(LINE_HEIGHT, getMeasuredHeight()); + } + + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension( getDefaultSize(500, widthMeasureSpec), - resolveSize(getDesiredHeight(), heightMeasureSpec)); + clampToMultiplesOfLineHeight(resolveSize(getDesiredHeight(), + heightMeasureSpec))); + } + + private int clampToMultiplesOfLineHeight(int size) { + if (size <= LINE_HEIGHT) { + return size; + } + return (size / LINE_HEIGHT) * LINE_HEIGHT; } @Override |