Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b74d0640 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update TextClassifier Javadoc."

parents feb6ba28 33ff200c
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -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 {

+4 −4
Original line number Diff line number Diff line
@@ -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)