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


Java Linkify.addLinks方法代碼示例

本文整理匯總了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);
}
 
開發者ID:JackChan1999,項目名稱:WeChatDemo,代碼行數:26,代碼來源:LinkifyUtil.java

示例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);
    }
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:21,代碼來源:MessageObject.java

示例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();
}
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:17,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:20,代碼來源:PatternUtils.java

示例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);
}
 
開發者ID:Yuijam,項目名稱:droidfan,代碼行數:21,代碼來源:StatusUtils.java

示例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;
}
 
開發者ID:liulinbo,項目名稱:Amumu,代碼行數:20,代碼來源:HtmlUtils.java

示例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());
}
 
開發者ID:freespanish,項目名稱:Diccionario,代碼行數:17,代碼來源:MainActivity.java

示例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();
    }
 
開發者ID:ratmole,項目名稱:Mach3Pendant,代碼行數:20,代碼來源:Mach3PendantActivity.java

示例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;
}
 
開發者ID:gregoreesmaa,項目名稱:minu-poska-android,代碼行數:8,代碼來源:TextUtils.java

示例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);
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:16,代碼來源:CustomTextView.java

示例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;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:14,代碼來源:ConversationItem.java

示例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);
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:10,代碼來源:PatternUtils.java

示例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;
}
 
開發者ID:Protino,項目名稱:Fad-Flicks,代碼行數:10,代碼來源:ReviewDetailFragment.java

示例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();
}
 
開發者ID:Vhati,項目名稱:OpenUHS,代碼行數:16,代碼來源:DownloaderActivity.java

示例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);
}
 
開發者ID:EyeSeeTea,項目名稱:EDSApp,代碼行數:13,代碼來源:AUtils.java


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