diff options
Diffstat (limited to 'tests/VoiceInteraction')
16 files changed, 856 insertions, 0 deletions
diff --git a/tests/VoiceInteraction/Android.mk b/tests/VoiceInteraction/Android.mk new file mode 100644 index 0000000..8decca7 --- /dev/null +++ b/tests/VoiceInteraction/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := VoiceInteraction + +include $(BUILD_PACKAGE) diff --git a/tests/VoiceInteraction/AndroidManifest.xml b/tests/VoiceInteraction/AndroidManifest.xml new file mode 100644 index 0000000..06d31a4 --- /dev/null +++ b/tests/VoiceInteraction/AndroidManifest.xml @@ -0,0 +1,55 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.test.voiceinteraction"> + + <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" /> + + <application> + <activity android:name="VoiceInteractionMain" android:label="Voice Interaction" + android:theme="@android:style/Theme.Material"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity android:name="SettingsActivity" + android:label="Voice Interaction Settings" + android:excludeFromRecents="true" + android:noHistory="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity> + <service android:name="MainInteractionService" + android:label="Test Voice Interaction Service" + android:permission="android.permission.BIND_VOICE_INTERACTION" + android:process=":interactor"> + <meta-data android:name="android.voice_interaction" + android:resource="@xml/interaction_service" /> + <intent-filter> + <action android:name="android.service.voice.VoiceInteractionService" /> + </intent-filter> + </service> + <service android:name="MainInteractionSessionService" + android:permission="android.permission.BIND_VOICE_INTERACTION" + android:process=":session"> + </service> + <service android:name="MainRecognitionService" + android:label="Test Voice Interaction Service"> + <intent-filter> + <action android:name="android.speech.RecognitionService" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + <meta-data android:name="android.speech" android:resource="@xml/recognition_service" /> + </service> + <activity android:name="TestInteractionActivity" android:label="Voice Interaction Target" + android:theme="@android:style/Theme.Material.Light.Voice"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.VOICE" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/tests/VoiceInteraction/res/layout/main.xml b/tests/VoiceInteraction/res/layout/main.xml new file mode 100644 index 0000000..3d7a418 --- /dev/null +++ b/tests/VoiceInteraction/res/layout/main.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + > + + <Button android:id="@+id/start" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/start" + /> + +</LinearLayout> + + diff --git a/tests/VoiceInteraction/res/layout/settings.xml b/tests/VoiceInteraction/res/layout/settings.xml new file mode 100644 index 0000000..e123449 --- /dev/null +++ b/tests/VoiceInteraction/res/layout/settings.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceMedium" + android:text="Preferences placeholder" /> diff --git a/tests/VoiceInteraction/res/layout/test_interaction.xml b/tests/VoiceInteraction/res/layout/test_interaction.xml new file mode 100644 index 0000000..d55736f --- /dev/null +++ b/tests/VoiceInteraction/res/layout/test_interaction.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + 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" + android:textAppearance="?android:attr/textAppearanceMedium" + android:text="We are interacting!" + /> + + <TextView android:id="@+id/log" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1" + android:layout_marginTop="16dp" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textColor="#ffffffff" + /> + + <Button android:id="@+id/complete" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:text="@string/completeVoice" + /> + + <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 new file mode 100644 index 0000000..002f350 --- /dev/null +++ b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="match_parent" + 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/complete" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/complete" + /> + <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 new file mode 100644 index 0000000..7eec90c --- /dev/null +++ b/tests/VoiceInteraction/res/values/strings.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<resources> + + <string name="start">Start</string> + <string name="confirm">Confirm</string> + <string name="abort">Abort</string> + <string name="complete">Complete</string> + <string name="abortVoice">Abort Voice</string> + <string name="completeVoice">Complete Voice</string> + +</resources> + diff --git a/tests/VoiceInteraction/res/xml/interaction_service.xml b/tests/VoiceInteraction/res/xml/interaction_service.xml new file mode 100644 index 0000000..ce5669c --- /dev/null +++ b/tests/VoiceInteraction/res/xml/interaction_service.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright (c) 2014, 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. + */ +--> + +<voice-interaction-service xmlns:android="http://schemas.android.com/apk/res/android" + android:sessionService="com.android.test.voiceinteraction.MainInteractionSessionService" + android:recognitionService="com.android.test.voiceinteraction.MainRecognitionService" + android:settingsActivity="com.android.test.voiceinteraction.SettingsActivity" /> diff --git a/tests/VoiceInteraction/res/xml/recognition_service.xml b/tests/VoiceInteraction/res/xml/recognition_service.xml new file mode 100644 index 0000000..b720fc4 --- /dev/null +++ b/tests/VoiceInteraction/res/xml/recognition_service.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright (c) 2014, 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. + */ +--> + +<recognition-service xmlns:android="http://schemas.android.com/apk/res/android" + android:settingsActivity="com.android.test.voiceinteraction.SettingsActivity" /> diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java new file mode 100644 index 0000000..4639114 --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.content.Intent; +import android.os.Bundle; +import android.service.voice.AlwaysOnHotwordDetector; +import android.service.voice.AlwaysOnHotwordDetector.Callback; +import android.service.voice.AlwaysOnHotwordDetector.EventPayload; +import android.service.voice.VoiceInteractionService; +import android.util.Log; + +import java.util.Arrays; +import java.util.Locale; + +public class MainInteractionService extends VoiceInteractionService { + static final String TAG = "MainInteractionService"; + + private final Callback mHotwordCallback = new Callback() { + @Override + public void onAvailabilityChanged(int status) { + Log.i(TAG, "onAvailabilityChanged(" + status + ")"); + hotwordAvailabilityChangeHelper(status); + } + + @Override + public void onDetected(EventPayload eventPayload) { + Log.i(TAG, "onDetected"); + } + + @Override + public void onError() { + Log.i(TAG, "onError"); + } + + @Override + public void onRecognitionPaused() { + Log.i(TAG, "onRecognitionPaused"); + } + + @Override + public void onRecognitionResumed() { + Log.i(TAG, "onRecognitionResumed"); + } + }; + + private AlwaysOnHotwordDetector mHotwordDetector; + + @Override + public void onReady() { + super.onReady(); + Log.i(TAG, "Creating " + this); + Log.i(TAG, "Keyphrase enrollment error? " + getKeyphraseEnrollmentInfo().getParseError()); + Log.i(TAG, "Keyphrase enrollment meta-data: " + + Arrays.toString(getKeyphraseEnrollmentInfo().listKeyphraseMetadata())); + + mHotwordDetector = createAlwaysOnHotwordDetector( + "Hello There", Locale.forLanguageTag("en-US"), mHotwordCallback); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Bundle args = new Bundle(); + args.putParcelable("intent", new Intent(this, TestInteractionActivity.class)); + startSession(args); + stopSelf(startId); + return START_NOT_STICKY; + } + + private void hotwordAvailabilityChangeHelper(int availability) { + Log.i(TAG, "Hotword availability = " + availability); + switch (availability) { + case AlwaysOnHotwordDetector.STATE_HARDWARE_UNAVAILABLE: + Log.i(TAG, "STATE_HARDWARE_UNAVAILABLE"); + break; + case AlwaysOnHotwordDetector.STATE_KEYPHRASE_UNSUPPORTED: + Log.i(TAG, "STATE_KEYPHRASE_UNSUPPORTED"); + break; + case AlwaysOnHotwordDetector.STATE_KEYPHRASE_UNENROLLED: + Log.i(TAG, "STATE_KEYPHRASE_UNENROLLED"); + Intent enroll = mHotwordDetector.createEnrollIntent(); + Log.i(TAG, "Need to enroll with " + enroll); + break; + case AlwaysOnHotwordDetector.STATE_KEYPHRASE_ENROLLED: + Log.i(TAG, "STATE_KEYPHRASE_ENROLLED - starting recognition"); + if (mHotwordDetector.startRecognition( + AlwaysOnHotwordDetector.RECOGNITION_FLAG_NONE)) { + Log.i(TAG, "startRecognition succeeded"); + } else { + Log.i(TAG, "startRecognition failed"); + } + break; + } + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java new file mode 100644 index 0000000..d20906e --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.service.voice.VoiceInteractionSession; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +public class MainInteractionSession extends VoiceInteractionSession + implements View.OnClickListener { + static final String TAG = "MainInteractionSession"; + + Intent mStartIntent; + View mContentView; + TextView mText; + Button mStartButton; + Button mConfirmButton; + Button mCompleteButton; + 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; + static final int STATE_COMPLETE_VOICE = 5; + + int mState = STATE_IDLE; + Request mPendingRequest; + + MainInteractionSession(Context context) { + super(context); + } + + @Override + public void onCreate(Bundle args) { + super.onCreate(args); + showWindow(); + mStartIntent = args.getParcelable("intent"); + } + + @Override + public View onCreateContentView() { + mContentView = getLayoutInflater().inflate(R.layout.voice_interaction_session, null); + 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); + mCompleteButton = (Button)mContentView.findViewById(R.id.complete); + mCompleteButton.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); + mCompleteButton.setEnabled(mState == STATE_COMPLETE_VOICE); + } + + public void onClick(View v) { + if (v == mStartButton) { + mState = STATE_LAUNCHING; + updateState(); + startVoiceActivity(mStartIntent); + } else if (v == mConfirmButton) { + if (mState == STATE_CONFIRM) { + mPendingRequest.sendConfirmResult(true, null); + } else { + mPendingRequest.sendCommandResult(true, null); + } + mPendingRequest = null; + mState = STATE_IDLE; + updateState(); + } else if (v == mAbortButton) { + mPendingRequest.sendAbortVoiceResult(null); + mPendingRequest = null; + mState = STATE_IDLE; + updateState(); + } else if (v== mCompleteButton) { + mPendingRequest.sendCompleteVoiceResult(null); + mPendingRequest = null; + mState = STATE_IDLE; + updateState(); + } + } + + @Override + public boolean[] onGetSupportedCommands(Caller caller, String[] commands) { + return new boolean[commands.length]; + } + + @Override + 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"); + mPendingRequest = request; + mState = STATE_CONFIRM; + updateState(); + } + + @Override + public void onCompleteVoice(Caller caller, Request request, CharSequence message, Bundle extras) { + Log.i(TAG, "onCompleteVoice: message=" + message + " extras=" + extras); + mText.setText(message); + mPendingRequest = request; + mState = STATE_COMPLETE_VOICE; + 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.setText("Finish Command"); + mPendingRequest = request; + mState = STATE_COMMAND; + updateState(); + } + + @Override + public void onCancel(Request request) { + Log.i(TAG, "onCancel"); + request.sendCancelResult(); + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java new file mode 100644 index 0000000..7cf8178 --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.os.Bundle; +import android.service.voice.VoiceInteractionSession; +import android.service.voice.VoiceInteractionSessionService; + +public class MainInteractionSessionService extends VoiceInteractionSessionService { + @Override + public VoiceInteractionSession onNewSession(Bundle args) { + return new MainInteractionSession(this); + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainRecognitionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainRecognitionService.java new file mode 100644 index 0000000..c716e7a --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainRecognitionService.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.content.Intent; +import android.speech.RecognitionService; +import android.util.Log; + +/** + * Stub recognition service needed to be a complete voice interactor. + */ +public class MainRecognitionService extends RecognitionService { + + private static final String TAG = "MainRecognitionService"; + + @Override + public void onCreate() { + super.onCreate(); + Log.i(TAG, "onCreate"); + } + + @Override + protected void onStartListening(Intent recognizerIntent, Callback listener) { + Log.d(TAG, "onStartListening"); + } + + @Override + protected void onCancel(Callback listener) { + Log.d(TAG, "onCancel"); + } + + @Override + protected void onStopListening(Callback listener) { + Log.d(TAG, "onStopListening"); + } + + @Override + public void onDestroy() { + super.onDestroy(); + Log.d(TAG, "onDestroy"); + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/SettingsActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/SettingsActivity.java new file mode 100644 index 0000000..8b346ff --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/SettingsActivity.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.app.Activity; +import android.os.Bundle; + +/** + * Stub activity to test out settings selection for voice interactor. + */ +public class SettingsActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.settings); + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java new file mode 100644 index 0000000..d64eefa --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.app.Activity; +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 implements View.OnClickListener { + static final String TAG = "TestInteractionActivity"; + + VoiceInteractor mInteractor; + Button mAbortButton; + Button mCompleteButton; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (!isVoiceInteraction()) { + Log.w(TAG, "Not running as a voice interaction!"); + finish(); + return; + } + + setContentView(R.layout.test_interaction); + mAbortButton = (Button)findViewById(R.id.abort); + mAbortButton.setOnClickListener(this); + mCompleteButton = (Button)findViewById(R.id.complete); + mCompleteButton.setOnClickListener(this); + + // Framework should take care of these. + getWindow().setGravity(Gravity.TOP); + getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + + mInteractor = getVoiceInteractor(); + VoiceInteractor.ConfirmationRequest req = new VoiceInteractor.ConfirmationRequest( + "This is a confirmation", null) { + @Override + public void onCancel() { + Log.i(TAG, "Canceled!"); + getActivity().finish(); + } + + @Override + public void onConfirmationResult(boolean confirmed, Bundle result) { + Log.i(TAG, "Confirmation result: confirmed=" + confirmed + " result=" + result); + getActivity().finish(); + } + }; + mInteractor.submitRequest(req); + } + + @Override + public void onResume() { + super.onResume(); + } + + @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); + } else if (v == mCompleteButton) { + VoiceInteractor.CompleteVoiceRequest req = new VoiceInteractor.CompleteVoiceRequest( + "Woohoo, completed!", null) { + @Override + public void onCancel() { + Log.i(TAG, "Canceled!"); + } + + @Override + public void onCompleteResult(Bundle result) { + Log.i(TAG, "Complete result: result=" + result); + getActivity().finish(); + } + }; + mInteractor.submitRequest(req); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/VoiceInteractionMain.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/VoiceInteractionMain.java new file mode 100644 index 0000000..5d212a4 --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/VoiceInteractionMain.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +public class VoiceInteractionMain extends Activity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.main); + findViewById(R.id.start).setOnClickListener(mStartListener); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + View.OnClickListener mStartListener = new View.OnClickListener() { + public void onClick(View v) { + startService(new Intent(VoiceInteractionMain.this, MainInteractionService.class)); + } + }; +} |