The Android Developer Challenge is back! Submit your idea before December 2.

TextLinks

class TextLinks
kotlin.Any
   ↳ androidx.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

A builder to construct a TextLinks instance.

The default implementation of TextLinkSpan.

A request object for generating TextLinks.

abstract

A factory to create spans from TextLinks.

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

abstract

A ClickableSpan for a TextLink.

Contains necessary data for TextLinkSpan.

Constants

static Int

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

static Int

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

static Int

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

static Int

Links were successfully applied to the text.

static Int

No links applied to text.

static Int

No links exist to apply to text.

static Int

Status unknown.

Public methods

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

Annotates the given text with the generated links.

static TextLinks
createFromBundle(@NonNull bundle: Bundle)

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

Bundle

Returns the extended, vendor specific data.

MutableCollection<TextLinks.TextLink!>

Returns an unmodifiable Collection of the links.

Bundle

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

String

Constants

APPLY_STRATEGY_IGNORE

static val APPLY_STRATEGY_IGNORE: Int

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

Value: 0

APPLY_STRATEGY_REPLACE

static val APPLY_STRATEGY_REPLACE: Int

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

Value: 1

STATUS_DIFFERENT_TEXT

static val STATUS_DIFFERENT_TEXT: Int

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

Value: 3

STATUS_LINKS_APPLIED

static val STATUS_LINKS_APPLIED: Int

Links were successfully applied to the text.

Value: 0

STATUS_NO_LINKS_APPLIED

static val STATUS_NO_LINKS_APPLIED: Int

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

Value: 2

STATUS_NO_LINKS_FOUND

static val STATUS_NO_LINKS_FOUND: Int

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

Value: 1

STATUS_UNKNOWN

static val STATUS_UNKNOWN: Int

Status unknown.

Value: -1

Public methods

apply

fun apply(@NonNull text: Spannable, @NonNull textClassifier: TextClassifier, @NonNull textLinksParams: TextLinksParams): Int

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 TextView#setMovementMethod(MovementMethod)

Parameters
text Spannable: the text to apply the links to. Must match the original text
textClassifier Spannable: the TextClassifier to use to classify a clicked link. Should usually be the one used to generate the links
textLinksParams Spannable: the param that specifies how the links should be applied
Return
Int: the status code which indicates the operation is success or not.

createFromBundle

@NonNull static fun createFromBundle(@NonNull bundle: Bundle): TextLinks

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

Exceptions
IllegalArgumentException if the bundle is malformed.

getExtras

@NonNull fun getExtras(): Bundle

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

@NonNull fun getLinks(): MutableCollection<TextLinks.TextLink!>

Returns an unmodifiable Collection of the links.

toBundle

@NonNull fun toBundle(): Bundle

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

toString

@NonNull fun toString(): String