Java 类android.text.util.Linkify.MatchFilter 实例源码

项目:tomdroid    文件:LinkInternalSpan.java   
public static MatchFilter getNoteLinkMatchFilter(final SpannableStringBuilder noteContent, final LinkInternalSpan[] links) {

    return new MatchFilter() {

        public boolean acceptMatch(CharSequence s, int start, int end) {
            int spanstart, spanend;
            for(LinkInternalSpan link: links) {
                spanstart = noteContent.getSpanStart(link);
                spanend = noteContent.getSpanEnd(link);
                if(!(end <= spanstart || spanend <= start)) {
                    return false;
                }
            }
            return true;
        }
    };
}
项目:tomdroid    文件:ViewNote.java   
private void showNote(boolean xml) {
    if(xml) {
        content.setText(note.getXmlContent());
        title.setText((CharSequence) note.getTitle());
        this.setTitle(this.getTitle() + " - XML");
        return;
    }
    LinkInternalSpan[] links = noteContent.getSpans(0, noteContent.length(), LinkInternalSpan.class);
    MatchFilter noteLinkMatchFilter = LinkInternalSpan.getNoteLinkMatchFilter(noteContent, links);

    // show the note (spannable makes the TextView able to output styled text)
    content.setText(noteContent, TextView.BufferType.SPANNABLE);

    // add links to stuff that is understood by Android except phone numbers because it's too aggressive
    // TODO this is SLOWWWW!!!!
    int linkFlags = 0;

    if(Preferences.getBoolean(Preferences.Key.LINK_EMAILS))
        linkFlags |= Linkify.EMAIL_ADDRESSES;
    if(Preferences.getBoolean(Preferences.Key.LINK_URLS))
        linkFlags |= Linkify.WEB_URLS;
    if(Preferences.getBoolean(Preferences.Key.LINK_ADDRESSES))
        linkFlags |= Linkify.MAP_ADDRESSES;

    Linkify.addLinks(content, linkFlags);

    // Custom phone number linkifier (fixes lp:512204)
    if(Preferences.getBoolean(Preferences.Key.LINK_PHONES))
        Linkify.addLinks(content, LinkifyPhone.PHONE_PATTERN, "tel:", LinkifyPhone.sPhoneNumberMatchFilter, Linkify.sPhoneNumberTransformFilter);

    // This will create a link every time a note title is found in the text.
    // The pattern contains a very dumb (title1)|(title2) escaped correctly
    // Then we transform the url from the note name to the note id to avoid characters that mess up with the URI (ex: ?)
    if(Preferences.getBoolean(Preferences.Key.LINK_TITLES)) {
        Pattern pattern = NoteManager.buildNoteLinkifyPattern(this, note.getTitle());

        if(pattern != null) {
            Linkify.addLinks(
                content,
                pattern,
                Tomdroid.CONTENT_URI+"/",
                noteLinkMatchFilter,
                noteTitleTransformFilter
            );

            // content.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
    title.setText((CharSequence) note.getTitle());
}
项目:tomdroid    文件:EditNote.java   
private void showNote(boolean xml) {
    if(xml) {

        formatBar.setVisibility(View.GONE);
        content.setText(note.getXmlContent());
        title.setText((CharSequence) note.getTitle());
        this.setTitle(this.getTitle() + " - XML");
        xmlOn = true;
        return;
    }

    LinkInternalSpan[] links = noteContent.getSpans(0, noteContent.length(), LinkInternalSpan.class);
    MatchFilter noteLinkMatchFilter = LinkInternalSpan.getNoteLinkMatchFilter(noteContent, links);

    // show the note (spannable makes the TextView able to output styled text)
    content.setText(noteContent, TextView.BufferType.SPANNABLE);

    // add links to stuff that is understood by Android except phone numbers because it's too aggressive
    // TODO this is SLOWWWW!!!!
    int linkFlags = 0;

    if(Preferences.getBoolean(Preferences.Key.LINK_EMAILS))
        linkFlags |= Linkify.EMAIL_ADDRESSES;
    if(Preferences.getBoolean(Preferences.Key.LINK_URLS))
        linkFlags |= Linkify.WEB_URLS;
    if(Preferences.getBoolean(Preferences.Key.LINK_ADDRESSES))
        linkFlags |= Linkify.MAP_ADDRESSES;

    Linkify.addLinks(content, linkFlags);

    // Custom phone number linkifier (fixes lp:512204)
    if(Preferences.getBoolean(Preferences.Key.LINK_PHONES))
        Linkify.addLinks(content, LinkifyPhone.PHONE_PATTERN, "tel:", LinkifyPhone.sPhoneNumberMatchFilter, Linkify.sPhoneNumberTransformFilter);

    // This will create a link every time a note title is found in the text.
    // The pattern contains a very dumb (title1)|(title2) escaped correctly
    // Then we transform the url from the note name to the note id to avoid characters that mess up with the URI (ex: ?)
    if(Preferences.getBoolean(Preferences.Key.LINK_TITLES)) {
        Pattern pattern = NoteManager.buildNoteLinkifyPattern(this, note.getTitle());

        if(pattern != null) {
            Linkify.addLinks(
                content,
                pattern,
                Tomdroid.CONTENT_URI+"/",
                noteLinkMatchFilter,
                noteTitleTransformFilter
            );

            // content.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
    title.setText((CharSequence) note.getTitle());
}
项目:tomdroid    文件:Tomdroid.java   
private void showNote(boolean xml) {

    if(xml) {
        content.setText(note.getXmlContent());
        title.setText((CharSequence) note.getTitle());
        this.setTitle(this.getTitle() + " - XML");
        return;
    }

    LinkInternalSpan[] links = noteContent.getSpans(0, noteContent.length(), LinkInternalSpan.class);
    MatchFilter noteLinkMatchFilter = LinkInternalSpan.getNoteLinkMatchFilter(noteContent, links);

    // show the note (spannable makes the TextView able to output styled text)
    content.setText(noteContent, TextView.BufferType.SPANNABLE);

    // add links to stuff that is understood by Android except phone numbers because it's too aggressive
    // TODO this is SLOWWWW!!!!

    int linkFlags = 0;

    if(Preferences.getBoolean(Preferences.Key.LINK_EMAILS))
        linkFlags |= Linkify.EMAIL_ADDRESSES;
    if(Preferences.getBoolean(Preferences.Key.LINK_URLS))
        linkFlags |= Linkify.WEB_URLS;
    if(Preferences.getBoolean(Preferences.Key.LINK_ADDRESSES))
        linkFlags |= Linkify.MAP_ADDRESSES;

    Linkify.addLinks(content, linkFlags);

    // Custom phone number linkifier (fixes lp:512204)
    if(Preferences.getBoolean(Preferences.Key.LINK_PHONES))
        Linkify.addLinks(content, LinkifyPhone.PHONE_PATTERN, "tel:", LinkifyPhone.sPhoneNumberMatchFilter, Linkify.sPhoneNumberTransformFilter);

    // This will create a link every time a note title is found in the text.
    // The pattern contains a very dumb (title1)|(title2) escaped correctly
    // Then we transform the url from the note name to the note id to avoid characters that mess up with the URI (ex: ?)
    if(Preferences.getBoolean(Preferences.Key.LINK_TITLES)) {
        Pattern pattern = NoteManager.buildNoteLinkifyPattern(this, note.getTitle());

        if(pattern != null) {
            Linkify.addLinks(
                content,
                pattern,
                Tomdroid.CONTENT_URI+"/",
                noteLinkMatchFilter,
                noteTitleTransformFilter
            );

            // content.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
    title.setText((CharSequence) note.getTitle());
}