summaryrefslogtreecommitdiffstats
path: root/tests/VoiceInteraction
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
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')
-rw-r--r--tests/VoiceInteraction/res/layout/test_interaction.xml12
-rw-r--r--tests/VoiceInteraction/res/layout/voice_interaction_session.xml65
-rw-r--r--tests/VoiceInteraction/res/values/strings.xml5
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java57
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java27
5 files changed, 130 insertions, 36 deletions
diff --git a/tests/VoiceInteraction/res/layout/test_interaction.xml b/tests/VoiceInteraction/res/layout/test_interaction.xml
index 2abf651..4c0c67a 100644
--- a/tests/VoiceInteraction/res/layout/test_interaction.xml
+++ b/tests/VoiceInteraction/res/layout/test_interaction.xml
@@ -18,6 +18,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
+ android:padding="8dp"
>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
@@ -29,9 +30,16 @@
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
- android:layout_marginTop="10dp"
- android:textSize="12sp"
+ android:layout_marginTop="16dp"
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffffff"
/>
+ <Button android:id="@+id/abort"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:text="@string/abortVoice"
+ />
+
</LinearLayout>
diff --git a/tests/VoiceInteraction/res/layout/voice_interaction_session.xml b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml
index 563fa44..142d781 100644
--- a/tests/VoiceInteraction/res/layout/voice_interaction_session.xml
+++ b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml
@@ -14,26 +14,49 @@
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="#ffffffff"
- android:fitsSystemWindows="true"
- >
-
- <TextView android:id="@+id/text"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="32dp"
- />
-
- <Button android:id="@+id/start"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/start"
- />
-
-</LinearLayout>
-
-
+ android:fitsSystemWindows="true">
+
+ <FrameLayout android:layout_width="fill_parent"
+ android:layout_height="match_parent"
+ android:padding="8dp">
+
+ <LinearLayout android:id="@+id/content"
+ android:layout_width="fill_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:background="#ffffffff"
+ android:elevation="8dp"
+ >
+
+ <TextView android:id="@+id/text"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ />
+
+ <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <Button android:id="@+id/start"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/start"
+ />
+ <Button android:id="@+id/confirm"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/confirm"
+ />
+ <Button android:id="@+id/abort"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/abort"
+ />
+ </LinearLayout>
+
+ </LinearLayout>
+ </FrameLayout>
+</FrameLayout>
diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml
index 12edb31..70baa52 100644
--- a/tests/VoiceInteraction/res/values/strings.xml
+++ b/tests/VoiceInteraction/res/values/strings.xml
@@ -16,7 +16,10 @@
<resources>
- <string name="start">Start!</string>
+ <string name="start">Start</string>
+ <string name="confirm">Confirm</string>
+ <string name="abort">Abort</string>
+ <string name="abortVoice">Abort Voice</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 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();
}