use of android.text.Spanned in project platform_frameworks_base by android.
the class Editor method selectCurrentWord.
/**
* Adjusts selection to the word under last touch offset. Return true if the operation was
* successfully performed.
*/
private boolean selectCurrentWord() {
if (!mTextView.canSelectText()) {
return false;
}
if (needsToSelectAllToSelectWordOrParagraph()) {
return mTextView.selectAllText();
}
long lastTouchOffsets = getLastTouchOffsets();
final int minOffset = TextUtils.unpackRangeStartFromLong(lastTouchOffsets);
final int maxOffset = TextUtils.unpackRangeEndFromLong(lastTouchOffsets);
// Safety check in case standard touch event handling has been bypassed
if (minOffset < 0 || minOffset > mTextView.getText().length())
return false;
if (maxOffset < 0 || maxOffset > mTextView.getText().length())
return false;
int selectionStart, selectionEnd;
// If a URLSpan (web address, email, phone...) is found at that position, select it.
URLSpan[] urlSpans = ((Spanned) mTextView.getText()).getSpans(minOffset, maxOffset, URLSpan.class);
if (urlSpans.length >= 1) {
URLSpan urlSpan = urlSpans[0];
selectionStart = ((Spanned) mTextView.getText()).getSpanStart(urlSpan);
selectionEnd = ((Spanned) mTextView.getText()).getSpanEnd(urlSpan);
} else {
// FIXME - We should check if there's a LocaleSpan in the text, this may be
// something we should try handling or checking for.
final WordIterator wordIterator = getWordIterator();
wordIterator.setCharSequence(mTextView.getText(), minOffset, maxOffset);
selectionStart = wordIterator.getBeginning(minOffset);
selectionEnd = wordIterator.getEnd(maxOffset);
if (selectionStart == BreakIterator.DONE || selectionEnd == BreakIterator.DONE || selectionStart == selectionEnd) {
// Possible when the word iterator does not properly handle the text's language
long range = getCharClusterRange(minOffset);
selectionStart = TextUtils.unpackRangeStartFromLong(range);
selectionEnd = TextUtils.unpackRangeEndFromLong(range);
}
}
Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd);
return selectionEnd > selectionStart;
}
use of android.text.Spanned in project androidquery by androidquery.
the class IntentListActivity method getAA.
private ArrayAdapter<ActivityItem> getAA() {
list = new ArrayList<ActivityItem>();
int[] ids = getResList();
String[] names = getResources().getStringArray(ids[0]);
String[] values = getResources().getStringArray(ids[1]);
for (int i = 0; i < names.length; i++) {
String name = names[i];
String value = values[i];
if (value.startsWith("http")) {
list.add(new ActivityItem(null, name, value, null));
} else {
String[] vs = value.split(":");
String meta = null;
if (vs.length > 2) {
meta = vs[2];
}
list.add(makeActivity(vs[0], name, vs[1], meta));
}
}
if (type == null && (TestUtility.isTestDevice(this) || TestUtility.isEmulator())) {
list.add(makeActivity("com.androidquery.test.AdhocActivity", "Ad Hoc Debug", "", null));
list.add(makeActivity("com.androidquery.test.AdhocActivity2", "Ad Hoc Debug2", "", null));
}
ArrayAdapter<ActivityItem> result = new ArrayAdapter<ActivityItem>(this, R.layout.list_item, list) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.list_item, null);
}
ActivityItem ai = (ActivityItem) getItem(position);
AQuery aq = new AQuery(convertView);
String text = ai.getName();
String meta = ai.getMeta();
if (meta != null) {
text += " <small><small><font color=\"red\">" + meta + "</font></small></small>";
}
Spanned span = Html.fromHtml(text);
aq.id(R.id.name).text(span);
return convertView;
}
};
return result;
}
use of android.text.Spanned in project ExoPlayer by google.
the class WebvttCueParserTest method testParseMultipleTagsOfSameKind.
public void testParseMultipleTagsOfSameKind() {
Spanned text = parseCueText("blah <b>blah</b> blah <b>foo</b>");
assertEquals("blah blah blah foo", text.toString());
StyleSpan[] spans = getSpans(text, StyleSpan.class);
assertEquals(2, spans.length);
assertEquals(5, text.getSpanStart(spans[0]));
assertEquals(9, text.getSpanEnd(spans[0]));
assertEquals(15, text.getSpanStart(spans[1]));
assertEquals(18, text.getSpanEnd(spans[1]));
assertEquals(Typeface.BOLD, spans[0].getStyle());
assertEquals(Typeface.BOLD, spans[1].getStyle());
}
use of android.text.Spanned in project ExoPlayer by google.
the class WebvttCueParserTest method testParseInvalidVoidSlash.
public void testParseInvalidVoidSlash() {
Spanned text = parseCueText("blah <b/.st1.st2 trailing stuff> blah");
assertEquals("blah blah", text.toString());
StyleSpan[] spans = getSpans(text, StyleSpan.class);
assertEquals(0, spans.length);
}
use of android.text.Spanned in project ExoPlayer by google.
the class WebvttCueParserTest method testParseMonkey.
public void testParseMonkey() throws Exception {
Spanned text = parseCueText("< u>An unclosed u tag with <<<<< i>italic</u></u></u></u >" + "</i><u><u> inside");
assertEquals("An unclosed u tag with italic inside", text.toString());
text = parseCueText(">>>>>>>>>An unclosed u tag with <<<<< italic</u></u></u>" + "</u ></i><u><u> inside");
assertEquals(">>>>>>>>>An unclosed u tag with inside", text.toString());
}
Aggregations