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

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

Merge "Put the TextClassification action's intent in the extra."

parents 70244c68 385b10c1
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ import java.util.concurrent.TimeUnit;
 */
public final class TextClassifierImpl implements TextClassifier {

    /** @hide */
    public static final String ACTIONS_INTENTS = "actions-intents";

    private static final String LOG_TAG = DEFAULT_LOG_TAG;

    private static final boolean DEBUG = false;
@@ -567,6 +570,7 @@ public final class TextClassifierImpl implements TextClassifier {
        // TODO: Make this configurable.
        final float foreignTextThreshold = typeCount == 0 ? 0.5f : 0.7f;
        boolean isPrimaryAction = true;
        final ArrayList<Intent> sourceIntents = new ArrayList<>();
        for (LabeledIntent labeledIntent : IntentFactory.create(
                mContext, classifiedText, isForeignText(classifiedText, foreignTextThreshold),
                referenceTime, highestScoringResult)) {
@@ -586,9 +590,15 @@ public final class TextClassifierImpl implements TextClassifier {
                isPrimaryAction = false;
            }
            builder.addAction(action);
            sourceIntents.add(labeledIntent.getIntent());
        }

        return builder.setId(createId(text, start, end)).build();
        final Bundle extras = new Bundle();
        extras.putParcelableArrayList(ACTIONS_INTENTS, sourceIntents);

        return builder.setId(createId(text, start, end))
                .setExtras(extras)
                .build();
    }

    private boolean isForeignText(String text, float threshold) {
+3 −0
Original line number Diff line number Diff line
@@ -262,6 +262,9 @@ public class TextClassifierTest {
        assertEquals(
                context.getString(com.android.internal.R.string.translate),
                classification.getActions().get(0).getTitle());
        Intent intent = (Intent) classification.getExtras()
                .getParcelableArrayList(TextClassifierImpl.ACTIONS_INTENTS).get(0);
        assertEquals(Intent.ACTION_TRANSLATE, intent.getAction());

        LocaleList.setDefault(originalLocales);
    }