當前位置: 首頁>>代碼示例>>Java>>正文


Java URLSpan.getURL方法代碼示例

本文整理匯總了Java中android.text.style.URLSpan.getURL方法的典型用法代碼示例。如果您正苦於以下問題:Java URLSpan.getURL方法的具體用法?Java URLSpan.getURL怎麽用?Java URLSpan.getURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.style.URLSpan的用法示例。


在下文中一共展示了URLSpan.getURL方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getText

import android.text.style.URLSpan; //導入方法依賴的package包/類
/**
 * @param context
 * @param spannable
 * @param title
 * @return
 */
public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) {
	if (spannable == null || spannable.length() <= 0) {
		Log.e(TAG, "getText  spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();");
		return new SpannableStringBuilder();
	}

	SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
	builder.clearSpans();// should clear old spans
	URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class);
	if (urls != null) {
		for (URLSpan urlSpan : urls) {
			if (urlSpan != null) {
				MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title);
				builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable
						.getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			}
		}
	}

	return builder;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:MyURLSpan.java

示例2: dealUnderLinesData

import android.text.style.URLSpan; //導入方法依賴的package包/類
/**
 * 解析link
 *
 * @param tv_content
 * @param context
 */
private static void dealUnderLinesData(TextView tv_content, Context context) {
    CharSequence charSequence = tv_content.getText();
    if (charSequence instanceof Spannable) {
        tv_content.setText("");
        Spannable s = EmojiDisplay.spannableFilter(tv_content.getContext(),
                new SpannableStringBuilder(charSequence),
                charSequence,
                EmoticonsKeyboardUtils.getFontHeight(tv_content));
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            String clickText = s.subSequence(start, end).toString();
            URLSpanNoUnderline urlSpanNoUnderline = new URLSpanNoUnderline(context, span.getURL(), clickText);
            s.setSpan(urlSpanNoUnderline, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        tv_content.append(s);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:26,代碼來源:CustomTextView.java

示例3: dealAILink

import android.text.style.URLSpan; //導入方法依賴的package包/類
/**
 * 解析機器人對話link
 *
 * @param textView
 */
private static void dealAILink(TextView textView, String type) {
    CharSequence charSequence = textView.getText();
    if (charSequence instanceof Spannable) {
        textView.setText("");
        Spannable s = (Spannable) charSequence;
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            String clickContent = s.subSequence(start, end).toString();
            AIURLSpan myURLSpan = new AIURLSpan(span.getURL(), type, clickContent, textView.getContext());
            s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.append(s);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:22,代碼來源:CustomTextView.java

示例4: dealCustomLink

import android.text.style.URLSpan; //導入方法依賴的package包/類
/**
 * 解析富文本link
 *
 * @param textView
 */
private static void dealCustomLink(TextView textView) {
    CharSequence charSequence = textView.getText();
    if (charSequence instanceof Spannable) {
        textView.setText("");
        Spannable s = (Spannable) charSequence;
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            CustomClickSpan myURLSpan = new CustomClickSpan(textView.getContext(), span.getURL());
            s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.append(s);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:21,代碼來源:CustomTextView.java

示例5: makeLinksClickable

import android.text.style.URLSpan; //導入方法依賴的package包/類
public static void makeLinksClickable(TextView v) {
	SpannableStringBuilder ssb = new SpannableStringBuilder(v.getText());
	URLSpan[] spans = ssb.getSpans(0, ssb.length(), URLSpan.class);
	for (URLSpan span : spans) {
		int start = ssb.getSpanStart(span);
		int end = ssb.getSpanEnd(span);
		final String url = span.getURL();
		ssb.removeSpan(span);
		ClickableSpan cSpan = new ClickableSpan() {
			@Override
			public void onClick(View v2) {
				LinkDialogFragment f = LinkDialogFragment.newInstance(url);
				FragmentManager fm = ((AppCompatActivity) v2.getContext())
						.getSupportFragmentManager();
				f.show(fm, f.getUniqueTag());
			}
		};
		ssb.setSpan(cSpan, start, end, 0);
	}
	v.setText(ssb);
	v.setMovementMethod(ArticleMovementMethod.getInstance());
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:23,代碼來源:UiUtils.java

示例6: formatForTextView

import android.text.style.URLSpan; //導入方法依賴的package包/類
private Spannable formatForTextView(Spannable p_Text) {
    URLSpan[] spans = p_Text.getSpans(0, p_Text.length(), URLSpan.class);
    Pattern hashTagURLPattern = Pattern.compile(".*\\/\\#tags\\/.*", Pattern.CASE_INSENSITIVE);
    Matcher hashtagMatcher = null;
    for (URLSpan span : spans) {
        hashtagMatcher = hashTagURLPattern.matcher(span.getURL());
        // Only format if it's a hashtag link
        if (hashtagMatcher.find()) {
            int start = p_Text.getSpanStart(span);
            int end = p_Text.getSpanEnd(span);
            p_Text.removeSpan(span);
            span = new URLSpanNoUnderline(span.getURL());
            p_Text.setSpan(span, start, end, 0);
        }
    }
    return p_Text;
}
 
開發者ID:adityabhaskar,項目名稱:DoneForAndroid,代碼行數:18,代碼來源:TaskListAdapter.java

示例7: getTransformation

import android.text.style.URLSpan; //導入方法依賴的package包/類
@Override
public CharSequence getTransformation(CharSequence src, View view) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        Linkify.addLinks(textView, Linkify.WEB_URLS);

        if (textView.getText() != null && textView.getText() instanceof Spannable) {
            Spannable text = (Spannable) textView.getText();
            URLSpan[] spans = text.getSpans(0, textView.length(), URLSpan.class);
            for (int i = spans.length - 1; i >= 0; i--) {
                URLSpan oldSpan = spans[i];
                int start = text.getSpanStart(oldSpan), end = text.getSpanEnd(oldSpan);
                String url = oldSpan.getURL();

                text.removeSpan(oldSpan);
                text.setSpan(new CustomTabsURLSpan(url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            return text;
        }
    }
    return src;
}
 
開發者ID:TheAndroidMaster,項目名稱:Paper-Tales,代碼行數:23,代碼來源:WallActivity.java

示例8: hackURLSpanHasResult

import android.text.style.URLSpan; //導入方法依賴的package包/類
/**
 * @param spanText
 * @return true if have url
 */
public static final boolean hackURLSpanHasResult(SpannableStringBuilder spanText) {
    boolean result = false;
    URLSpan[] spans = spanText.getSpans(0, spanText.length(), URLSpan.class);
    // TODO URLSpan need change to ClickableSpan (GoURLSpan) , otherwise URLSpan can not click, not display underline.WHY?
    for (URLSpan span : spans) {
        int start = spanText.getSpanStart(span);
        int end = spanText.getSpanEnd(span);
        String url = span.getURL();
        if (url != null) {
            result = true;
            spanText.removeSpan(span);
            ClickableSpan span1 = new GoURLSpan(span.getURL());
            spanText.setSpan(span1, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }

    return result;
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:23,代碼來源:GoURLSpan.java

示例9: formatURLSpan

import android.text.style.URLSpan; //導入方法依賴的package包/類
public static Spannable formatURLSpan(Spannable s) {
    Linkify.addLinks(s, Linkify.WEB_URLS);
    URLSpan[] urlSpans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan urlSpan : urlSpans) {
        final String url = urlSpan.getURL();
        final Matcher m = chinesePattern.matcher(url);
        if (m.find()) {
            s.removeSpan(urlSpan);
            continue;
        }
        int start = s.getSpanStart(urlSpan);
        int end = s.getSpanEnd(urlSpan);
        s.removeSpan(urlSpan);
        s.setSpan(new TalkURLSpan(urlSpan.getURL(), ThemeUtil.getThemeColor(MainApp.CONTEXT.
                        getResources(), BizLogic.getTeamColor())), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return s;
}
 
開發者ID:jianliaoim,項目名稱:talk-android,代碼行數:20,代碼來源:MessageFormatter.java

示例10: initLink

import android.text.style.URLSpan; //導入方法依賴的package包/類
private void initLink() {
       tv = (TextView) findViewById(R.id.tv_link_test);
	tv.setClickable(false);  
 
       String htmlLinkText = "<a href=\"測試\">link</a> specified via an <a> tag.";   
       // 文字的樣式(style)被覆蓋,不能改變……  
       tv.setText(Html.fromHtml(htmlLinkText));  
       tv.setMovementMethod(LinkMovementMethod.getInstance());  
         
       CharSequence text = tv.getText();  
       if (text instanceof Spannable) {  
           int end = text.length();  
           Spannable sp = (Spannable) tv.getText();  
           URLSpan[] urls = sp.getSpans(0, end, URLSpan.class);  
           SpannableStringBuilder style = new SpannableStringBuilder(text);  
           style.clearSpans();// should clear old spans  
           for (URLSpan url : urls) {  
               MyURLSpan myURLSpan = new MyURLSpan(url.getURL());  
               style.setSpan(myURLSpan, sp.getSpanStart(url), sp.getSpanEnd(url), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);  
           }  
           tv.setText(style);  
       }
}
 
開發者ID:iOnesmile,項目名稱:MyAndroidDemo,代碼行數:24,代碼來源:TextViewLinkActivity.java

示例11: styleLinkifiedTextView

import android.text.style.URLSpan; //導入方法依賴的package包/類
/**
 * Stylify text view to primary colour and no underline
 * @param c App context
 * @param t TextView
 */
public static void styleLinkifiedTextView(Context c, TextView t) {
    // Get individual spans and replace them with clickable ones.
    Spannable s = new SpannableString(t.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(c, span.getURL());
        s.setSpan(span, start, end, 0);
    }

    t.setText(s);
    // Need to set this to allow for clickable TextView links.
    if (!(t instanceof HtmlTextView)) {
        t.setMovementMethod(LinkMovementMethod.getInstance());
        t.setLongClickable(false);
    }
}
 
開發者ID:lloydtorres,項目名稱:stately,代碼行數:25,代碼來源:SparkleHelper.java

示例12: wrapIntoHashGirlURLSpan

import android.text.style.URLSpan; //導入方法依賴的package包/類
private SpannableString wrapIntoHashGirlURLSpan(String htmlText, final OnClickHashListener onClickHashListener) {
    SpannableString s = SpannableString.valueOf(Html.fromHtml(htmlText));
    URLSpan[] urlSpanList = s.getSpans(0, s.length(), URLSpan.class);
    for(URLSpan urlSpan : urlSpanList) {
        int start = s.getSpanStart(urlSpan);
        int end = s.getSpanEnd(urlSpan);
        s.removeSpan(urlSpan);
        HashGirlURLSpan hashGirlURLSpan = new HashGirlURLSpan(urlSpan.getURL(), new OnClickHashListener() {
            @Override
            public void onClickHash(String url) {
                if(onClickHashListener != null) {
                    onClickHashListener.onClickHash(url);
                }
            }
        });
        hashGirlURLSpan.setUnderline(underline);
        hashGirlURLSpan.setStrike(strike);
        hashGirlURLSpan.setColor(color);
        hashGirlURLSpan.setBgcolor(bgcolor);
        hashGirlURLSpan.setAlpha(alpha);
        s.setSpan(hashGirlURLSpan, start, end, 0);
    }
    return s;
}
 
開發者ID:skyfe79,項目名稱:HashGirl,代碼行數:25,代碼來源:HashGirl.java

示例13: resetLinkSpan

import android.text.style.URLSpan; //導入方法依賴的package包/類
private void resetLinkSpan(SpannableStringBuilder ssb, RichTextConfig config, URLSpan urlSpan) {
    int start = ssb.getSpanStart(urlSpan);
    int end = ssb.getSpanEnd(urlSpan);
    ssb.removeSpan(urlSpan);
    LinkHolder linkHolder = new LinkHolder(urlSpan.getURL(), accentColor);
    if (config.linkFixCallback != null) {
        config.linkFixCallback.fix(linkHolder);
    }
    LongClickableURLSpan longClickableURLSpan = new LongClickableURLSpan(linkHolder, config.onUrlClickListener, config.onUrlLongClickListener);
    ssb.setSpan(longClickableURLSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:12,代碼來源:CachedSpannedParser.java

示例14: addCustomTabUrlHandler

import android.text.style.URLSpan; //導入方法依賴的package包/類
private static void addCustomTabUrlHandler(Activity activity, TextView textView) {
    CharSequence text = textView.getText();
    Spannable s = new SpannableString(text);
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span : spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new CustomTabUrlSpan(activity, span.getURL());
        s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
}
 
開發者ID:mecid,項目名稱:robird-reborn,代碼行數:14,代碼來源:LinkUtils.java

示例15: stripUnderlines

import android.text.style.URLSpan; //導入方法依賴的package包/類
public static void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:13,代碼來源:URLSpanNoUnderline.java


注:本文中的android.text.style.URLSpan.getURL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。