Search in sources :

Example 6 with Spanned

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;
}
Also used : WordIterator(android.text.method.WordIterator) URLSpan(android.text.style.URLSpan) Spanned(android.text.Spanned) Paint(android.graphics.Paint)

Example 7 with Spanned

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;
}
Also used : AQuery(com.androidquery.AQuery) ViewGroup(android.view.ViewGroup) View(android.view.View) AdapterView(android.widget.AdapterView) Spanned(android.text.Spanned) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with Spanned

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

Example 9 with Spanned

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

Example 10 with Spanned

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

Aggregations

Spanned (android.text.Spanned)204 Paint (android.graphics.Paint)81 TextPaint (android.text.TextPaint)63 Spannable (android.text.Spannable)32 SpannableStringBuilder (android.text.SpannableStringBuilder)27 SpannableString (android.text.SpannableString)25 SuggestionSpan (android.text.style.SuggestionSpan)24 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)12 Context (android.content.Context)10 StyleSpan (android.text.style.StyleSpan)9 InputMethodManager (android.view.inputmethod.InputMethodManager)9 TextView (android.widget.TextView)9 Parcelable (android.os.Parcelable)8 WordIterator (android.text.method.WordIterator)7 CharacterStyle (android.text.style.CharacterStyle)7