diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-04-04 18:02:06 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2014-04-24 17:48:58 -0700 |
commit | 91097de49b0f683b00e26a75dbc0ac6082344137 (patch) | |
tree | 82c3185634a71233ce2e81a3645b07b1ba55f412 /tests/VoiceInteraction | |
parent | 23af77a3cd1febc740d885ff03ead09837df269c (diff) | |
download | frameworks_base-91097de49b0f683b00e26a75dbc0ac6082344137.zip frameworks_base-91097de49b0f683b00e26a75dbc0ac6082344137.tar.gz frameworks_base-91097de49b0f683b00e26a75dbc0ac6082344137.tar.bz2 |
Initial implementation of new voice interaction API.
This gives a basic working implementation of a persist
running service that can start a voice interaction when
it wants, with the target activity(s) able to go through
the protocol to interact with it. It may even work when
the screen is off by putting the activity manager in the
correct state to act like the screen is on.
Includes a sample app that is a voice interation service
and also has an activity it can launch.
Now that I have this initial implementation, I think I
want to rework some aspects of the API.
Change-Id: I7646d0af8fb4ac768c63a18fe3de43f8091f60e9
Diffstat (limited to 'tests/VoiceInteraction')
9 files changed, 334 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..9c5acf9 --- /dev/null +++ b/tests/VoiceInteraction/AndroidManifest.xml @@ -0,0 +1,27 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.test.voiceinteraction"> + + <application> + <activity android:name="VoiceInteractionMain" android:label="Voice Interaction"> + <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> + <service android:name="MainInteractionService" + android:permission="android.permission.BIND_VOICE_INTERACTION" + android:process=":interactor"> + <intent-filter> + <action android:name="android.service.voice.VoiceInteractionService" /> + </intent-filter> + </service> + <activity android:name="TestInteractionActivity" android:label="Voice Interaction Target"> + <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/test_interaction.xml b/tests/VoiceInteraction/res/layout/test_interaction.xml new file mode 100644 index 0000000..2abf651 --- /dev/null +++ b/tests/VoiceInteraction/res/layout/test_interaction.xml @@ -0,0 +1,37 @@ +<?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" + > + + <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="10dp" + android:textSize="12sp" + android:textColor="#ffffffff" + /> + +</LinearLayout> diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml new file mode 100644 index 0000000..12edb31 --- /dev/null +++ b/tests/VoiceInteraction/res/values/strings.xml @@ -0,0 +1,22 @@ +<?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> + +</resources> + 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..35702f1 --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java @@ -0,0 +1,39 @@ +/* + * 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.service.voice.VoiceInteractionService; +import android.util.Log; + +public class MainInteractionService extends VoiceInteractionService { + static final String TAG = "MainInteractionService"; + + @Override + public void onCreate() { + super.onCreate(); + Log.i(TAG, "Creating " + this); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + startVoiceActivity(new Intent(this, TestInteractionActivity.class), + new MainInteractionSession(this)); + stopSelf(startId); + return START_NOT_STICKY; + } +} 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..adc0df4 --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java @@ -0,0 +1,53 @@ +/* + * 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.os.Bundle; +import android.service.voice.VoiceInteractionSession; +import android.util.Log; + +public class MainInteractionSession extends VoiceInteractionSession { + static final String TAG = "MainInteractionSession"; + + MainInteractionSession(Context context) { + super(context); + } + + @Override + public boolean[] onGetSupportedCommands(Caller caller, String[] commands) { + return new boolean[commands.length]; + } + + @Override + public void onConfirm(Caller caller, Request request, String prompt, Bundle extras) { + Log.i(TAG, "onConform: prompt=" + prompt + " extras=" + extras); + request.sendConfirmResult(true, null); + } + + @Override + public void onCommand(Caller caller, Request request, String command, Bundle extras) { + Log.i(TAG, "onCommand: command=" + command + " extras=" + extras); + request.sendCommandResult(null); + } + + @Override + public void onCancel(Request request) { + Log.i(TAG, "onCancel"); + request.sendCancelResult(); + } +} 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..016a80e --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java @@ -0,0 +1,66 @@ +/* + * 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; + +public class TestInteractionActivity extends Activity { + static final String TAG = "TestInteractionActivity"; + + VoiceInteractor mInteractor; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.test_interaction); + if (!isVoiceInteraction()) { + Log.w(TAG, "Not running as a voice interaction!"); + finish(); + return; + } + + mInteractor = getVoiceInteractor(); + mInteractor.startConfirmation(new VoiceInteractor.Callback() { + @Override + public void onConfirmationResult(VoiceInteractor.Request request, boolean confirmed, + Bundle result) { + Log.i(TAG, "Confirmation result: confirmed=" + confirmed + " result=" + result); + finish(); + } + + @Override + public void onCancel(VoiceInteractor.Request request) { + Log.i(TAG, "Canceled!"); + finish(); + } + }, "This is a confirmation", null); + } + + @Override + public void onResume() { + super.onResume(); + } + + @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)); + } + }; +} |