public final class TextLinks


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

Nested types

public final class TextLinks.Builder

This class is deprecated.

Use android.view.textclassifier.TextLinks.Builder instead.

This class is deprecated.

You may create your own custom span by calling apply.

public final class TextLinks.Request

This class is deprecated.

Use android.view.textclassifier.TextLinks.Request instead.

public final class TextLinks.Request.Builder

This class is deprecated.

Use android.view.textclassifier.TextLinks.Builder instead.

public interface TextLinks.SpanFactory

This interface is deprecated.

Use apply instead.

public final class TextLinks.TextLink

This class is deprecated.

Use android.view.textclassifier.TextLinks.TextLink instead.

public abstract class TextLinks.TextLinkSpan extends ClickableSpan

This class is deprecated.

Use android.view.textclassifier.TextLinks.TextLinkSpan instead.

This class is deprecated.

Access the data from android.view.textclassifier.TextLinks.TextLinkSpan directly instead.

Constants

static final int

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

static final int

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

static final int

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

static final int

Links were successfully applied to the text.

static final int

No links applied to text.

static final int

No links exist to apply to text.

static final int

Status unknown.

Public methods

int
apply(
    @NonNull Spannable text,
    @NonNull TextClassifier textClassifier,
    @NonNull TextLinksParams textLinksParams
)

Annotates the given text with the generated links.

static @NonNull TextLinks

Extracts an TextLinks object from a bundle that was added using toBundle.

@NonNull Bundle

Returns the extended, vendor specific data.

@NonNull Collection<TextLinks.TextLink>

Returns an unmodifiable Collection of the links.

@NonNull CharSequence

Returns the text that was used to generate these links.

@NonNull Bundle

Adds a TextLinks object to a Bundle that can be read back with the same parameters to createFromBundle.

@NonNull String

Constants

APPLY_STRATEGY_IGNORE

public static final int APPLY_STRATEGY_IGNORE = 0

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

APPLY_STRATEGY_REPLACE

public static final int APPLY_STRATEGY_REPLACE = 1

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

STATUS_DIFFERENT_TEXT

public static final int STATUS_DIFFERENT_TEXT = 3

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

public static final int STATUS_LINKS_APPLIED = 0

Links were successfully applied to the text.

public static final int STATUS_NO_LINKS_APPLIED = 2

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

public static final int STATUS_NO_LINKS_FOUND = 1

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

STATUS_UNKNOWN

public static final int STATUS_UNKNOWN = -1

Status unknown.

Public methods

apply

public int apply(
    @NonNull Spannable text,
    @NonNull TextClassifier textClassifier,
    @NonNull TextLinksParams textLinksParams
)

Annotates the given text with the generated links.

NOTE: It may be necessary to set a LinkMovementMethod on the TextView widget to properly handle links. See setMovementMethod. It is also necessary that the TextView be focusable. See setFocusable} and setFocusableInTouchMode.

Parameters
@NonNull Spannable text

the text to apply the links to. Must match the original text

@NonNull TextClassifier textClassifier

the TextClassifier to use to classify a clicked link. Should usually be the one used to generate the links

@NonNull TextLinksParams textLinksParams

the param that specifies how the links should be applied

Returns
int

the status code which indicates the operation is success or not.

createFromBundle

public static @NonNull TextLinks createFromBundle(@NonNull Bundle bundle)

Extracts an TextLinks object from a bundle that was added using toBundle.

Throws
java.lang.IllegalArgumentException

if the bundle is malformed.

getExtras

public @NonNull Bundle getExtras()

Returns the extended, vendor specific data.

NOTE: Each call to this method returns a new bundle copy so clients should prefer to hold a reference to the returned bundle rather than frequently calling this method. Avoid updating the content of this bundle. On pre-O devices, the values in the Bundle are not deep copied.

getLinks

public @NonNull Collection<TextLinks.TextLinkgetLinks()

Returns an unmodifiable Collection of the links.

getText

public @NonNull CharSequence getText()

Returns the text that was used to generate these links.

toBundle

public @NonNull Bundle toBundle()

Adds a TextLinks object to a Bundle that can be read back with the same parameters to createFromBundle.

toString

public @NonNull String toString()