本文整理汇总了Java中android.text.util.Linkify.addLinks方法的典型用法代码示例。如果您正苦于以下问题:Java Linkify.addLinks方法的具体用法?Java Linkify.addLinks怎么用?Java Linkify.addLinks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.util.Linkify
的用法示例。
在下文中一共展示了Linkify.addLinks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCustomLink
import android.text.util.Linkify; //导入方法依赖的package包/类
/**
* 添加自定义超链接
*/
public static void addCustomLink(TextView textView) {
// @用户:
Pattern pattern = Pattern.compile("\\@([A-Za-z0-9\u4E00-\u9FA5]+)\\.?");
// http://www.qq.com/path?uid=1&username=xx
String scheme = "weibo://user?uid=";
// 匹配过滤器
Linkify.MatchFilter matchFilter = new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence s, int start, int end) {
String text = s.subSequence(start, end).toString();
// System.out.println("----text: " + text);
if (text.endsWith(".")) { // 邮箱,不需要匹配
return false;
} else {
return true; // 返回true会显示为超链接
}
}
};
Linkify.TransformFilter transformFilter = null;
Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);
}
示例2: generateLinkDescription
import android.text.util.Linkify; //导入方法依赖的package包/类
public void generateLinkDescription() {
if (linkDescription != null) {
return;
}
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage && messageOwner.media.webpage.description != null) {
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.webpage.description);
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame && messageOwner.media.game.description != null) {
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.game.description);
}
if (linkDescription != null) {
if (containsUrls(linkDescription)) {
try {
Linkify.addLinks((Spannable) linkDescription, Linkify.WEB_URLS);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
linkDescription = Emoji.replaceEmoji(linkDescription, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
}
}
示例3: showAboutDialog
import android.text.util.Linkify; //导入方法依赖的package包/类
private void showAboutDialog() {
// Transform text into URL link
View aboutView = getLayoutInflater().inflate(R.layout.dialog_about, null, false);
TextView txtView = (TextView) aboutView.findViewById(R.id.aboutTxtView);
Pattern pattern = Pattern.compile("here");
Linkify.addLinks(txtView, pattern, getString(R.string.magpie_url));
// Create and show the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(
this,
android.R.style.Theme_Material_Light_NoActionBar_Fullscreen));
builder.setTitle(getString(R.string.about_app))
.setView(aboutView)
.create()
.show();
}
示例4: linkifyUsers
import android.text.util.Linkify; //导入方法依赖的package包/类
private static void linkifyUsers(Spannable spannable, final Map<String, String> userMap) {
Linkify.MatchFilter filter = new Linkify.MatchFilter() {
@Override
public final boolean acceptMatch(final CharSequence s, final int start, final int end) {
String name = s.subSequence(start + 1, end).toString().trim();
return userMap.containsKey(name);
}
};
Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher matcher, String value) {
String userName = value.subSequence(1, value.length()).toString().trim();
String userId = userMap.get(userName);
return userId;
}
};
Linkify.addLinks(spannable, PATTERN_AT, SCHEME_AT, filter, transformFilter);
}
示例5: setItemStatus
import android.text.util.Linkify; //导入方法依赖的package包/类
public static void setItemStatus(final TextView textView, final String text) {
final String htmlText = text + " ";
final List<String> highlightWords = findHighlightWords(htmlText);
final String plainText = Html.fromHtml(htmlText).toString();
final SpannableString spannable = new SpannableString(plainText);
Linkify.addLinks(spannable, Linkify.WEB_URLS);
final Matcher m = PATTERN_USER.matcher(spannable);
while (m.find()) {
int start = m.start(1);
int end = m.end(1);
if (start >= 0 && start < end) {
spannable.setSpan(new ForegroundColorSpan(AppContext.getContext().getResources().getColor(R.color.colorPrimary)), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
linkifyTags(spannable);
removeUnderLines(spannable);
applyHighlightSpan(spannable, highlightWords);
textView.setText(spannable, BufferType.SPANNABLE);
}
示例6: linkifyPlainLinks
import android.text.util.Linkify; //导入方法依赖的package包/类
private static SpannableStringBuilder linkifyPlainLinks(CharSequence input,
ColorStateList linkTextColor,
@ColorInt int linkHighlightColor) {
final SpannableString plainLinks = new SpannableString(input); // copy of input
Linkify.addLinks(plainLinks, Linkify.WEB_URLS);
final URLSpan[] urlSpans = plainLinks.getSpans(0, plainLinks.length(), URLSpan.class);
// add any plain links to the output
final SpannableStringBuilder ssb = new SpannableStringBuilder(input);
for (URLSpan urlSpan : urlSpans) {
ssb.setSpan(new TouchableUrlSpan(urlSpan.getURL(), linkTextColor, linkHighlightColor),
plainLinks.getSpanStart(urlSpan),
plainLinks.getSpanEnd(urlSpan),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return ssb;
}
示例7: showAboutDialog
import android.text.util.Linkify; //导入方法依赖的package包/类
@Override
public void showAboutDialog() {
final SpannableString spannableString = new SpannableString(getString(R.string.about_msg));
Linkify.addLinks(spannableString, Linkify.ALL);
final AlertDialog aboutDialog = new AlertDialog.Builder(this)
.setPositiveButton(android.R.string.ok, null)
.setTitle(getString(R.string.app_name) + " " + getString(R.string.app_version))
.setMessage(spannableString)
.create();
aboutDialog.show();
((TextView) aboutDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}
示例8: showTitlesDialog
import android.text.util.Linkify; //导入方法依赖的package包/类
private void showTitlesDialog() {
String aboutTitle = String.format("About %s", getString(R.string.app_name));
String versionString = String.format("Version: %s", getString(R.string.version));
String aboutText = getString(R.string.about);
final TextView message = new TextView(this);
final SpannableString s = new SpannableString(aboutText);
message.setPadding(5, 5, 5, 5);
message.setText(versionString + "\n\n" + s);
Linkify.addLinks(message, Linkify.ALL);
new AlertDialog.Builder(this).
setTitle(aboutTitle).
setCancelable(true).
setIcon(R.drawable.icon).
setPositiveButton(this.getString(android.R.string.ok), null).
setView(message).create().show();
}
示例9: linkify
import android.text.util.Linkify; //导入方法依赖的package包/类
public static CharSequence linkify(CharSequence str) {
SpannableStringBuilder ssb = new SpannableStringBuilder(str);
Linkify.addLinks(ssb, emailPattern, "mailto:");
Linkify.addLinks(ssb, httpUrlPattern, null);
Linkify.addLinks(ssb, wwwUrlPattern, "http://");
return ssb;
}
示例10: setTextWithAIMessage
import android.text.util.Linkify; //导入方法依赖的package包/类
/**
* 解析机器人搜索到文档的内容
*
* @param context
* @param textView
* @param text
*/
public static void setTextWithAIMessage(Context context, TextView textView, String text) {
textView.setText(Html.fromHtml(filterHtmlTag(MessageUtils.dealAIMessage(text))));
String type = SafeJson.safeGet(SafeJson.parseObj(text), Field.TYPE);
dealAILink(textView, type);
Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
textView.setMovementMethod(new AIMessageMovementMethod());
dealAILink(textView, type);
}
示例11: linkifyMessageBody
import android.text.util.Linkify; //导入方法依赖的package包/类
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0);
if (hasLinks) {
URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = messageBody.getSpanStart(urlSpan);
int end = messageBody.getSpanEnd(urlSpan);
messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return messageBody;
}
示例12: linkifyTopic
import android.text.util.Linkify; //导入方法依赖的package包/类
private static void linkifyTopic(Spannable spannable) {
Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher matcher, String value) {
return value.replace("#", "");
}
};
Linkify.addLinks(spannable, PATTERN_TOPIC, SCHEME_TOPIC, null, transformFilter);
}
示例13: onCreateView
import android.text.util.Linkify; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.review_detail, container, false);
ButterKnife.bind(this, rootView);
reviewAuthor.setText(review.getAuthor());
reviewText.setText(review.getContent());
Linkify.addLinks(reviewText, Linkify.ALL);
return rootView;
}
示例14: showAboutMessage
import android.text.util.Linkify; //导入方法依赖的package包/类
/**
* Shows a dialog describing this app.
*/
private void showAboutMessage() {
SpannableString aboutMessage = new SpannableString( this.getString( R.string.alert_about_message ) );
Linkify.addLinks( aboutMessage, Linkify.WEB_URLS );
AlertDialog.Builder aboutBuilder = new AlertDialog.Builder( this );
aboutBuilder.setIcon( R.drawable.ic_info_normal_24dp );
aboutBuilder.setTitle( R.string.alert_about_title );
aboutBuilder.setMessage( aboutMessage );
aboutBuilder.setPositiveButton(R.string.ok, null );
AlertDialog aboutDialog = aboutBuilder.create();
aboutDialog.show();
}
示例15: showAlertWithHtmlMessageAndLastCommit
import android.text.util.Linkify; //导入方法依赖的package包/类
/**
* Shows an alert dialog with a big message inside based on a raw resource HTML formatted
* @param titleId Id of the title resource
* @param rawId Id of the raw text resource in HTML format
*/
public static void showAlertWithHtmlMessageAndLastCommit(int titleId, int rawId, Context context){
String stringMessage = getMessageWithCommit(rawId, context);
final SpannableString linkedMessage = new SpannableString(Html.fromHtml(stringMessage));
Linkify.addLinks(linkedMessage, Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);
showAlertWithLogoAndVersion(titleId, linkedMessage, context);
}