当前位置: 首页>>代码示例>>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;未经允许,请勿转载。