本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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");
}
示例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");
}
示例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);
}
示例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);
}
示例8: linkify
import android.text.util.Linkify; //導入方法依賴的package包/類
@Override
public abstract SpannedConfigurator linkify(Pattern p, String scheme, Linkify.MatchFilter matchFilter,
Linkify.TransformFilter transformFilter);
示例9: linkify
import android.text.util.Linkify; //導入方法依賴的package包/類
@Override
public abstract TextViewConfigurator linkify(Pattern p, String scheme, Linkify.MatchFilter matchFilter,
Linkify.TransformFilter transformFilter);
示例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);