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

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

Merge "Populate entities information to extras and add copy action"

parents 74a57744 09214420
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -92,10 +92,15 @@ public final class ConversationAction implements Parcelable {
     */
     */
    public static final String TYPE_SHARE_LOCATION = "share_location";
    public static final String TYPE_SHARE_LOCATION = "share_location";


    // TODO: Make this public API
    /** @hide **/
    /** @hide **/
    public static final String TYPE_ADD_CONTACT = "add_contact";
    public static final String TYPE_ADD_CONTACT = "add_contact";


    public static final @android.annotation.NonNull Creator<ConversationAction> CREATOR =
    // TODO: Make this public API
    /** @hide **/
    public static final String TYPE_COPY = "copy";

    public static final @NonNull Creator<ConversationAction> CREATOR =
            new Creator<ConversationAction>() {
            new Creator<ConversationAction>() {
                @Override
                @Override
                public ConversationAction createFromParcel(Parcel in) {
                public ConversationAction createFromParcel(Parcel in) {
+25 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 */
 */
public final class ExtrasUtils {
public final class ExtrasUtils {


    private static final String ENTITIES_EXTRAS = "entities-extras";
    private static final String ACTION_INTENT = "action-intent";
    private static final String ACTION_INTENT = "action-intent";
    private static final String ACTIONS_INTENTS = "actions-intents";
    private static final String ACTIONS_INTENTS = "actions-intents";
    private static final String FOREIGN_LANGUAGE = "foreign-language";
    private static final String FOREIGN_LANGUAGE = "foreign-language";
@@ -93,6 +94,30 @@ public final class ExtrasUtils {
        return container.getParcelable(ACTION_INTENT);
        return container.getParcelable(ACTION_INTENT);
    }
    }


    /**
     * Stores {@code entities} information in TextClassifier response object's extras
     * {@code container}.
     *
     * @see {@link #getCopyText(Bundle)}
     */
    public static void putEntitiesExtras(Bundle container, @Nullable Bundle entitiesExtras) {
        container.putParcelable(ENTITIES_EXTRAS, entitiesExtras);
    }

    /**
     * Returns {@code entities} information contained in a TextClassifier response object.
     *
     * @see {@link #putEntitiesExtras(Bundle, Bundle)}
     */
    @Nullable
    public static String getCopyText(Bundle container) {
        Bundle entitiesExtras = container.getParcelable(ENTITIES_EXTRAS);
        if (entitiesExtras == null) {
            return null;
        }
        return entitiesExtras.getString("text");
    }

    /**
    /**
     * Returns {@code actionIntents} information contained in the TextClassification object.
     * Returns {@code actionIntents} information contained in the TextClassification object.
     */
     */
+1 −0
Original line number Original line Diff line number Diff line
@@ -193,6 +193,7 @@ public final class TextClassificationConstants {
                    .add(ConversationAction.TYPE_VIEW_CALENDAR)
                    .add(ConversationAction.TYPE_VIEW_CALENDAR)
                    .add(ConversationAction.TYPE_VIEW_MAP)
                    .add(ConversationAction.TYPE_VIEW_MAP)
                    .add(ConversationAction.TYPE_ADD_CONTACT)
                    .add(ConversationAction.TYPE_ADD_CONTACT)
                    .add(ConversationAction.TYPE_COPY)
                    .toString();
                    .toString();
    /**
    /**
     * < 0  : Not set. Use value from LangId model.
     * < 0  : Not set. Use value from LangId model.
+3 −0
Original line number Original line Diff line number Diff line
@@ -451,6 +451,9 @@ public final class TextClassifierImpl implements TextClassifier {
                remoteAction = labeledIntentResult.remoteAction;
                remoteAction = labeledIntentResult.remoteAction;
                ExtrasUtils.putActionIntent(extras, labeledIntentResult.resolvedIntent);
                ExtrasUtils.putActionIntent(extras, labeledIntentResult.resolvedIntent);
            }
            }
            ExtrasUtils.putEntitiesExtras(
                    extras,
                    TemplateIntentFactory.nameVariantsToBundle(nativeSuggestion.getEntityData()));
            conversationActions.add(
            conversationActions.add(
                    new ConversationAction.Builder(actionType)
                    new ConversationAction.Builder(actionType)
                            .setConfidenceScore(nativeSuggestion.getScore())
                            .setConfidenceScore(nativeSuggestion.getScore())
+10 −3
Original line number Original line Diff line number Diff line
@@ -41,6 +41,9 @@ import java.util.List;
public final class TemplateIntentFactory {
public final class TemplateIntentFactory {
    private static final String TAG = TextClassifier.DEFAULT_LOG_TAG;
    private static final String TAG = TextClassifier.DEFAULT_LOG_TAG;


    /**
     * Constructs and returns a list of {@link LabeledIntent} based on the given templates.
     */
    @Nullable
    @Nullable
    public List<LabeledIntent> create(
    public List<LabeledIntent> create(
            @NonNull RemoteActionTemplate[] remoteActionTemplates) {
            @NonNull RemoteActionTemplate[] remoteActionTemplates) {
@@ -108,11 +111,14 @@ public final class TemplateIntentFactory {
                }
                }
            }
            }
        }
        }
        intent.putExtras(createExtras(remoteActionTemplate.extras));
        intent.putExtras(nameVariantsToBundle(remoteActionTemplate.extras));
        return intent;
        return intent;
    }
    }


    private static Bundle createExtras(NamedVariant[] namedVariants) {
    /**
     * Converts an array of {@link NamedVariant} to a Bundle and returns it.
     */
    public static Bundle nameVariantsToBundle(@Nullable NamedVariant[] namedVariants) {
        if (namedVariants == null) {
        if (namedVariants == null) {
            return Bundle.EMPTY;
            return Bundle.EMPTY;
        }
        }
@@ -142,7 +148,8 @@ public final class TemplateIntentFactory {
                    break;
                    break;
                default:
                default:
                    Log.w(TAG,
                    Log.w(TAG,
                            "Unsupported type found in createExtras : " + namedVariant.getType());
                            "Unsupported type found in nameVariantsToBundle : "
                                    + namedVariant.getType());
            }
            }
        }
        }
        return bundle;
        return bundle;
Loading