Search in sources :

Example 76 with StyleSpan

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]));
}
Also used : StyleSpan(android.text.style.StyleSpan) Spanned(android.text.Spanned) UnderlineSpan(android.text.style.UnderlineSpan)

Example 77 with StyleSpan

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]));
    }
}
Also used : StyleSpan(android.text.style.StyleSpan) Spanned(android.text.Spanned) UnderlineSpan(android.text.style.UnderlineSpan)

Example 78 with StyleSpan

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]));
}
Also used : StyleSpan(android.text.style.StyleSpan) Spanned(android.text.Spanned)

Example 79 with StyleSpan

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());
}
Also used : StyleSpan(android.text.style.StyleSpan) Spanned(android.text.Spanned) UnderlineSpan(android.text.style.UnderlineSpan)

Example 80 with StyleSpan

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);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan)

Aggregations

StyleSpan (android.text.style.StyleSpan)145 SpannableString (android.text.SpannableString)56 SpannableStringBuilder (android.text.SpannableStringBuilder)36 RelativeSizeSpan (android.text.style.RelativeSizeSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)25 View (android.view.View)18 TextView (android.widget.TextView)17 UnderlineSpan (android.text.style.UnderlineSpan)16 Spannable (android.text.Spannable)14 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)12 TypedArray (android.content.res.TypedArray)10 TextPaint (android.text.TextPaint)10 SubscriptSpan (android.text.style.SubscriptSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 Handler (android.os.Handler)9 Message (android.os.Message)9 URLSpan (android.text.style.URLSpan)8 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)8 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)8