Search in sources :

Example 6 with URLSpan

use of android.text.style.URLSpan in project weex-example by KalicyZhou.

the class RichText method setTelLink.

@WXComponentProp(name = "tel")
public void setTelLink(String tel) {
    SpannableString spannable = new SpannableString(tel);
    spannable.setSpan(new URLSpan("tel:" + tel), 0, tel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ((TextView) getHostView()).setText(spannable);
}
Also used : SpannableString(android.text.SpannableString) TextView(android.widget.TextView) URLSpan(android.text.style.URLSpan) WXComponentProp(com.taobao.weex.ui.component.WXComponentProp)

Example 7 with URLSpan

use of android.text.style.URLSpan in project Etar-Calendar by Etar-Group.

the class UtilsTests method testExtendedLinkify.

/**
     * Tests the linkify section of event locations.
     */
@SmallTest
public void testExtendedLinkify() {
    final URLSpan[] NO_LINKS = new URLSpan[] {};
    URLSpan span_tel01 = new URLSpan("tel:6505551234");
    URLSpan span_tel02 = new URLSpan("tel:5555678");
    URLSpan span_tel03 = new URLSpan("tel:+16505551234");
    URLSpan span_tel04 = new URLSpan("tel:16505551234");
    URLSpan span_web = new URLSpan("http://www.google.com");
    URLSpan span_geo01 = new URLSpan("geo:0,0?q=1600+Amphitheatre+Parkway%2C+Mountain+View+CA+94043");
    URLSpan span_geo02 = new URLSpan("geo:0,0?q=37.422081°, -122.084576°");
    URLSpan span_geo03 = new URLSpan("geo:0,0?q=37.422081,-122.084576");
    URLSpan span_geo04 = new URLSpan("geo:0,0?q=+37°25'19.49\", -122°5'4.47\"");
    URLSpan span_geo05 = new URLSpan("geo:0,0?q=37°25'19.49\"N, 122°5'4.47\"W");
    URLSpan span_geo06 = new URLSpan("geo:0,0?q=N 37° 25' 19.49\",  W 122° 5' 4.47\"");
    URLSpan span_geo07 = new URLSpan("geo:0,0?q=non-specified address");
    // First test without the last-ditch geo attempt.
    // Phone spans.
    findLinks("", NO_LINKS, false);
    findLinks("(650) 555-1234", new URLSpan[] { span_tel01 }, false);
    findLinks("94043", NO_LINKS, false);
    findLinks("123456789012", NO_LINKS, false);
    findLinks("+1 (650) 555-1234", new URLSpan[] { span_tel03 }, false);
    findLinks("(650) 555 1234", new URLSpan[] { span_tel01 }, false);
    findLinks("1-650-555-1234", new URLSpan[] { span_tel04 }, false);
    findLinks("*#650.555.1234#*!", new URLSpan[] { span_tel01 }, false);
    findLinks("555.5678", new URLSpan[] { span_tel02 }, false);
    // Web spans.
    findLinks("http://www.google.com", new URLSpan[] { span_web }, false);
    // Geo spans.
    findLinks("1600 Amphitheatre Parkway, Mountain View CA 94043", new URLSpan[] { span_geo01 }, false);
    findLinks("37.422081°, -122.084576°", new URLSpan[] { span_geo02 }, false);
    findLinks("37.422081,-122.084576", new URLSpan[] { span_geo03 }, false);
    findLinks("+37°25'19.49\", -122°5'4.47\"", new URLSpan[] { span_geo04 }, false);
    findLinks("37°25'19.49\"N, 122°5'4.47\"W", new URLSpan[] { span_geo05 }, false);
    findLinks("N 37° 25' 19.49\",  W 122° 5' 4.47\"", new URLSpan[] { span_geo06 }, false);
    // Multiple spans.
    findLinks("(650) 555-1234 1600 Amphitheatre Parkway, Mountain View CA 94043", new URLSpan[] { span_tel01, span_geo01 }, false);
    findLinks("(650) 555-1234, 555-5678", new URLSpan[] { span_tel01, span_tel02 }, false);
    // Now test using the last-ditch geo attempt.
    findLinks("", NO_LINKS, true);
    findLinks("(650) 555-1234", new URLSpan[] { span_tel01 }, true);
    findLinks("http://www.google.com", new URLSpan[] { span_web }, true);
    findLinks("1600 Amphitheatre Parkway, Mountain View CA 94043", new URLSpan[] { span_geo01 }, true);
    findLinks("37.422081°, -122.084576°", new URLSpan[] { span_geo02 }, true);
    findLinks("37.422081,-122.084576", new URLSpan[] { span_geo03 }, true);
    findLinks("+37°25'19.49\", -122°5'4.47\"", new URLSpan[] { span_geo04 }, true);
    findLinks("37°25'19.49\"N, 122°5'4.47\"W", new URLSpan[] { span_geo05 }, true);
    findLinks("N 37° 25' 19.49\",  W 122° 5' 4.47\"", new URLSpan[] { span_geo06 }, true);
    findLinks("non-specified address", new URLSpan[] { span_geo07 }, true);
}
Also used : URLSpan(android.text.style.URLSpan) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with URLSpan

use of android.text.style.URLSpan in project android_frameworks_base by ParanoidAndroid.

the class LinkSpec method applyLink.

private static final void applyLink(String url, int start, int end, Spannable text) {
    URLSpan span = new URLSpan(url);
    text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : URLSpan(android.text.style.URLSpan)

Example 9 with URLSpan

use of android.text.style.URLSpan in project android_frameworks_base by AOSPA.

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 10 with URLSpan

use of android.text.style.URLSpan in project weex-example by KalicyZhou.

the class SupplementalInfoRetriever method append.

final void append(String itemID, String source, String[] newTexts, String linkURL) {
    StringBuilder newTextCombined = new StringBuilder();
    if (source != null) {
        newTextCombined.append(source).append(' ');
    }
    int linkStart = newTextCombined.length();
    boolean first = true;
    for (String newText : newTexts) {
        if (first) {
            newTextCombined.append(newText);
            first = false;
        } else {
            newTextCombined.append(" [");
            newTextCombined.append(newText);
            newTextCombined.append(']');
        }
    }
    int linkEnd = newTextCombined.length();
    String newText = newTextCombined.toString();
    Spannable content = new SpannableString(newText + "\n\n");
    if (linkURL != null) {
        // Lower-case these as it should always be OK to lower-case these schemes.
        if (linkURL.startsWith("HTTP://")) {
            linkURL = "http" + linkURL.substring(4);
        } else if (linkURL.startsWith("HTTPS://")) {
            linkURL = "https" + linkURL.substring(5);
        }
        content.setSpan(new URLSpan(linkURL), linkStart, linkEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    newContents.add(content);
    newHistories.add(new String[] { itemID, newText });
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Aggregations

URLSpan (android.text.style.URLSpan)134 SpannableString (android.text.SpannableString)36 Spannable (android.text.Spannable)22 SpannableStringBuilder (android.text.SpannableStringBuilder)21 TextPaint (android.text.TextPaint)21 Spanned (android.text.Spanned)20 TextView (android.widget.TextView)19 ForegroundColorSpan (android.text.style.ForegroundColorSpan)16 StyleSpan (android.text.style.StyleSpan)16 UnderlineSpan (android.text.style.UnderlineSpan)14 Paint (android.graphics.Paint)13 ImageSpan (android.text.style.ImageSpan)13 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)13 View (android.view.View)13 Intent (android.content.Intent)12 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)12 ClickableSpan (android.text.style.ClickableSpan)12 SubscriptSpan (android.text.style.SubscriptSpan)12