use of android.text.style.StyleSpan in project ExoPlayer by google.
the class WebvttCueParserTest method testParseWellFormedUnclosedEndAtCueEnd.
public void testParseWellFormedUnclosedEndAtCueEnd() throws Exception {
Spanned text = parseCueText("An <u some trailing stuff>unclosed u tag with " + "<i>italic</i> inside");
assertEquals("An unclosed u tag with italic inside", text.toString());
UnderlineSpan[] underlineSpans = getSpans(text, UnderlineSpan.class);
StyleSpan[] styleSpans = getSpans(text, StyleSpan.class);
assertEquals(1, underlineSpans.length);
assertEquals(1, styleSpans.length);
assertEquals(Typeface.ITALIC, styleSpans[0].getStyle());
assertEquals(3, text.getSpanStart(underlineSpans[0]));
assertEquals(23, text.getSpanStart(styleSpans[0]));
assertEquals(29, text.getSpanEnd(styleSpans[0]));
assertEquals(36, text.getSpanEnd(underlineSpans[0]));
}
use of android.text.style.StyleSpan in project ExoPlayer by google.
the class WebvttCueParserTest method testParseMalformedNestedElements.
public void testParseMalformedNestedElements() throws Exception {
Spanned text = parseCueText("<b><u>An unclosed u tag with <i>italic</u> inside</i></b>");
assertEquals("An unclosed u tag with italic inside", text.toString());
UnderlineSpan[] underlineSpans = getSpans(text, UnderlineSpan.class);
StyleSpan[] styleSpans = getSpans(text, StyleSpan.class);
assertEquals(1, underlineSpans.length);
assertEquals(2, styleSpans.length);
// all tags applied until matching start tag found
assertEquals(0, text.getSpanStart(underlineSpans[0]));
assertEquals(29, text.getSpanEnd(underlineSpans[0]));
if (styleSpans[0].getStyle() == Typeface.BOLD) {
assertEquals(0, text.getSpanStart(styleSpans[0]));
assertEquals(23, text.getSpanStart(styleSpans[1]));
assertEquals(29, text.getSpanEnd(styleSpans[1]));
assertEquals(36, text.getSpanEnd(styleSpans[0]));
} else {
assertEquals(0, text.getSpanStart(styleSpans[1]));
assertEquals(23, text.getSpanStart(styleSpans[0]));
assertEquals(29, text.getSpanEnd(styleSpans[0]));
assertEquals(36, text.getSpanEnd(styleSpans[1]));
}
}
use of android.text.style.StyleSpan in project ExoPlayer by google.
the class WebvttCueParserTest method testParseCloseNonExistingTag.
public void testParseCloseNonExistingTag() throws Exception {
Spanned text = parseCueText("blah<b>blah</i>blah</b>blah");
assertEquals("blahblahblahblah", text.toString());
StyleSpan[] spans = getSpans(text, StyleSpan.class);
assertEquals(1, spans.length);
assertEquals(Typeface.BOLD, spans[0].getStyle());
assertEquals(4, text.getSpanStart(spans[0]));
// should be 12 when valid
assertEquals(8, text.getSpanEnd(spans[0]));
}
use of android.text.style.StyleSpan in project ExoPlayer by google.
the class WebvttCueParserTest method testParseWellFormedUnclosedEndAtParent.
public void testParseWellFormedUnclosedEndAtParent() throws Exception {
Spanned text = parseCueText("An unclosed u tag with <i><u>underline and italic</i> inside");
assertEquals("An unclosed u tag with underline and italic inside", text.toString());
UnderlineSpan[] underlineSpans = getSpans(text, UnderlineSpan.class);
StyleSpan[] styleSpans = getSpans(text, StyleSpan.class);
assertEquals(1, underlineSpans.length);
assertEquals(1, styleSpans.length);
assertEquals(23, text.getSpanStart(underlineSpans[0]));
assertEquals(23, text.getSpanStart(styleSpans[0]));
assertEquals(43, text.getSpanEnd(underlineSpans[0]));
assertEquals(43, text.getSpanEnd(styleSpans[0]));
assertEquals(Typeface.ITALIC, styleSpans[0].getStyle());
}
use of android.text.style.StyleSpan in project ExoPlayer by google.
the class Cea608Decoder method handleMidrowCtrl.
private void handleMidrowCtrl(byte cc2) {
// TODO: support the extended styles (i.e. backgrounds and transparencies)
// cc2 - 0|0|1|0|ATRBT|U
// ATRBT is the 3-byte encoded attribute, and U is the underline toggle
boolean isUnderlined = (cc2 & 0x01) == 0x01;
currentCueBuilder.setUnderline(isUnderlined);
int attribute = (cc2 >> 1) & 0x0F;
if (attribute == 0x07) {
currentCueBuilder.setMidrowStyle(new StyleSpan(Typeface.ITALIC), 2);
currentCueBuilder.setMidrowStyle(new ForegroundColorSpan(Color.WHITE), 1);
} else {
currentCueBuilder.setMidrowStyle(new ForegroundColorSpan(COLORS[attribute]), 1);
}
}
Aggregations