Search in sources :

Example 96 with Spanned

use of android.text.Spanned in project SocialTokenAutoComplete by bitjjj.

the class TokenCompleteTextView method init.

private void init() {
    setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    objects = new ArrayList<Object>();
    Editable text = getText();
    assert null != text;
    spanWatcher = new TokenSpanWatcher();
    resetListeners();
    setTextIsSelectable(false);
    setLongClickable(false);
    //In theory, get the soft keyboard to not supply suggestions.
    setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
    setOnEditorActionListener(this);
    setFilters(new InputFilter[] { new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            //Detect single commas, remove them and complete the current token instead
            if (source.length() == 1 && source.charAt(0) == SPLITOR) {
                performCompletion();
                return "";
            }
            //We need to not do anything when we would delete the prefix
            if (dstart < prefix.length() && dend == prefix.length()) {
                return prefix.substring(dstart, dend);
            }
            return null;
        }
    } });
    //We had _Parent style during initialization to handle an edge case in the parent
    //now we can switch to Clear, usually the best choice
    setDeletionStyle(TokenDeleteStyle.Clear);
    initialized = true;
}
Also used : InputFilter(android.text.InputFilter) MultiAutoCompleteTextView(android.widget.MultiAutoCompleteTextView) Editable(android.text.Editable) Spanned(android.text.Spanned) Paint(android.graphics.Paint)

Example 97 with Spanned

use of android.text.Spanned 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 98 with Spanned

use of android.text.Spanned in project ExoPlayer by google.

the class WebvttCueParserTest method testParseEmptyTagName.

public void testParseEmptyTagName() throws Exception {
    Spanned text = parseCueText("An unclosed u tag with <>italic inside");
    assertEquals("An unclosed u tag with italic inside", text.toString());
}
Also used : Spanned(android.text.Spanned)

Example 99 with Spanned

use of android.text.Spanned 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 100 with Spanned

use of android.text.Spanned 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)

Aggregations

Spanned (android.text.Spanned)200 Paint (android.graphics.Paint)81 TextPaint (android.text.TextPaint)63 Spannable (android.text.Spannable)32 SpannableStringBuilder (android.text.SpannableStringBuilder)26 SuggestionSpan (android.text.style.SuggestionSpan)24 SpannableString (android.text.SpannableString)23 Editable (android.text.Editable)22 TextAppearanceSpan (android.text.style.TextAppearanceSpan)15 SpannedString (android.text.SpannedString)14 TypedArray (android.content.res.TypedArray)12 URLSpan (android.text.style.URLSpan)12 View (android.view.View)11 Context (android.content.Context)9 StyleSpan (android.text.style.StyleSpan)9 InputMethodManager (android.view.inputmethod.InputMethodManager)9 Parcelable (android.os.Parcelable)8 TextView (android.widget.TextView)8 WordIterator (android.text.method.WordIterator)7 CharacterStyle (android.text.style.CharacterStyle)7