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

Commit 74f3d396 authored by James Cook's avatar James Cook Committed by Android (Google) Code Review
Browse files

Merge "Allow different visual and voice assist prompts" into mnc-dev

parents 912f705f 6cf39750
Loading
Loading
Loading
Loading
+27 −8
Original line number Diff line number Diff line
@@ -5498,7 +5498,8 @@ package android.app {
  }
  public static class VoiceInteractor.AbortVoiceRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.AbortVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    ctor public VoiceInteractor.AbortVoiceRequest(android.app.VoiceInteractor.Prompt, android.os.Bundle);
    ctor public deprecated VoiceInteractor.AbortVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    method public void onAbortResult(android.os.Bundle);
  }
@@ -5508,17 +5509,20 @@ package android.app {
  }
  public static class VoiceInteractor.CompleteVoiceRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.CompleteVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    ctor public VoiceInteractor.CompleteVoiceRequest(android.app.VoiceInteractor.Prompt, android.os.Bundle);
    ctor public deprecated VoiceInteractor.CompleteVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    method public void onCompleteResult(android.os.Bundle);
  }
  public static class VoiceInteractor.ConfirmationRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.ConfirmationRequest(java.lang.CharSequence, android.os.Bundle);
    ctor public VoiceInteractor.ConfirmationRequest(android.app.VoiceInteractor.Prompt, android.os.Bundle);
    ctor public deprecated VoiceInteractor.ConfirmationRequest(java.lang.CharSequence, android.os.Bundle);
    method public void onConfirmationResult(boolean, android.os.Bundle);
  }
  public static class VoiceInteractor.PickOptionRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.PickOptionRequest(java.lang.CharSequence, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    ctor public VoiceInteractor.PickOptionRequest(android.app.VoiceInteractor.Prompt, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    ctor public deprecated VoiceInteractor.PickOptionRequest(java.lang.CharSequence, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    method public void onPickOptionResult(boolean, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
  }
@@ -5537,6 +5541,17 @@ package android.app {
    field public static final android.os.Parcelable.Creator<android.app.VoiceInteractor.PickOptionRequest.Option> CREATOR;
  }
  public static class VoiceInteractor.Prompt implements android.os.Parcelable {
    ctor public VoiceInteractor.Prompt(java.lang.CharSequence[], java.lang.CharSequence);
    ctor public VoiceInteractor.Prompt(java.lang.CharSequence);
    method public int countVoicePrompts();
    method public int describeContents();
    method public java.lang.CharSequence getVisualPrompt();
    method public java.lang.CharSequence getVoicePromptAt(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.VoiceInteractor.Prompt> CREATOR;
  }
  public static abstract class VoiceInteractor.Request {
    method public void cancel();
    method public android.app.Activity getActivity();
@@ -28987,7 +29002,8 @@ package android.service.voice {
  }
  public static final class VoiceInteractionSession.AbortVoiceRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public java.lang.CharSequence getMessage();
    method public deprecated java.lang.CharSequence getMessage();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendAbortResult(android.os.Bundle);
  }
@@ -28998,12 +29014,14 @@ package android.service.voice {
  }
  public static final class VoiceInteractionSession.CompleteVoiceRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public java.lang.CharSequence getMessage();
    method public deprecated java.lang.CharSequence getMessage();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendCompleteResult(android.os.Bundle);
  }
  public static final class VoiceInteractionSession.ConfirmationRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public java.lang.CharSequence getPrompt();
    method public deprecated java.lang.CharSequence getPrompt();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendConfirmationResult(boolean, android.os.Bundle);
  }
@@ -29019,7 +29037,8 @@ package android.service.voice {
  public static final class VoiceInteractionSession.PickOptionRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public android.app.VoiceInteractor.PickOptionRequest.Option[] getOptions();
    method public java.lang.CharSequence getPrompt();
    method public deprecated java.lang.CharSequence getPrompt();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendIntermediatePickOptionResult(android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    method public void sendPickOptionResult(android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
  }
+27 −8
Original line number Diff line number Diff line
@@ -5594,7 +5594,8 @@ package android.app {
  }
  public static class VoiceInteractor.AbortVoiceRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.AbortVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    ctor public VoiceInteractor.AbortVoiceRequest(android.app.VoiceInteractor.Prompt, android.os.Bundle);
    ctor public deprecated VoiceInteractor.AbortVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    method public void onAbortResult(android.os.Bundle);
  }
@@ -5604,17 +5605,20 @@ package android.app {
  }
  public static class VoiceInteractor.CompleteVoiceRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.CompleteVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    ctor public VoiceInteractor.CompleteVoiceRequest(android.app.VoiceInteractor.Prompt, android.os.Bundle);
    ctor public deprecated VoiceInteractor.CompleteVoiceRequest(java.lang.CharSequence, android.os.Bundle);
    method public void onCompleteResult(android.os.Bundle);
  }
  public static class VoiceInteractor.ConfirmationRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.ConfirmationRequest(java.lang.CharSequence, android.os.Bundle);
    ctor public VoiceInteractor.ConfirmationRequest(android.app.VoiceInteractor.Prompt, android.os.Bundle);
    ctor public deprecated VoiceInteractor.ConfirmationRequest(java.lang.CharSequence, android.os.Bundle);
    method public void onConfirmationResult(boolean, android.os.Bundle);
  }
  public static class VoiceInteractor.PickOptionRequest extends android.app.VoiceInteractor.Request {
    ctor public VoiceInteractor.PickOptionRequest(java.lang.CharSequence, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    ctor public VoiceInteractor.PickOptionRequest(android.app.VoiceInteractor.Prompt, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    ctor public deprecated VoiceInteractor.PickOptionRequest(java.lang.CharSequence, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    method public void onPickOptionResult(boolean, android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
  }
@@ -5633,6 +5637,17 @@ package android.app {
    field public static final android.os.Parcelable.Creator<android.app.VoiceInteractor.PickOptionRequest.Option> CREATOR;
  }
  public static class VoiceInteractor.Prompt implements android.os.Parcelable {
    ctor public VoiceInteractor.Prompt(java.lang.CharSequence[], java.lang.CharSequence);
    ctor public VoiceInteractor.Prompt(java.lang.CharSequence);
    method public int countVoicePrompts();
    method public int describeContents();
    method public java.lang.CharSequence getVisualPrompt();
    method public java.lang.CharSequence getVoicePromptAt(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.VoiceInteractor.Prompt> CREATOR;
  }
  public static abstract class VoiceInteractor.Request {
    method public void cancel();
    method public android.app.Activity getActivity();
@@ -31120,7 +31135,8 @@ package android.service.voice {
  }
  public static final class VoiceInteractionSession.AbortVoiceRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public java.lang.CharSequence getMessage();
    method public deprecated java.lang.CharSequence getMessage();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendAbortResult(android.os.Bundle);
  }
@@ -31131,12 +31147,14 @@ package android.service.voice {
  }
  public static final class VoiceInteractionSession.CompleteVoiceRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public java.lang.CharSequence getMessage();
    method public deprecated java.lang.CharSequence getMessage();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendCompleteResult(android.os.Bundle);
  }
  public static final class VoiceInteractionSession.ConfirmationRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public java.lang.CharSequence getPrompt();
    method public deprecated java.lang.CharSequence getPrompt();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendConfirmationResult(boolean, android.os.Bundle);
  }
@@ -31152,7 +31170,8 @@ package android.service.voice {
  public static final class VoiceInteractionSession.PickOptionRequest extends android.service.voice.VoiceInteractionSession.Request {
    method public android.app.VoiceInteractor.PickOptionRequest.Option[] getOptions();
    method public java.lang.CharSequence getPrompt();
    method public deprecated java.lang.CharSequence getPrompt();
    method public android.app.VoiceInteractor.Prompt getVoicePrompt();
    method public void sendIntermediatePickOptionResult(android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
    method public void sendPickOptionResult(android.app.VoiceInteractor.PickOptionRequest.Option[], android.os.Bundle);
  }
+1 −0
Original line number Diff line number Diff line
@@ -17,3 +17,4 @@
package android.app;

parcelable VoiceInteractor.PickOptionRequest.Option;
parcelable VoiceInteractor.Prompt;
+159 −12
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.os.Bundle;
import android.os.IBinder;
@@ -257,7 +259,7 @@ public class VoiceInteractor {
     * so the user can give a confirmation.
     */
    public static class ConfirmationRequest extends Request {
        final CharSequence mPrompt;
        final Prompt mPrompt;
        final Bundle mExtras;

        /**
@@ -266,11 +268,23 @@ public class VoiceInteractor {
         *     should be spoken.
         * @param extras Additional optional information or null.
         */
        public ConfirmationRequest(CharSequence prompt, Bundle extras) {
        public ConfirmationRequest(@Nullable Prompt prompt, @Nullable Bundle extras) {
            mPrompt = prompt;
            mExtras = extras;
        }

        /**
         * Create a new confirmation request.
         * @param prompt Optional confirmation to speak to the user or null if nothing
         *     should be spoken.
         * @param extras Additional optional information or null.
         * @deprecated Prefer the version that takes a {@link Prompt}.
         */
        public ConfirmationRequest(CharSequence prompt, Bundle extras) {
            mPrompt = (prompt != null ? new Prompt(prompt) : null);
            mExtras = extras;
        }

        public void onConfirmationResult(boolean confirmed, Bundle result) {
        }

@@ -288,7 +302,7 @@ public class VoiceInteractor {
     * either {@link #onPickOptionResult} or {@link #onCancel()}.
     */
    public static class PickOptionRequest extends Request {
        final CharSequence mPrompt;
        final Prompt mPrompt;
        final Option[] mOptions;
        final Bundle mExtras;

@@ -417,12 +431,27 @@ public class VoiceInteractor {
         * @param options The set of {@link Option}s the user is selecting from.
         * @param extras Additional optional information or null.
         */
        public PickOptionRequest(CharSequence prompt, Option[] options, Bundle extras) {
        public PickOptionRequest(@Nullable Prompt prompt, Option[] options,
                @Nullable Bundle extras) {
            mPrompt = prompt;
            mOptions = options;
            mExtras = extras;
        }

        /**
         * Create a new pick option request.
         * @param prompt Optional question to be asked of the user when the options are
         *     presented or null if nothing should be asked.
         * @param options The set of {@link Option}s the user is selecting from.
         * @param extras Additional optional information or null.
         * @deprecated Prefer the version that takes a {@link Prompt}.
         */
        public PickOptionRequest(CharSequence prompt, Option[] options, Bundle extras) {
            mPrompt = (prompt != null ? new Prompt(prompt) : null);
            mOptions = options;
            mExtras = extras;
        }

        /**
         * Called when a single option is confirmed or narrowed to one of several options.
         * @param finished True if the voice interaction has finished making a selection, in
@@ -451,17 +480,29 @@ public class VoiceInteractor {
     * interaction task.
     */
    public static class CompleteVoiceRequest extends Request {
        final CharSequence mMessage;
        final Prompt mPrompt;
        final Bundle mExtras;

        /**
         * Create a new completed voice interaction request.
         * @param prompt Optional message to speak to the user about the completion status of
         *     the task or null if nothing should be spoken.
         * @param extras Additional optional information or null.
         */
        public CompleteVoiceRequest(@Nullable Prompt prompt, @Nullable Bundle extras) {
            mPrompt = prompt;
            mExtras = extras;
        }

        /**
         * Create a new completed voice interaction request.
         * @param message Optional message to speak to the user about the completion status of
         *     the task or null if nothing should be spoken.
         * @param extras Additional optional information or null.
         * @deprecated Prefer the version that takes a {@link Prompt}.
         */
        public CompleteVoiceRequest(CharSequence message, Bundle extras) {
            mMessage = message;
            mPrompt = (message != null ? new Prompt(message) : null);
            mExtras = extras;
        }

@@ -470,7 +511,7 @@ public class VoiceInteractor {

        IVoiceInteractorRequest submit(IVoiceInteractor interactor, String packageName,
                IVoiceInteractorCallback callback) throws RemoteException {
            return interactor.startCompleteVoice(packageName, callback, mMessage, mExtras);
            return interactor.startCompleteVoice(packageName, callback, mPrompt, mExtras);
        }
    }

@@ -486,17 +527,29 @@ public class VoiceInteractor {
     * interaction task.
     */
    public static class AbortVoiceRequest extends Request {
        final CharSequence mMessage;
        final Prompt mPrompt;
        final Bundle mExtras;

        /**
         * Create a new voice abort request.
         * @param prompt Optional message to speak to the user indicating why the task could
         *     not be completed by voice or null if nothing should be spoken.
         * @param extras Additional optional information or null.
         */
        public AbortVoiceRequest(@Nullable Prompt prompt, @Nullable Bundle extras) {
            mPrompt = prompt;
            mExtras = extras;
        }

        /**
         * Create a new voice abort request.
         * @param message Optional message to speak to the user indicating why the task could
         *     not be completed by voice or null if nothing should be spoken.
         * @param extras Additional optional information or null.
         * @deprecated Prefer the version that takes a {@link Prompt}.
         */
        public AbortVoiceRequest(CharSequence message, Bundle extras) {
            mMessage = message;
            mPrompt = (message != null ? new Prompt(message) : null);
            mExtras = extras;
        }

@@ -505,7 +558,7 @@ public class VoiceInteractor {

        IVoiceInteractorRequest submit(IVoiceInteractor interactor, String packageName,
                IVoiceInteractorCallback callback) throws RemoteException {
            return interactor.startAbortVoice(packageName, callback, mMessage, mExtras);
            return interactor.startAbortVoice(packageName, callback, mPrompt, mExtras);
        }
    }

@@ -552,6 +605,100 @@ public class VoiceInteractor {
        }
    }

    /**
     * A set of voice prompts to use with the voice interaction system to confirm an action, select
     * an option, or do similar operations. Multiple voice prompts may be provided for variety. A
     * visual prompt must be provided, which might not match the spoken version. For example, the
     * confirmation "Are you sure you want to purchase this item?" might use a visual label like
     * "Purchase item".
     */
    public static class Prompt implements Parcelable {
        // Mandatory voice prompt. Must contain at least one item, which must not be null.
        private final CharSequence[] mVoicePrompts;

        // Mandatory visual prompt.
        private final CharSequence mVisualPrompt;

        /**
         * Constructs a prompt set.
         * @param voicePrompts An array of one or more voice prompts. Must not be empty or null.
         * @param visualPrompt A prompt to display on the screen. Must not be null.
         */
        public Prompt(@NonNull CharSequence[] voicePrompts, @NonNull CharSequence visualPrompt) {
            if (voicePrompts == null) {
                throw new NullPointerException("voicePrompts must not be null");
            }
            if (voicePrompts.length == 0) {
                throw new IllegalArgumentException("voicePrompts must not be empty");
            }
            if (visualPrompt == null) {
                throw new NullPointerException("visualPrompt must not be null");
            }
            this.mVoicePrompts = voicePrompts;
            this.mVisualPrompt = visualPrompt;
        }

        /**
         * Constructs a prompt set with single prompt used for all interactions. This is most useful
         * in test apps. Non-trivial apps should prefer the detailed constructor.
         */
        public Prompt(@NonNull CharSequence prompt) {
            this.mVoicePrompts = new CharSequence[] { prompt };
            this.mVisualPrompt = prompt;
        }

        /**
         * Returns a prompt to use for voice interactions.
         */
        @NonNull
        public CharSequence getVoicePromptAt(int index) {
            return mVoicePrompts[index];
        }

        /**
         * Returns the number of different voice prompts.
         */
        public int countVoicePrompts() {
            return mVoicePrompts.length;
        }

        /**
         * Returns the prompt to use for visual display.
         */
        @NonNull
        public CharSequence getVisualPrompt() {
            return mVisualPrompt;
        }

        /** Constructor to support Parcelable behavior. */
        Prompt(Parcel in) {
            mVoicePrompts = in.readCharSequenceArray();
            mVisualPrompt = in.readCharSequence();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeCharSequenceArray(mVoicePrompts);
            dest.writeCharSequence(mVisualPrompt);
        }

        public static final Creator<Prompt> CREATOR
                = new Creator<Prompt>() {
            public Prompt createFromParcel(Parcel in) {
                return new Prompt(in);
            }

            public Prompt[] newArray(int size) {
                return new Prompt[size];
            }
        };
    }

    VoiceInteractor(IVoiceInteractor interactor, Context context, Activity activity,
            Looper looper) {
        mInteractor = interactor;
@@ -631,7 +778,7 @@ public class VoiceInteractor {
    }

    /**
     * Queries the supported commands available from the VoiceinteractionService.
     * Queries the supported commands available from the VoiceInteractionService.
     * The command is a string that describes the generic operation to be performed.
     * An example might be "org.example.commands.PICK_DATE" to ask the user to pick
     * a date.  (Note: This is not an actual working example.)
+66 −19

File changed.

Preview size limit exceeded, changes collapsed.

Loading