Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

TextSelection

class TextSelection
kotlin.Any
   ↳ androidx.textclassifier.TextSelection

Information about where text selection should be.

Summary

Nested classes

Builder used to build TextSelection objects.

A request object for generating TextSelection.

Public methods

static TextSelection
createFromBundle(@NonNull bundle: Bundle)

Extracts a selection from a bundle that was added using toBundle().

Float

Returns the confidence score for the specified entity.

String

Returns the entity type at the specified index.

Int

Returns the number of entity types found in the classified text.

Bundle

Returns the extended, vendor specific data.

String?

Returns the id, if one exists, for this object.

Int

Returns the end index of the text selection.

Int

Returns the start index of the text selection.

Bundle

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

String

Public methods

createFromBundle

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

Extracts a selection from a bundle that was added using toBundle().

getConfidenceScore

fun getConfidenceScore(entity: String!): Float

Returns the confidence score for the specified entity. The value ranges from 0 (low confidence) to 1 (high confidence). 0 indicates that the entity was not found for the classified text.

getEntityType

@NonNull fun getEntityType(index: Int): String

Returns the entity type at the specified index. Entities are ordered from high confidence to low confidence.

Exceptions
IndexOutOfBoundsException if the specified index is out of range.

getEntityTypeCount

fun getEntityTypeCount(): Int

Returns the number of entity types found in the classified text.

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.

getId

@Nullable fun getId(): String?

Returns the id, if one exists, for this object.

getSelectionEndIndex

fun getSelectionEndIndex(): Int

Returns the end index of the text selection.

getSelectionStartIndex

fun getSelectionStartIndex(): Int

Returns the start index of the text selection.

toBundle

@NonNull fun toBundle(): Bundle

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

toString

fun toString(): String