本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}