summaryrefslogtreecommitdiffstats
path: root/tests/VoiceInteraction
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-03-13 18:02:54 -0700
committerDianne Hackborn <hackbod@google.com>2015-03-16 11:29:12 -0700
commit3d07c94c393831091958fe6a98811843db8973bd (patch)
tree0cd5c4ea3dc580772b28ef76e9b5b76fe23de081 /tests/VoiceInteraction
parent872d191e6134b429f833013b8706c7b54ebd0d2a (diff)
downloadframeworks_base-3d07c94c393831091958fe6a98811843db8973bd.zip
frameworks_base-3d07c94c393831091958fe6a98811843db8973bd.tar.gz
frameworks_base-3d07c94c393831091958fe6a98811843db8973bd.tar.bz2
Add new voice request for picking from a list.
Also add API for voice interaction service to control whether the system should hold a wake lock while it is working with an activity (and actually *do* hold a wake lock while doing so, duh!). And while in there, clean up the launching wake lock to correctly give blame to the app that is launching. Change-Id: I7cc4d566b80f59fe0a9ac51ae9bbb7188a01f433
Diffstat (limited to 'tests/VoiceInteraction')
-rw-r--r--tests/VoiceInteraction/res/layout/test_interaction.xml7
-rw-r--r--tests/VoiceInteraction/res/values/strings.xml2
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java73
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java49
4 files changed, 121 insertions, 10 deletions
diff --git a/tests/VoiceInteraction/res/layout/test_interaction.xml b/tests/VoiceInteraction/res/layout/test_interaction.xml
index f4648b5..8c8151d 100644
--- a/tests/VoiceInteraction/res/layout/test_interaction.xml
+++ b/tests/VoiceInteraction/res/layout/test_interaction.xml
@@ -41,6 +41,13 @@
android:text="@string/completeVoice"
/>
+ <Button android:id="@+id/pick"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:text="@string/pickVoice"
+ />
+
<Button android:id="@+id/abort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml
index 9f99c97..5331457 100644
--- a/tests/VoiceInteraction/res/values/strings.xml
+++ b/tests/VoiceInteraction/res/values/strings.xml
@@ -22,7 +22,7 @@
<string name="complete">Complete</string>
<string name="abortVoice">Abort Voice</string>
<string name="completeVoice">Complete Voice</string>
+ <string name="pickVoice">Pick Voice</string>
<string name="cancelVoice">Cancel</string>
</resources>
-
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
index bcfc6f4..ad339be 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
@@ -18,6 +18,7 @@ package com.android.test.voiceinteraction;
import android.app.AssistContent;
import android.app.AssistStructure;
+import android.app.VoiceInteractor;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -47,12 +48,15 @@ public class MainInteractionSession extends VoiceInteractionSession
static final int STATE_IDLE = 0;
static final int STATE_LAUNCHING = 1;
static final int STATE_CONFIRM = 2;
- static final int STATE_COMMAND = 3;
- static final int STATE_ABORT_VOICE = 4;
- static final int STATE_COMPLETE_VOICE = 5;
- static final int STATE_DONE=6;
+ static final int STATE_PICK_OPTION = 3;
+ static final int STATE_COMMAND = 4;
+ static final int STATE_ABORT_VOICE = 5;
+ static final int STATE_COMPLETE_VOICE = 6;
+ static final int STATE_DONE=7;
int mState = STATE_IDLE;
+ VoiceInteractor.PickOptionRequest.Option[] mPendingOptions;
+ CharSequence mPendingPrompt;
Request mPendingRequest;
MainInteractionSession(Context context) {
@@ -154,7 +158,8 @@ public class MainInteractionSession extends VoiceInteractionSession
mAssistVisualizer.setVisibility(View.GONE);
}
mStartButton.setEnabled(mState == STATE_IDLE);
- mConfirmButton.setEnabled(mState == STATE_CONFIRM || mState == STATE_COMMAND);
+ mConfirmButton.setEnabled(mState == STATE_CONFIRM || mState == STATE_PICK_OPTION
+ || mState == STATE_COMMAND);
mAbortButton.setEnabled(mState == STATE_ABORT_VOICE);
mCompleteButton.setEnabled(mState == STATE_COMPLETE_VOICE);
}
@@ -167,10 +172,32 @@ public class MainInteractionSession extends VoiceInteractionSession
} else if (v == mConfirmButton) {
if (mState == STATE_CONFIRM) {
mPendingRequest.sendConfirmResult(true, null);
- } else {
+ mPendingRequest = null;
+ mState = STATE_LAUNCHING;
+ } else if (mState == STATE_PICK_OPTION) {
+ int numReturn = mPendingOptions.length/2;
+ if (numReturn <= 0) {
+ numReturn = 1;
+ }
+ VoiceInteractor.PickOptionRequest.Option[] picked
+ = new VoiceInteractor.PickOptionRequest.Option[numReturn];
+ for (int i=0; i<picked.length; i++) {
+ picked[i] = mPendingOptions[i*2];
+ }
+ mPendingOptions = picked;
+ if (picked.length <= 1) {
+ mPendingRequest.sendPickOptionResult(true, picked, null);
+ mPendingRequest = null;
+ mState = STATE_LAUNCHING;
+ } else {
+ mPendingRequest.sendPickOptionResult(false, picked, null);
+ updatePickText();
+ }
+ } else if (mPendingRequest != null) {
mPendingRequest.sendCommandResult(true, null);
+ mPendingRequest = null;
+ mState = STATE_LAUNCHING;
}
- mPendingRequest = null;
} else if (v == mAbortButton) {
mPendingRequest.sendAbortVoiceResult(null);
mPendingRequest = null;
@@ -178,6 +205,7 @@ public class MainInteractionSession extends VoiceInteractionSession
mPendingRequest.sendCompleteVoiceResult(null);
mPendingRequest = null;
}
+ updateState();
}
@Override
@@ -198,13 +226,40 @@ public class MainInteractionSession extends VoiceInteractionSession
public void onConfirm(Caller caller, Request request, CharSequence prompt, Bundle extras) {
Log.i(TAG, "onConfirm: prompt=" + prompt + " extras=" + extras);
mText.setText(prompt);
- mStartButton.setText("Confirm");
+ mConfirmButton.setText("Confirm");
mPendingRequest = request;
+ mPendingPrompt = prompt;
mState = STATE_CONFIRM;
updateState();
}
@Override
+ public void onPickOption(Caller caller, Request request, CharSequence prompt,
+ VoiceInteractor.PickOptionRequest.Option[] options, Bundle extras) {
+ Log.i(TAG, "onPickOption: prompt=" + prompt + " options=" + options + " extras=" + extras);
+ mConfirmButton.setText("Pick Option");
+ mPendingRequest = request;
+ mPendingPrompt = prompt;
+ mPendingOptions = options;
+ mState = STATE_PICK_OPTION;
+ updatePickText();
+ updateState();
+ }
+
+ void updatePickText() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(mPendingPrompt);
+ sb.append(": ");
+ for (int i=0; i<mPendingOptions.length; i++) {
+ if (i > 0) {
+ sb.append(", ");
+ }
+ sb.append(mPendingOptions[i].getLabel());
+ }
+ mText.setText(sb.toString());
+ }
+
+ @Override
public void onCompleteVoice(Caller caller, Request request, CharSequence message, Bundle extras) {
Log.i(TAG, "onCompleteVoice: message=" + message + " extras=" + extras);
mText.setText(message);
@@ -226,7 +281,7 @@ public class MainInteractionSession extends VoiceInteractionSession
public void onCommand(Caller caller, Request request, String command, Bundle extras) {
Log.i(TAG, "onCommand: command=" + command + " extras=" + extras);
mText.setText("Command: " + command);
- mStartButton.setText("Finish Command");
+ mConfirmButton.setText("Finish Command");
mPendingRequest = request;
mState = STATE_COMMAND;
updateState();
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
index 023e0ec..e195c30 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
@@ -26,14 +26,17 @@ import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.TextView;
public class TestInteractionActivity extends Activity implements View.OnClickListener {
static final String TAG = "TestInteractionActivity";
VoiceInteractor mInteractor;
VoiceInteractor.Request mCurrentRequest = null;
+ TextView mLog;
Button mAbortButton;
Button mCompleteButton;
+ Button mPickButton;
Button mCancelButton;
@Override
@@ -54,10 +57,13 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
}
setContentView(R.layout.test_interaction);
+ mLog = (TextView)findViewById(R.id.log);
mAbortButton = (Button)findViewById(R.id.abort);
mAbortButton.setOnClickListener(this);
mCompleteButton = (Button)findViewById(R.id.complete);
mCompleteButton.setOnClickListener(this);
+ mPickButton = (Button)findViewById(R.id.pick);
+ mPickButton.setOnClickListener(this);
mCancelButton = (Button)findViewById(R.id.cancel);
mCancelButton.setOnClickListener(this);
@@ -92,11 +98,13 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
@Override
public void onCancel() {
Log.i(TAG, "Canceled!");
+ mLog.append("Canceled abort\n");
}
@Override
public void onAbortResult(Bundle result) {
Log.i(TAG, "Abort result: result=" + result);
+ mLog.append("Abort: result=" + result + "\n");
getActivity().finish();
}
};
@@ -107,15 +115,56 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
@Override
public void onCancel() {
Log.i(TAG, "Canceled!");
+ mLog.append("Canceled complete\n");
}
@Override
public void onCompleteResult(Bundle result) {
Log.i(TAG, "Complete result: result=" + result);
+ mLog.append("Complete: result=" + result + "\n");
getActivity().finish();
}
};
mInteractor.submitRequest(req);
+ } else if (v == mPickButton) {
+ VoiceInteractor.PickOptionRequest.Option[] options =
+ new VoiceInteractor.PickOptionRequest.Option[5];
+ options[0] = new VoiceInteractor.PickOptionRequest.Option("One");
+ options[1] = new VoiceInteractor.PickOptionRequest.Option("Two");
+ options[2] = new VoiceInteractor.PickOptionRequest.Option("Three");
+ options[3] = new VoiceInteractor.PickOptionRequest.Option("Four");
+ options[4] = new VoiceInteractor.PickOptionRequest.Option("Five");
+ VoiceInteractor.PickOptionRequest req = new VoiceInteractor.PickOptionRequest(
+ "Need to pick something", options, null) {
+ @Override
+ public void onCancel() {
+ Log.i(TAG, "Canceled!");
+ mLog.append("Canceled pick\n");
+ }
+
+ @Override
+ public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) {
+ Log.i(TAG, "Pick result: finished=" + finished + " selections=" + selections
+ + " result=" + result);
+ StringBuilder sb = new StringBuilder();
+ if (finished) {
+ sb.append("Pick final result: ");
+ } else {
+ sb.append("Pick intermediate result: ");
+ }
+ for (int i=0; i<selections.length; i++) {
+ if (i >= 1) {
+ sb.append(", ");
+ }
+ sb.append(selections[i].getLabel());
+ }
+ mLog.append(sb.toString());
+ if (finished) {
+ getActivity().finish();
+ }
+ }
+ };
+ mInteractor.submitRequest(req);
} else if (v == mCancelButton && mCurrentRequest != null) {
Log.i(TAG, "Cancel request");
mCurrentRequest.cancel();