Loading core/java/com/android/internal/widget/ImageFloatingTextView.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -169,4 +169,8 @@ public class ImageFloatingTextView extends TextView { } } return false; return false; } } public int getLayoutHeight() { return getLayout().getHeight(); } } } core/java/com/android/internal/widget/MessagingLinearLayout.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -138,7 +138,7 @@ public class MessagingLinearLayout extends ViewGroup { first = false; first = false; boolean measuredTooSmall = false; boolean measuredTooSmall = false; if (textChild != null) { if (textChild != null) { measuredTooSmall = childHeight < textChild.getLayout().getHeight() measuredTooSmall = childHeight < textChild.getLayoutHeight() + textChild.getPaddingTop() + textChild.getPaddingBottom(); + textChild.getPaddingTop() + textChild.getPaddingBottom(); } } Loading core/tests/coretests/res/layout/messaging_linear_layout_test.xml +0 −1 Original line number Original line Diff line number Diff line Loading @@ -19,7 +19,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_height="match_parent" android:maxHeight="300px" android:spacing="5px"> android:spacing="5px"> </com.android.internal.widget.MessagingLinearLayout> </com.android.internal.widget.MessagingLinearLayout> No newline at end of file core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.internal.widget; package com.android.internal.widget; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import android.content.Context; import android.content.Context; import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry; Loading Loading @@ -111,6 +111,9 @@ public class ImageFloatingTextViewTest { mTextView.measure(widthMeasureSpec, heightMeasureSpec); mTextView.measure(widthMeasureSpec, heightMeasureSpec); mView.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()); } } } } core/tests/coretests/src/com/android/internal/widget/MessagingLinearLayoutTest.java +31 −19 Original line number Original line Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import android.content.Context; import android.content.Context; import android.os.Debug; import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry; import android.support.test.espresso.core.deps.guava.base.Function; import android.support.test.espresso.core.deps.guava.base.Function; import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest; Loading @@ -46,8 +45,7 @@ public class MessagingLinearLayoutTest { @Before @Before public void setup() { public void setup() { mContext = InstrumentationRegistry.getTargetContext(); mContext = InstrumentationRegistry.getTargetContext(); // maxHeight: 300px // spacing: 5px // spacing: 50px mView = (MessagingLinearLayout) LayoutInflater.from(mContext).inflate( mView = (MessagingLinearLayout) LayoutInflater.from(mContext).inflate( R.layout.messaging_linear_layout_test, null); R.layout.messaging_linear_layout_test, null); } } Loading Loading @@ -81,8 +79,8 @@ public class MessagingLinearLayoutTest { assertEquals(3, child1.getNumIndentLines()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); assertFalse(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(205, mView.getMeasuredHeight()); assertEquals(205, mView.getMeasuredHeight()); } } Loading @@ -100,8 +98,8 @@ public class MessagingLinearLayoutTest { assertEquals(2, child1.getNumIndentLines()); assertEquals(2, child1.getNumIndentLines()); assertEquals(1, child2.getNumIndentLines()); assertEquals(1, child2.getNumIndentLines()); assertFalse(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(105, mView.getMeasuredHeight()); assertEquals(105, mView.getMeasuredHeight()); } } Loading @@ -118,14 +116,14 @@ public class MessagingLinearLayoutTest { mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertEquals(3, child2.getNumIndentLines()); assertEquals(3, child2.getNumIndentLines()); assertTrue(child1.isHidden()); assertTrue("child1 should be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(300, mView.getMeasuredHeight()); assertEquals(350, mView.getMeasuredHeight()); } } @Test @Test public void testLargeSmall_largeWrapsWith3indentbutnot3_andHitsMax() { public void testLargeSmall_largeWrapsWith3indentbutNotFullHeight_andHitsMax() { FakeImageFloatingTextView child1 = fakeChild((i) -> i > 2 ? 5 : 4); FakeImageFloatingTextView child1 = fakeChild((i) -> i > 2 ? 7 : 6); FakeImageFloatingTextView child2 = fakeChild((i) -> 1); FakeImageFloatingTextView child2 = fakeChild((i) -> 1); mView.setNumIndentLines(2); mView.setNumIndentLines(2); Loading @@ -135,10 +133,11 @@ public class MessagingLinearLayoutTest { mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertTrue(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(50, mView.getMeasuredHeight()); assertEquals(355, mView.getMeasuredHeight()); assertEquals(2, child2.getNumIndentLines()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); } } @Test @Test Loading @@ -153,8 +152,8 @@ public class MessagingLinearLayoutTest { mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertFalse(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(255, mView.getMeasuredHeight()); assertEquals(255, mView.getMeasuredHeight()); assertEquals(3, child1.getNumIndentLines()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); Loading Loading @@ -183,11 +182,24 @@ public class MessagingLinearLayoutTest { return mNumIndentLines; return mNumIndentLines; } } @Override public int getLayoutHeight() { return Math.max(LINE_HEIGHT, getMeasuredHeight()); } @Override @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension( setMeasuredDimension( getDefaultSize(500, widthMeasureSpec), 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 @Override Loading Loading
core/java/com/android/internal/widget/ImageFloatingTextView.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -169,4 +169,8 @@ public class ImageFloatingTextView extends TextView { } } return false; return false; } } public int getLayoutHeight() { return getLayout().getHeight(); } } }
core/java/com/android/internal/widget/MessagingLinearLayout.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -138,7 +138,7 @@ public class MessagingLinearLayout extends ViewGroup { first = false; first = false; boolean measuredTooSmall = false; boolean measuredTooSmall = false; if (textChild != null) { if (textChild != null) { measuredTooSmall = childHeight < textChild.getLayout().getHeight() measuredTooSmall = childHeight < textChild.getLayoutHeight() + textChild.getPaddingTop() + textChild.getPaddingBottom(); + textChild.getPaddingTop() + textChild.getPaddingBottom(); } } Loading
core/tests/coretests/res/layout/messaging_linear_layout_test.xml +0 −1 Original line number Original line Diff line number Diff line Loading @@ -19,7 +19,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_height="match_parent" android:maxHeight="300px" android:spacing="5px"> android:spacing="5px"> </com.android.internal.widget.MessagingLinearLayout> </com.android.internal.widget.MessagingLinearLayout> No newline at end of file
core/tests/coretests/src/com/android/internal/widget/ImageFloatingTextViewTest.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.internal.widget; package com.android.internal.widget; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import android.content.Context; import android.content.Context; import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry; Loading Loading @@ -111,6 +111,9 @@ public class ImageFloatingTextViewTest { mTextView.measure(widthMeasureSpec, heightMeasureSpec); mTextView.measure(widthMeasureSpec, heightMeasureSpec); mView.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()); } } } }
core/tests/coretests/src/com/android/internal/widget/MessagingLinearLayoutTest.java +31 −19 Original line number Original line Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import android.content.Context; import android.content.Context; import android.os.Debug; import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry; import android.support.test.espresso.core.deps.guava.base.Function; import android.support.test.espresso.core.deps.guava.base.Function; import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest; Loading @@ -46,8 +45,7 @@ public class MessagingLinearLayoutTest { @Before @Before public void setup() { public void setup() { mContext = InstrumentationRegistry.getTargetContext(); mContext = InstrumentationRegistry.getTargetContext(); // maxHeight: 300px // spacing: 5px // spacing: 50px mView = (MessagingLinearLayout) LayoutInflater.from(mContext).inflate( mView = (MessagingLinearLayout) LayoutInflater.from(mContext).inflate( R.layout.messaging_linear_layout_test, null); R.layout.messaging_linear_layout_test, null); } } Loading Loading @@ -81,8 +79,8 @@ public class MessagingLinearLayoutTest { assertEquals(3, child1.getNumIndentLines()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); assertFalse(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(205, mView.getMeasuredHeight()); assertEquals(205, mView.getMeasuredHeight()); } } Loading @@ -100,8 +98,8 @@ public class MessagingLinearLayoutTest { assertEquals(2, child1.getNumIndentLines()); assertEquals(2, child1.getNumIndentLines()); assertEquals(1, child2.getNumIndentLines()); assertEquals(1, child2.getNumIndentLines()); assertFalse(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(105, mView.getMeasuredHeight()); assertEquals(105, mView.getMeasuredHeight()); } } Loading @@ -118,14 +116,14 @@ public class MessagingLinearLayoutTest { mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertEquals(3, child2.getNumIndentLines()); assertEquals(3, child2.getNumIndentLines()); assertTrue(child1.isHidden()); assertTrue("child1 should be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(300, mView.getMeasuredHeight()); assertEquals(350, mView.getMeasuredHeight()); } } @Test @Test public void testLargeSmall_largeWrapsWith3indentbutnot3_andHitsMax() { public void testLargeSmall_largeWrapsWith3indentbutNotFullHeight_andHitsMax() { FakeImageFloatingTextView child1 = fakeChild((i) -> i > 2 ? 5 : 4); FakeImageFloatingTextView child1 = fakeChild((i) -> i > 2 ? 7 : 6); FakeImageFloatingTextView child2 = fakeChild((i) -> 1); FakeImageFloatingTextView child2 = fakeChild((i) -> 1); mView.setNumIndentLines(2); mView.setNumIndentLines(2); Loading @@ -135,10 +133,11 @@ public class MessagingLinearLayoutTest { mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertTrue(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(50, mView.getMeasuredHeight()); assertEquals(355, mView.getMeasuredHeight()); assertEquals(2, child2.getNumIndentLines()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); } } @Test @Test Loading @@ -153,8 +152,8 @@ public class MessagingLinearLayoutTest { mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.measure(WIDTH_SPEC, HEIGHT_SPEC); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); assertFalse(child1.isHidden()); assertFalse("child1 should not be hidden", child1.isHidden()); assertFalse(child2.isHidden()); assertFalse("child2 should not be hidden", child2.isHidden()); assertEquals(255, mView.getMeasuredHeight()); assertEquals(255, mView.getMeasuredHeight()); assertEquals(3, child1.getNumIndentLines()); assertEquals(3, child1.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); assertEquals(0, child2.getNumIndentLines()); Loading Loading @@ -183,11 +182,24 @@ public class MessagingLinearLayoutTest { return mNumIndentLines; return mNumIndentLines; } } @Override public int getLayoutHeight() { return Math.max(LINE_HEIGHT, getMeasuredHeight()); } @Override @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension( setMeasuredDimension( getDefaultSize(500, widthMeasureSpec), 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 @Override Loading