Build 1.0_r1(from source)

android.text.util
Class Linkify

java.lang.Object
  extended by android.text.util.Linkify

public class Linkify
extends Object

Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links. This is particularly useful for matching things like email addresses, web urls, etc. and making them actionable. Alone with the pattern that is to be matched, a url scheme prefix is also required. Any pattern match that does not begin with the supplied scheme will have the scheme prepended to the matched text when the clickable url is created. For instance, if you are matching web urls you would supply the scheme http://. If the pattern matches example.com, which does not have a url scheme prefix, the supplied scheme will be prepended to create http://example.com when the clickable url link is created.


Nested Class Summary
static interface Linkify.MatchFilter
          MatchFilter enables client code to have more control over what is allowed to match and become a link, and what is not.
static interface Linkify.TransformFilter
          TransformFilter enables client code to have more control over how matched patterns are represented as URLs.
 
Field Summary
static int ALL
          Bit mask indicating that all available patterns should be matched in methods that take an options mask
static int EMAIL_ADDRESSES
          Bit field indicating that email addresses should be matched in methods that take an options mask
static int MAP_ADDRESSES
          Bit field indicating that phone numbers should be matched in methods that take an options mask
static int PHONE_NUMBERS
          Bit field indicating that phone numbers should be matched in methods that take an options mask
static Linkify.MatchFilter sPhoneNumberMatchFilter
          Filters out URL matches that don't have enough digits to be a phone number.
static Linkify.TransformFilter sPhoneNumberTransformFilter
          Transforms matched phone number text into something suitable to be used in a tel: URL.
static Linkify.MatchFilter sUrlMatchFilter
          Filters out web URL matches that occur after an at-sign (@).
static int WEB_URLS
          Bit field indicating that web URLs should be matched in methods that take an options mask
 
Constructor Summary
Linkify()
           
 
Method Summary
static boolean addLinks(Spannable text, int mask)
          Scans the text of the provided Spannable and turns all occurrences of the link types indicated in the mask into clickable links.
static boolean addLinks(Spannable text, Pattern pattern, String scheme)
          Applies a regex to a Spannable turning the matches into links.
static boolean addLinks(Spannable s, Pattern p, String scheme, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)
          Applies a regex to a Spannable turning the matches into links.
static boolean addLinks(TextView text, int mask)
          Scans the text of the provided TextView and turns all occurrences of the link types indicated in the mask into clickable links.
static void addLinks(TextView text, Pattern pattern, String scheme)
          Applies a regex to the text of a TextView turning the matches into links.
static void addLinks(TextView text, Pattern p, String scheme, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)
          Applies a regex to the text of a TextView turning the matches into links.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_URLS

public static final int WEB_URLS
Bit field indicating that web URLs should be matched in methods that take an options mask

See Also:
Constant Field Values

EMAIL_ADDRESSES

public static final int EMAIL_ADDRESSES
Bit field indicating that email addresses should be matched in methods that take an options mask

See Also:
Constant Field Values

PHONE_NUMBERS

public static final int PHONE_NUMBERS
Bit field indicating that phone numbers should be matched in methods that take an options mask

See Also:
Constant Field Values

MAP_ADDRESSES

public static final int MAP_ADDRESSES
Bit field indicating that phone numbers should be matched in methods that take an options mask

See Also:
Constant Field Values

ALL

public static final int ALL
Bit mask indicating that all available patterns should be matched in methods that take an options mask

See Also:
Constant Field Values

sUrlMatchFilter

public static final Linkify.MatchFilter sUrlMatchFilter
Filters out web URL matches that occur after an at-sign (@). This is to prevent turning the domain name in an email address into a web link.


sPhoneNumberMatchFilter

public static final Linkify.MatchFilter sPhoneNumberMatchFilter
Filters out URL matches that don't have enough digits to be a phone number.


sPhoneNumberTransformFilter

public static final Linkify.TransformFilter sPhoneNumberTransformFilter
Transforms matched phone number text into something suitable to be used in a tel: URL. It does this by removing everything but the digits and plus signs. For instance: '+1 (919) 555-1212' becomes '+19195551212'

Constructor Detail

Linkify

public Linkify()
Method Detail

addLinks

public static final boolean addLinks(Spannable text,
                                     int mask)
Scans the text of the provided Spannable and turns all occurrences of the link types indicated in the mask into clickable links. If the mask is nonzero, it also removes any existing URLSpans attached to the Spannable, to avoid problems if you call it repeatedly on the same text.


addLinks

public static final boolean addLinks(TextView text,
                                     int mask)
Scans the text of the provided TextView and turns all occurrences of the link types indicated in the mask into clickable links. If matches are found the movement method for the TextView is set to LinkMovementMethod.


addLinks

public static final void addLinks(TextView text,
                                  Pattern pattern,
                                  String scheme)
Applies a regex to the text of a TextView turning the matches into links. If links are found then UrlSpans are applied to the link text match areas, and the movement method for the text is changed to LinkMovementMethod.

Parameters:
text - TextView whose text is to be marked-up with links
pattern - Regex pattern to be used for finding links
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

addLinks

public static final void addLinks(TextView text,
                                  Pattern p,
                                  String scheme,
                                  Linkify.MatchFilter matchFilter,
                                  Linkify.TransformFilter transformFilter)
Applies a regex to the text of a TextView turning the matches into links. If links are found then UrlSpans are applied to the link text match areas, and the movement method for the text is changed to LinkMovementMethod.

Parameters:
text - TextView whose text is to be marked-up with links
p - Regex pattern to be used for finding links
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
matchFilter - The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.

addLinks

public static final boolean addLinks(Spannable text,
                                     Pattern pattern,
                                     String scheme)
Applies a regex to a Spannable turning the matches into links.

Parameters:
text - Spannable whose text is to be marked-up with links
pattern - Regex pattern to be used for finding links
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

addLinks

public static final boolean addLinks(Spannable s,
                                     Pattern p,
                                     String scheme,
                                     Linkify.MatchFilter matchFilter,
                                     Linkify.TransformFilter transformFilter)
Applies a regex to a Spannable turning the matches into links.

Parameters:
s - Spannable whose text is to be marked-up with links
p - Regex pattern to be used for finding links
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
matchFilter - The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature