Merge "Update TextClassifier Javadoc."

This commit is contained in:
TreeHugger Robot
2017-10-24 21:50:59 +00:00
committed by Android (Google) Code Review
2 changed files with 50 additions and 4 deletions

View File

@@ -33,6 +33,52 @@ import java.util.List;
/**
* Information for generating a widget to handle classified text.
*
* <p>A TextClassification object contains icons, labels, onClickListeners and intents that may
* be used to build a widget that can be used to act on classified text.
*
* <p>e.g. building a view that, when clicked, shares the classified text with the preferred app:
*
* <pre>{@code
* // Called preferably outside the UiThread.
* TextClassification classification = textClassifier.classifyText(allText, 10, 25, null);
*
* // Called on the UiThread.
* Button button = new Button(context);
* button.setCompoundDrawablesWithIntrinsicBounds(classification.getIcon(), null, null, null);
* button.setText(classification.getLabel());
* button.setOnClickListener(classification.getOnClickListener());
* }</pre>
*
* <p>e.g. starting an action mode with menu items that can handle the classified text:
*
* <pre>{@code
* // Called preferably outside the UiThread.
* final TextClassification classification = textClassifier.classifyText(allText, 10, 25, null);
*
* // Called on the UiThread.
* view.startActionMode(new ActionMode.Callback() {
*
* public boolean onCreateActionMode(ActionMode mode, Menu menu) {
* for (int i = 0; i < classification.getActionCount(); i++) {
* if (thisAppHasPermissionToInvokeIntent(classification.getIntent(i))) {
* menu.add(Menu.NONE, i, 20, classification.getLabel(i))
* .setIcon(classification.getIcon(i))
* .setIntent(classification.getIntent(i));
* }
* }
* return true;
* }
*
* public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
* context.startActivity(item.getIntent());
* return true;
* }
*
* ...
* });
* }</pre>
*
*/
public final class TextClassification {

View File

@@ -29,8 +29,8 @@ import java.lang.annotation.RetentionPolicy;
/**
* Interface for providing text classification related features.
*
* <p>Unless otherwise stated, methods of this interface are blocking operations and you should
* avoid calling them on the UI thread.
* <p>Unless otherwise stated, methods of this interface are blocking operations.
* Avoid calling them on the UI thread.
*/
public interface TextClassifier {
@@ -75,8 +75,8 @@ public interface TextClassifier {
};
/**
* Returns suggested text selection indices, recognized types and their associated confidence
* scores. The selections are ordered from highest to lowest scoring.
* Returns suggested text selection start and end indices, recognized entity types, and their
* associated confidence scores. The entity types are ordered from highest to lowest scoring.
*
* @param text text providing context for the selected text (which is specified
* by the sub sequence starting at selectionStartIndex and ending at selectionEndIndex)