Android URLSpan - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android URLSpan class.

This code example shows how to use the following methods:
     * 
     * @param text 
     * @return this text 
     */ 
    public StyledText url(final CharSequence text) {
        return append(text, new URLSpan(text.toString()));
    } 
 
    /** 
     * Append given date in relative time format 
     * 
     * @param date 
     * @return this text 
     */ 
    public StyledText append(final Date date) {
        final CharSequence time = TimeUtils.getRelativeTime(date);
        // Un-capitalize time string if there is already a prefix. 
        // So you get "opened in 5 days" instead of "opened In 5 days". 
        final int timeLength = time.length();
        if (length() > 0 && timeLength > 0
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	@Override 
	public void handleTagNode(TagNode node, SpannableStringBuilder builder, 
			int start, int end, SpanStack spanStack) { 
 
		final String href = node.getAttributeByName("href"); 
		spanStack.pushSpan(new URLSpan(href), start, end); 
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		int end = mSB.length();
		int start = tm.getStart();
		if (start != end) {
			String href = tm.getAttributes().getValue("", "href");
			if (href != null) {
				mSB.setSpan(new URLSpan(href), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			} 
		} 
	} 
 
	private void endHeader(TagMarker tm, int i) {
		int start = tm.getStart();
		int end = mSB.length();
 
		// Back off to change only the text, not the blank line. 
		while (end > start && mSB.charAt(end - 1) == '\n') {
			end--;
		} 
 
		if (start != end) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        s.setSpan(new StrikethroughSpan(), 6, s.length() - 6,
                  Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        assertEquals(Html.toHtml(s), "<p>Hello <strike>struck</strike> world</p>\n");
 
        s = new SpannableString("Hello linky world");
        s.setSpan(new URLSpan("http://www.google.com"), 6, s.length() - 6,
                  Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        assertEquals(Html.toHtml(s),
                     "<p>Hello <a href=\"http://www.google.com\">linky</a> world</p>\n"); 
    } 
 
    @SmallTest 
    public void testImg() throws Exception { 
        Spanned s;
 
        s = Html.fromHtml("yes<img src=\"http://example.com/foo.gif\">no");
 
        assertEquals("<p>yes<img src=\"http://example.com/foo.gif\">no</p>\n",
                     Html.toHtml(s));
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getURL
    } 
 
    public static ClickableURLSpan replaceURLSpan(SpannableStringBuilder builder, URLSpan span, int color) {
        int start = builder.getSpanStart(span);
        int end = builder.getSpanEnd(span);
        String url = span.getURL();
 
        builder.removeSpan(span);
 
        ClickableURLSpan newSpan = new ClickableURLSpan(url);
        builder.setSpan(newSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
 
        return newSpan;
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        if (where != len) {
            Href h = (Href) obj;
 
            if (h != null) {
                if (h.mHref != null) {
                    text.setSpan(new URLSpan(h.mHref), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                } 
            } 
        } 
    } 
 
    private static void endHeader(SpannableStringBuilder text) {
        int len = text.length();
        Object obj = getLast(text, Header.class);
 
        int where = text.getSpanStart(obj);
 
        text.removeSpan(obj);
 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		int end = mSB.length();
		int start = tm.getStart();
		if (start != end) {
			String href = tm.getAttributes().getValue("", "href");
			if (href != null) {
				mSB.setSpan(new URLSpan(href), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			} 
		} 
	} 
 
	private void endHeader(TagMarker tm, int i) {
		int start = tm.getStart();
		int end = mSB.length();
 
		// Back off to change only the text, not the blank line. 
		while (end > start && mSB.charAt(end - 1) == '\n') {
			end--;
		} 
 
		if (start != end) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
        return hasMatches;
    } 
 
    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);
    } 
 
    private static final String makeUrl(String url, String[] prefixes,
            Matcher m, TransformFilter filter) {
        if (filter != null) {
            url = filter.transformUrl(m, url);
        } 
 
        boolean hasPrefix = false;
         
        for (int i = 0; i < prefixes.length; i++) {
            if (url.regionMatches(true, 0, prefixes[i], 0,
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
     * 
     * @param text 
     * @return this text 
     */ 
    public StyledText url(final CharSequence text) {
        return append(text, new URLSpan(text.toString()));
    } 
 
    /** 
     * Append given date in relative time format 
     * 
     * @param date 
     * @return this text 
     */ 
    public StyledText append(final Date date) {
        final CharSequence time = TimeUtils.getRelativeTime(date);
        // Un-capitalize time string if there is already a prefix. 
        // So you get "opened in 5 days" instead of "opened In 5 days". 
        final int timeLength = time.length();
        if (length() > 0 && timeLength > 0
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
  private void initializeAnchorTextView(int textViewId, int urlId, int descriptionId) {
    Resources resources = getResources();
    TextView textView = TextView.class.cast(findViewById(textViewId));
    SpannableString spannable = new SpannableString(resources.getString(descriptionId));
    spannable.setSpan(
        new URLSpan(resources.getString(urlId)),
        0, spannable.length(),
        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    textView.setText(spannable);
    // Make the URLSpan clickable. 
    textView.setMovementMethod(LinkMovementMethod.getInstance());
  } 
 
  @Override 
  protected void onResume() { 
    super.onResume(); 
    updateView(sharedPreferences);
    sharedPreferences.registerOnSharedPreferenceChangeListener(updateViewListener);
  } 
 
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android URLSpan Questions & Answers:

See Code Examples for Android URLSpan Methods: