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


Java Linkify.TransformFilter方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: addCustomLink2

import android.text.util.Linkify; //導入方法依賴的package包/類
public static void addCustomLink2(TextView textView) {
    // @用戶:
    Pattern pattern = Pattern.compile("\\#([A-Za-z0-9\u4E00-\u9FA5]+)\\#");
    // http://www.qq.com/path?uid=1&username=xx
    String scheme = "weibo://topic?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);
            return true;
        }
    };
    Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
        @Override
        public String transformUrl(Matcher match, String url) {
            return match.group(1);
        }
    };
    Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);
}
 
開發者ID:JackChan1999,項目名稱:WeChatDemo,代碼行數:23,代碼來源:LinkifyUtil.java

示例4: testLnkifyPattern1_TransformFilter1

import android.text.util.Linkify; //導入方法依賴的package包/類
public void testLnkifyPattern1_TransformFilter1() {
    String text = inputText1;
    Pattern pattern = Pattern.compile("CA");
    Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
        @Override
        public String transformUrl(Matcher match, String url) {
            return url + "/" + url;
        }
    };
    C1 config = createConfigurator(text);
    T2 result = config
            .linkify(pattern, "http://www.google.ie/search?q=", null, transformFilter)
            .apply();
    assertEquals(text, getText(result));
    Object[] spans = getSpans(result);
    assertEquals(1, spans.length);
    Spanned spanned = toSpanned(result);
    assertURLSpan(spanned, spans[0], 162, 164, 33, "http://www.google.ie/search?q=CA/CA");

}
 
開發者ID:bluecabin,項目名稱:Textoo,代碼行數:21,代碼來源:ConfiguratorImplTest.java

示例5: testLnkifyPattern1_TransformFilter2

import android.text.util.Linkify; //導入方法依賴的package包/類
public void testLnkifyPattern1_TransformFilter2() {
    String text = inputText1 + inputText2;
    Pattern pattern = Pattern.compile("CA");
    Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
        @Override
        public String transformUrl(Matcher match, String url) {
            return url + "/" + url;
        }
    };
    C1 config = createConfigurator(text);
    T2 result = config
            .linkify(pattern, "http://www.google.ie/search?q=", null, transformFilter)
            .apply();
    assertEquals(text, getText(result));
    Object[] spans = getSpans(result);
    assertEquals(2, spans.length);
    Spanned spanned = toSpanned(result);
    assertURLSpan(spanned, spans[0], 162, 164, 33, "http://www.google.ie/search?q=CA/CA");
    assertURLSpan(spanned, spans[1], 351, 353, 33, "http://www.google.ie/search?q=CA/CA");
}
 
開發者ID:bluecabin,項目名稱:Textoo,代碼行數:21,代碼來源:ConfiguratorImplTest.java

示例6: 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

示例7: linkifyUrl

import android.text.util.Linkify; //導入方法依賴的package包/類
private static void linkifyUrl(Spannable spannable) {
    Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
        @Override
        public String transformUrl(Matcher matcher, String value) {
            return value;
        }
    };
    Linkify.addLinks(spannable, PATTERN_URL, SCHEME_URL, null, transformFilter);
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:10,代碼來源:PatternUtils.java

示例8: linkify

import android.text.util.Linkify; //導入方法依賴的package包/類
@Override
public abstract SpannedConfigurator linkify(Pattern p, String scheme, Linkify.MatchFilter matchFilter,
                                            Linkify.TransformFilter transformFilter);
 
開發者ID:bluecabin,項目名稱:Textoo,代碼行數:4,代碼來源:StringConfigurator.java

示例9: linkify

import android.text.util.Linkify; //導入方法依賴的package包/類
@Override
public abstract TextViewConfigurator linkify(Pattern p, String scheme, Linkify.MatchFilter matchFilter,
                                             Linkify.TransformFilter transformFilter);
 
開發者ID:bluecabin,項目名稱:Textoo,代碼行數:4,代碼來源:TextViewConfigurator.java

示例10: linkify

import android.text.util.Linkify; //導入方法依賴的package包/類
/**
 * Applies a regex to the text and turn the matches into links.
 * See <a href="http://developer.android.com/reference/android/text/util/Linkify.html#addLinks(android.widget.TextView, java.util.regex.Pattern, java.lang.String, android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter)">
 * android.text.util.Linkify#addLinks(android.text.Spannable, java.util.regex.Pattern, java.lang.String, android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter)</a>
 *
 * @param p               Regex pattern to be used for finding links
 * @param scheme          Url scheme string (eg http://) to be prepended to the url of links that do not have a scheme specified in the link text
 * @param matchFilter     The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.
 * @param transformFilter enables client code to have more control over how matched patterns are represented as URLs.
 * @return updated configurator for further configurations
 */
C linkify(Pattern p, String scheme,
          Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter);
 
開發者ID:bluecabin,項目名稱:Textoo,代碼行數:14,代碼來源:TextLinkify.java


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