TextClassifierEvent.TextSelectionEvent

public static final class TextClassifierEvent.TextSelectionEvent
extends TextClassifierEvent implements Parcelable

java.lang.Object
   ↳ android.view.textclassifier.TextClassifierEvent
     ↳ android.view.textclassifier.TextClassifierEvent.TextSelectionEvent


This class represents events that are related to the smart text selection feature.

     // User started a selection. e.g. "York" in text "New York City, NY".
     new TextSelectionEvent.Builder(TYPE_SELECTION_STARTED)
         .setEventContext(classificationContext)
         .setEventIndex(0)
         .build();

     // System smart-selects a recognized entity. e.g. "New York City".
     new TextSelectionEvent.Builder(TYPE_SMART_SELECTION_MULTI)
         .setEventContext(classificationContext)
         .setResultId(textSelection.getId())
         .setRelativeWordStartIndex(-1) // Goes back one word to "New" from "York".
         .setRelativeWordEndIndex(2)    // Goes forward 2 words from "York" to start of ",".
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setEventIndex(1)
         .build();

     // User resets the selection to the original selection. i.e. "York".
     new TextSelectionEvent.Builder(TYPE_SELECTION_RESET)
         .setEventContext(classificationContext)
         .setResultId(textSelection.getId())
         .setRelativeSuggestedWordStartIndex(-1) // Repeated from above.
         .setRelativeSuggestedWordEndIndex(2)    // Repeated from above.
         .setRelativeWordStartIndex(0)           // Original selection is always at (0, 1].
         .setRelativeWordEndIndex(1)
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setEventIndex(2)
         .build();

     // User modified the selection. e.g. "New".
     new TextSelectionEvent.Builder(TYPE_SELECTION_MODIFIED)
         .setEventContext(classificationContext)
         .setResultId(textSelection.getId())
         .setRelativeSuggestedWordStartIndex(-1) // Repeated from above.
         .setRelativeSuggestedWordEndIndex(2)    // Repeated from above.
         .setRelativeWordStartIndex(-1)          // Goes backward one word from "York" to
         "New".
         .setRelativeWordEndIndex(0)             // Goes backward one word to exclude "York".
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setEventIndex(3)
         .build();

     // Smart (contextual) actions (at indices, 0, 1, 2) presented to the user.
     // e.g. "Map", "Ride share", "Explore".
     new TextSelectionEvent.Builder(TYPE_ACTIONS_SHOWN)
         .setEventContext(classificationContext)
         .setResultId(textClassification.getId())
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setActionIndices(0, 1, 2)
         .setEventIndex(4)
         .build();

     // User chooses the "Copy" action.
     new TextSelectionEvent.Builder(TYPE_COPY_ACTION)
         .setEventContext(classificationContext)
         .setResultId(textClassification.getId())
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setEventIndex(5)
         .build();

     // User chooses smart action at index 1. i.e. "Ride share".
     new TextSelectionEvent.Builder(TYPE_SMART_ACTION)
         .setEventContext(classificationContext)
         .setResultId(textClassification.getId())
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setActionIndices(1)
         .setEventIndex(5)
         .build();

     // Selection dismissed.
     new TextSelectionEvent.Builder(TYPE_SELECTION_DESTROYED)
         .setEventContext(classificationContext)
         .setResultId(textClassification.getId())
         .setEntityTypes(textClassification.getEntity(0))
         .setScore(textClassification.getConfidenceScore(entityType))
         .setEventIndex(6)
         .build();
 

Summary

Nested classes

class TextClassifierEvent.TextSelectionEvent.Builder

Builder class for TextSelectionEvent

Inherited constants

Fields

public static final Creator<TextClassifierEvent.TextSelectionEvent> CREATOR

Inherited fields

Public methods

int getRelativeSuggestedWordEndIndex()

Returns the relative word (exclusive) index of the end of the smart selection.

int getRelativeSuggestedWordStartIndex()

Returns the relative word index of the start of the smart selection.

int getRelativeWordEndIndex()

Returns the relative word (exclusive) index of the end of the selection.

int getRelativeWordStartIndex()

Returns the relative word index of the start of the selection.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Fields

CREATOR

Added in API level 29
public static final Creator<TextClassifierEvent.TextSelectionEvent> CREATOR

Public methods

getRelativeSuggestedWordEndIndex

Added in API level 29
public int getRelativeSuggestedWordEndIndex ()

Returns the relative word (exclusive) index of the end of the smart selection.

Returns
int

getRelativeSuggestedWordStartIndex

Added in API level 29
public int getRelativeSuggestedWordStartIndex ()

Returns the relative word index of the start of the smart selection.

Returns
int

getRelativeWordEndIndex

Added in API level 29
public int getRelativeWordEndIndex ()

Returns the relative word (exclusive) index of the end of the selection.

Returns
int

getRelativeWordStartIndex

Added in API level 29
public int getRelativeWordStartIndex ()

Returns the relative word index of the start of the selection.

Returns
int

writeToParcel

Added in API level 29
public 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. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES