/** * Sets a text style for the layout. * * @param style The text style for the layout * @return This {@link TextLayoutBuilder} instance */ public TextLayoutBuilder setTextStyle(int style) { return setTypeface(Typeface.defaultFromStyle(style)); }
layoutBuilder.setTypeface(typeface); } else { layoutBuilder.setTextStyle(textStyle);
builder.setTypeface(Typeface.defaultFromStyle(textStyle));
builder.setTypeface(Typeface.defaultFromStyle(textStyle)); } else { builder.setTypeface(null);
@Test public void testSetTypeface() { mLayout = mBuilder.setTypeface(Typeface.MONOSPACE).build(); assertEquals(mBuilder.getTypeface(), Typeface.MONOSPACE); }
@Test public void testLegacyBehaviour() { final Layout layout = new TextLayoutBuilder() .setText(ShadowLayout.LONG_TEXT) .setWidth(-1) .setTypeface(Typeface.DEFAULT) .setTextSize(10) .build(); assertEquals(ShadowLayout.LONG_TEXT_LENGTH, layout.getWidth()); } }
@Test public void testMeasureModeExactly() { final Layout layout = new TextLayoutBuilder() .setText(ShadowLayout.LONG_TEXT) .setWidth(20, MEASURE_MODE_EXACTLY) .setTypeface(Typeface.DEFAULT) .setTextSize(10) .build(); assertEquals(20, layout.getWidth()); }
@Test public void testMeasureModeAtMostShortText() { final Layout layout = new TextLayoutBuilder() .setText(ShadowLayout.SHORT_TEXT) .setWidth(20, MEASURE_MODE_AT_MOST) .setTypeface(Typeface.DEFAULT) .setTextSize(10) .build(); assertEquals(ShadowLayout.SHORT_TEXT_LENGTH, layout.getWidth()); }
@Test public void testMeasureModeUnspecified() { final Layout layout = new TextLayoutBuilder() .setText(ShadowLayout.LONG_TEXT) .setWidth(20, MEASURE_MODE_UNSPECIFIED) .setTypeface(Typeface.DEFAULT) .setTextSize(10) .build(); assertEquals(ShadowLayout.LONG_TEXT_LENGTH, layout.getWidth()); }
@Test public void testMeasureModeAtMostLongText() { final Layout layout = new TextLayoutBuilder() .setText(ShadowLayout.LONG_TEXT) .setWidth(20, MEASURE_MODE_AT_MOST) .setTypeface(Typeface.DEFAULT) .setTextSize(10) .build(); assertEquals(20, layout.getWidth()); }