TextLinks
public
final
class
TextLinks
extends Object
java.lang.Object | |
↳ | 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 | |
---|---|
class |
TextLinks.Builder
A builder to construct a TextLinks instance. |
class |
TextLinks.DefaultTextLinkSpan
The default implementation of |
class |
TextLinks.Request
A request object for generating TextLinks. |
interface |
TextLinks.SpanFactory
A factory to create spans from 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. |
class |
TextLinks.TextLinkSpanData
Contains necessary data for |
Constants | |
---|---|
int |
APPLY_STRATEGY_IGNORE
Do not replace |
int |
APPLY_STRATEGY_REPLACE
Replace any |
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. |
int |
STATUS_UNKNOWN
Status unknown. |
Public methods | |
---|---|
int
|
apply(Spannable text, TextClassifier textClassifier, TextLinksParams textLinksParams)
Annotates the given text with the generated links. |
static
TextLinks
|
createFromBundle(Bundle bundle)
Extracts an TextLinks object from a bundle that was added using |
Bundle
|
getExtras()
Returns the extended, vendor specific data. |
Collection<TextLinks.TextLink>
|
getLinks()
Returns an unmodifiable Collection of the links. |
CharSequence
|
getText()
Returns the text that was used to generate these links. |
Bundle
|
toBundle()
Adds a TextLinks object to a Bundle that can be read back with the same parameters
to |
String
|
toString()
|
Inherited methods | |
---|---|
Constants
APPLY_STRATEGY_IGNORE
public static final int APPLY_STRATEGY_IGNORE
Do not replace ClickableSpan
s that exist where the TextLinks.TextLinkSpan
needs to
be applied to. Do not apply the TextLinkSpan.
Constant Value: 0 (0x00000000)
APPLY_STRATEGY_REPLACE
public static final int APPLY_STRATEGY_REPLACE
Replace any ClickableSpan
s that exist where the TextLinks.TextLinkSpan
needs to be
applied to.
Constant Value: 1 (0x00000001)
STATUS_DIFFERENT_TEXT
public static final int STATUS_DIFFERENT_TEXT
The specified text does not match the text used to generate the links.
Constant Value: 3 (0x00000003)
STATUS_LINKS_APPLIED
public static final int STATUS_LINKS_APPLIED
Links were successfully applied to the text.
Constant Value: 0 (0x00000000)
STATUS_NO_LINKS_APPLIED
public static final int STATUS_NO_LINKS_APPLIED
No links applied to text. The links were filtered out.
Constant Value: 2 (0x00000002)
STATUS_NO_LINKS_FOUND
public static final int STATUS_NO_LINKS_FOUND
No links exist to apply to text. Links count is zero.
Constant Value: 1 (0x00000001)
STATUS_UNKNOWN
public static final int STATUS_UNKNOWN
Status unknown.
Constant Value: -1 (0xffffffff)
Public methods
apply
public int apply (Spannable text, TextClassifier textClassifier, 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 TextView.setMovementMethod(MovementMethod)
.
It is also necessary that the TextView be focusable.
See View.setFocusable(boolean)
} and
View.setFocusableInTouchMode(boolean)
.
Parameters | |
---|---|
text |
Spannable : the text to apply the links to. Must match the original text |
textClassifier |
TextClassifier : the TextClassifier to use to classify a clicked link. Should usually
be the one used to generate the links |
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 TextLinks createFromBundle (Bundle bundle)
Extracts an TextLinks object from a bundle that was added using toBundle()
.
Parameters | |
---|---|
bundle |
Bundle |
Returns | |
---|---|
TextLinks |
Throws | |
---|---|
IllegalArgumentException |
if the bundle is malformed. |
getExtras
public 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.
Returns | |
---|---|
Bundle |
getLinks
public Collection<TextLinks.TextLink> getLinks ()
Returns an unmodifiable Collection of the links.
Returns | |
---|---|
Collection<TextLinks.TextLink> |
getText
public CharSequence getText ()
Returns the text that was used to generate these links.
Returns | |
---|---|
CharSequence |
toBundle
public Bundle toBundle ()
Adds a TextLinks object to a Bundle that can be read back with the same parameters
to createFromBundle(Bundle)
.
Returns | |
---|---|
Bundle |
toString
public String toString ()
Returns | |
---|---|
String |
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.