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;
}
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]));
}
}
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());
}
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]));
}
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());
}
Aggregations