summaryrefslogtreecommitdiffstats
path: root/tests/VoiceInteraction/src
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-05-30 16:42:57 -0700
committerDianne Hackborn <hackbod@google.com>2014-05-30 16:42:57 -0700
commita2c076d54048258cf88ab14551ce5fdf5a09c6e8 (patch)
treeced1ac6d335206c20489839c2d50b67405e1156c /tests/VoiceInteraction/src
parent8d07a14ee4cd47815ed42a86ce089c3de646658f (diff)
downloadframeworks_base-a2c076d54048258cf88ab14551ce5fdf5a09c6e8.zip
frameworks_base-a2c076d54048258cf88ab14551ce5fdf5a09c6e8.tar.gz
frameworks_base-a2c076d54048258cf88ab14551ce5fdf5a09c6e8.tar.bz2
Clean up voice API.
Add various java docs. Switch to CharSequence where appropriate. Add new request for canceling voice interaction. Also update test app to follow API changes and be more better. Change-Id: If27eeba53cf6444660adb7d37ea2ce0557c6c91f
Diffstat (limited to 'tests/VoiceInteraction/src')
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java57
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java27
2 files changed, 72 insertions, 12 deletions
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
index a3af284..c24a088 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
@@ -33,9 +33,17 @@ public class MainInteractionSession extends VoiceInteractionSession
View mContentView;
TextView mText;
Button mStartButton;
+ Button mConfirmButton;
+ Button mAbortButton;
+ 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;
+
+ int mState = STATE_IDLE;
Request mPendingRequest;
- boolean mPendingConfirm;
MainInteractionSession(Context context) {
super(context);
@@ -54,21 +62,39 @@ public class MainInteractionSession extends VoiceInteractionSession
mText = (TextView)mContentView.findViewById(R.id.text);
mStartButton = (Button)mContentView.findViewById(R.id.start);
mStartButton.setOnClickListener(this);
+ mConfirmButton = (Button)mContentView.findViewById(R.id.confirm);
+ mConfirmButton.setOnClickListener(this);
+ mAbortButton = (Button)mContentView.findViewById(R.id.abort);
+ mAbortButton.setOnClickListener(this);
+ updateState();
return mContentView;
}
+ void updateState() {
+ mStartButton.setEnabled(mState == STATE_IDLE);
+ mConfirmButton.setEnabled(mState == STATE_CONFIRM || mState == STATE_COMMAND);
+ mAbortButton.setEnabled(mState == STATE_ABORT_VOICE);
+ }
+
public void onClick(View v) {
- if (mPendingRequest == null) {
- mStartButton.setEnabled(false);
+ if (v == mStartButton) {
+ mState = STATE_LAUNCHING;
+ updateState();
startVoiceActivity(mStartIntent);
- } else {
- if (mPendingConfirm) {
+ } else if (v == mConfirmButton) {
+ if (mState == STATE_CONFIRM) {
mPendingRequest.sendConfirmResult(true, null);
} else {
mPendingRequest.sendCommandResult(true, null);
}
mPendingRequest = null;
- mStartButton.setText("Start");
+ mState = STATE_IDLE;
+ updateState();
+ } else if (v == mAbortButton) {
+ mPendingRequest.sendAbortVoiceResult(null);
+ mPendingRequest = null;
+ mState = STATE_IDLE;
+ updateState();
}
}
@@ -78,23 +104,32 @@ public class MainInteractionSession extends VoiceInteractionSession
}
@Override
- public void onConfirm(Caller caller, Request request, String prompt, Bundle extras) {
+ public void onConfirm(Caller caller, Request request, CharSequence prompt, Bundle extras) {
Log.i(TAG, "onConfirm: prompt=" + prompt + " extras=" + extras);
mText.setText(prompt);
- mStartButton.setEnabled(true);
mStartButton.setText("Confirm");
mPendingRequest = request;
- mPendingConfirm = true;
+ mState = STATE_CONFIRM;
+ updateState();
+ }
+
+ @Override
+ public void onAbortVoice(Caller caller, Request request, CharSequence message, Bundle extras) {
+ Log.i(TAG, "onAbortVoice: message=" + message + " extras=" + extras);
+ mText.setText(message);
+ mPendingRequest = request;
+ mState = STATE_ABORT_VOICE;
+ updateState();
}
@Override
public void onCommand(Caller caller, Request request, String command, Bundle extras) {
Log.i(TAG, "onCommand: command=" + command + " extras=" + extras);
mText.setText("Command: " + command);
- mStartButton.setEnabled(true);
mStartButton.setText("Finish Command");
mPendingRequest = request;
- mPendingConfirm = false;
+ mState = STATE_COMMAND;
+ updateState();
}
@Override
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
index a61e0da..3ae6a36 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
@@ -21,12 +21,15 @@ import android.app.VoiceInteractor;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
+import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
-public class TestInteractionActivity extends Activity {
+public class TestInteractionActivity extends Activity implements View.OnClickListener {
static final String TAG = "TestInteractionActivity";
VoiceInteractor mInteractor;
+ Button mAbortButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -39,6 +42,8 @@ public class TestInteractionActivity extends Activity {
}
setContentView(R.layout.test_interaction);
+ mAbortButton = (Button)findViewById(R.id.abort);
+ mAbortButton.setOnClickListener(this);
// Framework should take care of these.
getWindow().setGravity(Gravity.TOP);
@@ -69,6 +74,26 @@ public class TestInteractionActivity extends Activity {
}
@Override
+ public void onClick(View v) {
+ if (v == mAbortButton) {
+ VoiceInteractor.AbortVoiceRequest req = new VoiceInteractor.AbortVoiceRequest(
+ "Dammit, we suck :(", null) {
+ @Override
+ public void onCancel() {
+ Log.i(TAG, "Canceled!");
+ }
+
+ @Override
+ public void onAbortResult(Bundle result) {
+ Log.i(TAG, "Abort result: result=" + result);
+ getActivity().finish();
+ }
+ };
+ mInteractor.submitRequest(req);
+ }
+ }
+
+ @Override
public void onDestroy() {
super.onDestroy();
}