Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

TextClassification.Builder

public static final class TextClassification.Builder
extends Object

java.lang.Object
   ↳ android.view.textclassifier.TextClassification.Builder


Builder for building TextClassification objects.

e.g.

TextClassification classification = new TextClassification.Builder()
          .setText(classifiedText)
          .setEntityType(TextClassifier.TYPE_EMAIL, 0.9)
          .setEntityType(TextClassifier.TYPE_OTHER, 0.1)
          .addAction(remoteAction1)
          .addAction(remoteAction2)
          .build();
 

Summary

Public constructors

TextClassification.Builder()

Public methods

TextClassification.Builder addAction(RemoteAction action)

Adds an action that may be performed on the classified text.

TextClassification build()

Builds and returns a TextClassification object.

TextClassification.Builder setEntityType(String type, float confidenceScore)

Sets an entity type for the classification result and assigns a confidence score.

TextClassification.Builder setIcon(Drawable icon)

This method was deprecated in API level 28. Use addAction(RemoteAction) instead.

TextClassification.Builder setId(String id)

Sets an id for the TextClassification object.

TextClassification.Builder setIntent(Intent intent)

This method was deprecated in API level 28. Use addAction(RemoteAction) instead.

TextClassification.Builder setLabel(String label)

This method was deprecated in API level 28. Use addAction(RemoteAction) instead.

TextClassification.Builder setOnClickListener(View.OnClickListener onClickListener)

This method was deprecated in API level 28. Use addAction(RemoteAction) instead.

TextClassification.Builder setText(String text)

Sets the classified text.

Inherited methods

Public constructors

TextClassification.Builder

added in API level 26
public TextClassification.Builder ()

Public methods

addAction

added in API level 28
public TextClassification.Builder addAction (RemoteAction action)

Adds an action that may be performed on the classified text. Actions should be added in order of likelihood that the user will use them, with the most likely action being added first.

Parameters
action RemoteAction

This value must never be null.

Returns
TextClassification.Builder

This value will never be null.

build

added in API level 26
public TextClassification build ()

Builds and returns a TextClassification object.

Returns
TextClassification

This value will never be null.

setEntityType

added in API level 26
public TextClassification.Builder setEntityType (String type, 
                float confidenceScore)

Sets an entity type for the classification result and assigns a confidence score. If a confidence score had already been set for the specified entity type, this will override that score.

Parameters
type String

This value must never be null.

Value is TYPE_UNKNOWN, TYPE_OTHER, TYPE_EMAIL, TYPE_PHONE, TYPE_ADDRESS, TYPE_URL, TYPE_DATE, TYPE_DATE_TIME or TYPE_FLIGHT_NUMBER.

confidenceScore float: a value from 0 (low confidence) to 1 (high confidence). 0 implies the entity does not exist for the classified text. Values greater than 1 are clamped to 1.

Value is between 0.0 and 1.0 inclusive.

Returns
TextClassification.Builder

This value will never be null.

setIcon

added in API level 26
public TextClassification.Builder setIcon (Drawable icon)

This method was deprecated in API level 28.
Use addAction(RemoteAction) instead.

Sets the icon for the primary action that may be rendered on a widget used to act on the classified text.

NOTE: This field is not parcelled. If read from a parcel, the returned icon represents the icon of the first RemoteAction (if one exists).

Parameters
icon Drawable

This value may be null.

Returns
TextClassification.Builder

This value will never be null.

setId

added in API level 28
public TextClassification.Builder setId (String id)

Sets an id for the TextClassification object.

Parameters
id String

This value may be null.

Returns
TextClassification.Builder

This value will never be null.

setIntent

added in API level 26
public TextClassification.Builder setIntent (Intent intent)

This method was deprecated in API level 28.
Use addAction(RemoteAction) instead.

Sets the intent for the primary action that may be fired to act on the classified text.

NOTE: This field is not parcelled.

Parameters
intent Intent

This value may be null.

Returns
TextClassification.Builder

This value will never be null.

setLabel

added in API level 26
public TextClassification.Builder setLabel (String label)

This method was deprecated in API level 28.
Use addAction(RemoteAction) instead.

Sets the label for the primary action that may be rendered on a widget used to act on the classified text.

NOTE: This field is not parcelled. If read from a parcel, the returned label represents the label of the first RemoteAction (if one exists).

Parameters
label String

This value may be null.

Returns
TextClassification.Builder

This value will never be null.

setOnClickListener

added in API level 26
public TextClassification.Builder setOnClickListener (View.OnClickListener onClickListener)

This method was deprecated in API level 28.
Use addAction(RemoteAction) instead.

Sets the OnClickListener for the primary action that may be triggered to act on the classified text.

NOTE: This field is not parcelable. If read from a parcel, the returned OnClickListener represents the first RemoteAction (if one exists).

Parameters
onClickListener View.OnClickListener

This value may be null.

Returns
TextClassification.Builder

This value will never be null.

setText

added in API level 26
public TextClassification.Builder setText (String text)

Sets the classified text.

Parameters
text String

This value may be null.

Returns
TextClassification.Builder

This value will never be null.