TextLinks

public final class TextLinks
extends Object implements Parcelable

java.lang.Object
   ↳ android.view.textclassifier.TextLinks


A collection of links, representing subsequences of text and the entity types (phone number, address, url, etc) they may be.

Summary

Nested classes

class TextLinks.Builder

A builder to construct a TextLinks instance. 

class TextLinks.Request

A request object for generating TextLinks. 

class TextLinks.TextLink

A link, identifying a substring of text and possible entity types for it. 

class TextLinks.TextLinkSpan

A ClickableSpan for a TextLink. 

Constants

int APPLY_STRATEGY_IGNORE

Do not replace ClickableSpans that exist where the TextLinks.TextLinkSpan needs to be applied to.

int APPLY_STRATEGY_REPLACE

Replace any ClickableSpans that exist where the TextLinks.TextLinkSpan needs to be applied to.

int STATUS_DIFFERENT_TEXT

The specified text does not match the text used to generate the links.

int STATUS_LINKS_APPLIED

Links were successfully applied to the text.

int STATUS_NO_LINKS_APPLIED

No links applied to text.

int STATUS_NO_LINKS_FOUND

No links exist to apply to text.

Inherited constants

Fields

public static final Creator<TextLinks> CREATOR

Public methods

int apply(Spannable text, int applyStrategy, Function<TextLinks.TextLinkTextLinks.TextLinkSpan> spanFactory)

Annotates the given text with the generated links.

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

Collection<TextLinks.TextLink> getLinks()

Returns an unmodifiable Collection of the links.

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

APPLY_STRATEGY_IGNORE

int APPLY_STRATEGY_IGNORE

Do not replace ClickableSpans that exist where the TextLinks.TextLinkSpan needs to be applied to. Do not apply the TextLinkSpan.

Constant Value: 0 (0x00000000)

APPLY_STRATEGY_REPLACE

int APPLY_STRATEGY_REPLACE

Replace any ClickableSpans that exist where the TextLinks.TextLinkSpan needs to be applied to.

Constant Value: 1 (0x00000001)

STATUS_DIFFERENT_TEXT

int STATUS_DIFFERENT_TEXT

The specified text does not match the text used to generate the links.

Constant Value: 3 (0x00000003)

STATUS_LINKS_APPLIED

int STATUS_LINKS_APPLIED

Links were successfully applied to the text.

Constant Value: 0 (0x00000000)

STATUS_NO_LINKS_APPLIED

int STATUS_NO_LINKS_APPLIED

No links applied to text. The links were filtered out.

Constant Value: 2 (0x00000002)

STATUS_NO_LINKS_FOUND

int STATUS_NO_LINKS_FOUND

No links exist to apply to text. Links count is zero.

Constant Value: 1 (0x00000001)

Fields

Public methods

apply

int apply (Spannable text, 
                int applyStrategy, 
                Function<TextLinks.TextLinkTextLinks.TextLinkSpan> spanFactory)

Annotates the given text with the generated links. It will fail if the provided text doesn't match the original text used to create the TextLinks.

NOTE: It may be necessary to set a LinkMovementMethod on the TextView widget to properly handle links. See setMovementMethod(MovementMethod)

Parameters
text Spannable: the text to apply the links to. Must match the original text

This value must never be null.

applyStrategy int: the apply strategy used to determine how to apply links to text. e.g APPLY_STRATEGY_IGNORE

spanFactory Function: a custom span factory for converting TextLinks to TextLinkSpans. Set to null to use the default span factory.

Returns
int a status code indicating whether or not the links were successfully applied e.g. STATUS_LINKS_APPLIED

describeContents

int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

getLinks

Collection<TextLinks.TextLink> getLinks ()

Returns an unmodifiable Collection of the links.

Returns
Collection<TextLinks.TextLink>

This value will never be null.

toString

String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

writeToParcel

void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written.

flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.