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

Commit 5eb72657 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Automerger Merge Worker
Browse files

Merge "Rewrite Icons from the TCS." into rvc-dev am: 1cf3ce8f am: f58bd41b

Change-Id: Id6192fc8dd949482fd3dc76a19a0a6aa40c39432
parents 36715ce0 f58bd41b
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -424,6 +424,11 @@ public abstract class TextClassifierService extends Service {
        return bundle.getParcelable(KEY_RESULT);
        return bundle.getParcelable(KEY_RESULT);
    }
    }


    /** @hide **/
    public static <T extends Parcelable> void putResponse(Bundle bundle, T response) {
        bundle.putParcelable(KEY_RESULT, response);
    }

    /**
    /**
     * Callbacks for TextClassifierService results.
     * Callbacks for TextClassifierService results.
     *
     *
+9 −0
Original line number Original line Diff line number Diff line
@@ -206,6 +206,15 @@ public final class ConversationAction implements Parcelable {
        return mExtras;
        return mExtras;
    }
    }


    /** @hide */
    public Builder toBuilder() {
        return new Builder(mType)
            .setTextReply(mTextReply)
            .setAction(mAction)
            .setConfidenceScore(mScore)
            .setExtras(mExtras);
    }

    /** Builder class to construct {@link ConversationAction}. */
    /** Builder class to construct {@link ConversationAction}. */
    public static final class Builder {
    public static final class Builder {
        @Nullable
        @Nullable
+4 −0
Original line number Original line Diff line number Diff line
@@ -88,6 +88,10 @@ final class EntityConfidence implements Parcelable {
        return 0;
        return 0;
    }
    }


    public Map<String, Float> toMap() {
        return new ArrayMap(mEntityConfidence);
    }

    @Override
    @Override
    public String toString() {
    public String toString() {
        return mEntityConfidence.toString();
        return mEntityConfidence.toString();
+41 −24
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.time.ZonedDateTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Locale;
@@ -270,6 +271,20 @@ public final class TextClassification implements Parcelable {
        return mExtras;
        return mExtras;
    }
    }


    /** @hide */
    public Builder toBuilder() {
        return new Builder()
                .setId(mId)
                .setText(mText)
                .addActions(mActions)
                .setEntityConfidence(mEntityConfidence)
                .setIcon(mLegacyIcon)
                .setLabel(mLegacyLabel)
                .setIntent(mLegacyIntent)
                .setOnClickListener(mLegacyOnClickListener)
                .setExtras(mExtras);
    }

    @Override
    @Override
    public String toString() {
    public String toString() {
        return String.format(Locale.US,
        return String.format(Locale.US,
@@ -323,7 +338,7 @@ public final class TextClassification implements Parcelable {
     */
     */
    public static final class Builder {
    public static final class Builder {


        @NonNull private List<RemoteAction> mActions = new ArrayList<>();
        @NonNull private final List<RemoteAction> mActions = new ArrayList<>();
        @NonNull private final Map<String, Float> mTypeScoreMap = new ArrayMap<>();
        @NonNull private final Map<String, Float> mTypeScoreMap = new ArrayMap<>();
        @Nullable private String mText;
        @Nullable private String mText;
        @Nullable private Drawable mLegacyIcon;
        @Nullable private Drawable mLegacyIcon;
@@ -332,8 +347,6 @@ public final class TextClassification implements Parcelable {
        @Nullable private OnClickListener mLegacyOnClickListener;
        @Nullable private OnClickListener mLegacyOnClickListener;
        @Nullable private String mId;
        @Nullable private String mId;
        @Nullable private Bundle mExtras;
        @Nullable private Bundle mExtras;
        @NonNull private final ArrayList<Intent> mActionIntents = new ArrayList<>();
        @Nullable private Bundle mForeignLanguageExtra;


        /**
        /**
         * Sets the classified text.
         * Sets the classified text.
@@ -361,6 +374,18 @@ public final class TextClassification implements Parcelable {
            return this;
            return this;
        }
        }


        Builder setEntityConfidence(EntityConfidence scores) {
            mTypeScoreMap.clear();
            mTypeScoreMap.putAll(scores.toMap());
            return this;
        }

        /** @hide */
        public Builder clearEntityTypes() {
            mTypeScoreMap.clear();
            return this;
        }

        /**
        /**
         * Adds an action that may be performed on the classified text. Actions should be added in
         * 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
         * order of likelihood that the user will use them, with the most likely action being added
@@ -368,19 +393,21 @@ public final class TextClassification implements Parcelable {
         */
         */
        @NonNull
        @NonNull
        public Builder addAction(@NonNull RemoteAction action) {
        public Builder addAction(@NonNull RemoteAction action) {
            return addAction(action, null);
        }

        /**
         * @param intent the intent in the remote action.
         * @see #addAction(RemoteAction)
         * @hide
         */
        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
        public Builder addAction(RemoteAction action, @Nullable Intent intent) {
            Preconditions.checkArgument(action != null);
            Preconditions.checkArgument(action != null);
            mActions.add(action);
            mActions.add(action);
            mActionIntents.add(intent);
            return this;
        }

        /** @hide */
        public Builder addActions(Collection<RemoteAction> actions) {
            Objects.requireNonNull(actions);
            mActions.addAll(actions);
            return this;
        }

        /** @hide */
        public Builder clearActions() {
            mActions.clear();
            return this;
            return this;
        }
        }


@@ -465,16 +492,6 @@ public final class TextClassification implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * @see #setExtras(Bundle)
         * @hide
         */
        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
        public Builder setForeignLanguageExtra(@Nullable Bundle extra) {
            mForeignLanguageExtra = extra;
            return this;
        }

        /**
        /**
         * Builds and returns a {@link TextClassification} object.
         * Builds and returns a {@link TextClassification} object.
         */
         */
+73 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.textclassifier;

import static com.google.common.truth.Truth.assertThat;

import android.app.PendingIntent;
import android.app.RemoteAction;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.os.Bundle;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public final class ConversationActionTest {

    @Test
    public void toBuilder() {
        final Context context = InstrumentationRegistry.getTargetContext();
        final PendingIntent intent = PendingIntent.getActivity(context, 0, new Intent(), 0);
        final Icon icon = Icon.createWithData(new byte[]{0}, 0, 1);
        final Bundle extras = new Bundle();
        extras.putInt("key", 5);
        final ConversationAction convAction =
                new ConversationAction.Builder(ConversationAction.TYPE_CALL_PHONE)
                        .setAction(new RemoteAction(icon, "title", "descr", intent))
                        .setConfidenceScore(0.5f)
                        .setExtras(extras)
                        .build();

        final ConversationAction fromBuilder = convAction.toBuilder().build();

        assertThat(fromBuilder.getType()).isEqualTo(convAction.getType());
        assertThat(fromBuilder.getAction()).isEqualTo(convAction.getAction());
        assertThat(fromBuilder.getConfidenceScore()).isEqualTo(convAction.getConfidenceScore());
        assertThat(fromBuilder.getExtras()).isEqualTo(convAction.getExtras());
        assertThat(fromBuilder.getTextReply()).isEqualTo(convAction.getTextReply());
    }

    @Test
    public void toBuilder_textReply() {
        final ConversationAction convAction =
                new ConversationAction.Builder(ConversationAction.TYPE_TEXT_REPLY)
                        .setTextReply(":P")
                        .build();

        final ConversationAction fromBuilder = convAction.toBuilder().build();

        assertThat(fromBuilder.getTextReply()).isEqualTo(convAction.getTextReply());
    }
}
Loading