@Test public void testAddLinks_addsLinksWhenDefaultSchemeIsNull() { Spannable spannable = new SpannableString("any https: LinkifyCompat.addLinks(spannable, PatternsCompat.AUTOLINK_WEB_URL, null, null, null); URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class); assertEquals("android.com and https: assertEquals("https: assertEquals("android.com", spans[1].getURL()); }
public static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) { if (shouldAddLinksFallbackToFramework()) { return Linkify.addLinks(text, mask); } if (mask == 0) { return false; } URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } if ((mask & Linkify.PHONE_NUMBERS) != 0) { Linkify.addLinks(text, Linkify.PHONE_NUMBERS); } final ArrayList<LinkSpec> links = new ArrayList<>(); if ((mask & Linkify.WEB_URLS) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_WEB_URL, new String[] { "http: Linkify.sUrlMatchFilter, null); } if ((mask & Linkify.EMAIL_ADDRESSES) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_EMAIL_ADDRESS, new String[] { "mailto:" }, null, null); } if ((mask & Linkify.MAP_ADDRESSES) != 0) { gatherMapLinks(links, text); } pruneOverlaps(links, text); if (links.size() == 0) { return false; } for (LinkSpec link: links) { if (link.frameworkAddedSpan == null) { applyLink(link.url, link.start, link.end, text); } } return true; }
LinkifyCompat { public static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) { if (shouldAddLinksFallbackToFramework()) { return Linkify.addLinks(text, mask); } if (mask == 0) { return false; } URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } if ((mask & Linkify.PHONE_NUMBERS) != 0) { Linkify.addLinks(text, Linkify.PHONE_NUMBERS); } final ArrayList<LinkSpec> links = new ArrayList<>(); if ((mask & Linkify.WEB_URLS) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_WEB_URL, new String[] { "http: Linkify.sUrlMatchFilter, null); } if ((mask & Linkify.EMAIL_ADDRESSES) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_EMAIL_ADDRESS, new String[] { "mailto:" }, null, null); } if ((mask & Linkify.MAP_ADDRESSES) != 0) { gatherMapLinks(links, text); } pruneOverlaps(links, text); if (links.size() == 0) { return false; } for (LinkSpec link: links) { if (link.frameworkAddedSpan == null) { applyLink(link.url, link.start, link.end, text); } } return true; } }
LinkifyCompat { public static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) { if (shouldAddLinksFallbackToFramework()) { return Linkify.addLinks(text, mask); } if (mask == 0) { return false; } URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } if ((mask & Linkify.PHONE_NUMBERS) != 0) { Linkify.addLinks(text, Linkify.PHONE_NUMBERS); } final ArrayList<LinkSpec> links = new ArrayList<>(); if ((mask & Linkify.WEB_URLS) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_WEB_URL, new String[] { "http: Linkify.sUrlMatchFilter, null); } if ((mask & Linkify.EMAIL_ADDRESSES) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_EMAIL_ADDRESS, new String[] { "mailto:" }, null, null); } if ((mask & Linkify.MAP_ADDRESSES) != 0) { gatherMapLinks(links, text); } pruneOverlaps(links, text); if (links.size() == 0) { return false; } for (LinkSpec link: links) { if (link.frameworkAddedSpan == null) { applyLink(link.url, link.start, link.end, text); } } return true; } private  LinkifyCompat(); }
LinkifyCompat { public static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) { if (shouldAddLinksFallbackToFramework()) { return Linkify.addLinks(text, mask); } if (mask == 0) { return false; } URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } if ((mask & Linkify.PHONE_NUMBERS) != 0) { Linkify.addLinks(text, Linkify.PHONE_NUMBERS); } final ArrayList<LinkSpec> links = new ArrayList<>(); if ((mask & Linkify.WEB_URLS) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_WEB_URL, new String[] { "http: Linkify.sUrlMatchFilter, null); } if ((mask & Linkify.EMAIL_ADDRESSES) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_EMAIL_ADDRESS, new String[] { "mailto:" }, null, null); } if ((mask & Linkify.MAP_ADDRESSES) != 0) { gatherMapLinks(links, text); } pruneOverlaps(links, text); if (links.size() == 0) { return false; } for (LinkSpec link: links) { if (link.frameworkAddedSpan == null) { applyLink(link.url, link.start, link.end, text); } } return true; } private  LinkifyCompat(); static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask); static boolean addLinks(@NonNull TextView text, @LinkifyMask int mask); static void addLinks(@NonNull TextView text, @NonNull Pattern pattern,
            @Nullable String scheme); static void addLinks(@NonNull TextView text, @NonNull Pattern pattern,
            @Nullable String scheme, @Nullable MatchFilter matchFilter,
            @Nullable TransformFilter transformFilter); @SuppressLint("NewApi") static void addLinks(@NonNull TextView text, @NonNull Pattern pattern,
            @Nullable String defaultScheme, @Nullable String[] schemes,
            @Nullable MatchFilter matchFilter, @Nullable TransformFilter transformFilter); static boolean addLinks(@NonNull Spannable text, @NonNull Pattern pattern,
            @Nullable String scheme); static boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
            @Nullable String scheme, @Nullable MatchFilter matchFilter,
            @Nullable TransformFilter transformFilter); @SuppressLint("NewApi") static boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
            @Nullable  String defaultScheme, @Nullable String[] schemes,
            @Nullable MatchFilter matchFilter, @Nullable TransformFilter transformFilter); }
LinkifyCompat { public static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) { if (shouldAddLinksFallbackToFramework()) { return Linkify.addLinks(text, mask); } if (mask == 0) { return false; } URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } if ((mask & Linkify.PHONE_NUMBERS) != 0) { Linkify.addLinks(text, Linkify.PHONE_NUMBERS); } final ArrayList<LinkSpec> links = new ArrayList<>(); if ((mask & Linkify.WEB_URLS) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_WEB_URL, new String[] { "http: Linkify.sUrlMatchFilter, null); } if ((mask & Linkify.EMAIL_ADDRESSES) != 0) { gatherLinks(links, text, PatternsCompat.AUTOLINK_EMAIL_ADDRESS, new String[] { "mailto:" }, null, null); } if ((mask & Linkify.MAP_ADDRESSES) != 0) { gatherMapLinks(links, text); } pruneOverlaps(links, text); if (links.size() == 0) { return false; } for (LinkSpec link: links) { if (link.frameworkAddedSpan == null) { applyLink(link.url, link.start, link.end, text); } } return true; } private  LinkifyCompat(); static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask); static boolean addLinks(@NonNull TextView text, @LinkifyMask int mask); static void addLinks(@NonNull TextView text, @NonNull Pattern pattern,
            @Nullable String scheme); static void addLinks(@NonNull TextView text, @NonNull Pattern pattern,
            @Nullable String scheme, @Nullable MatchFilter matchFilter,
            @Nullable TransformFilter transformFilter); @SuppressLint("NewApi") static void addLinks(@NonNull TextView text, @NonNull Pattern pattern,
            @Nullable String defaultScheme, @Nullable String[] schemes,
            @Nullable MatchFilter matchFilter, @Nullable TransformFilter transformFilter); static boolean addLinks(@NonNull Spannable text, @NonNull Pattern pattern,
            @Nullable String scheme); static boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
            @Nullable String scheme, @Nullable MatchFilter matchFilter,
            @Nullable TransformFilter transformFilter); @SuppressLint("NewApi") static boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
            @Nullable  String defaultScheme, @Nullable String[] schemes,
            @Nullable MatchFilter matchFilter, @Nullable TransformFilter transformFilter);  }