diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-05-02 10:45:59 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2014-05-05 11:18:08 -0700 |
commit | c03c9167c2d9a1e22fb2b176b00a0524177fb037 (patch) | |
tree | bc8045725f3384dff1c53a508041fa63f78e5ce8 /tests | |
parent | 6b003c9e3c0d3e5e31d9578e6d15facc6553e45e (diff) | |
download | frameworks_base-c03c9167c2d9a1e22fb2b176b00a0524177fb037.zip frameworks_base-c03c9167c2d9a1e22fb2b176b00a0524177fb037.tar.gz frameworks_base-c03c9167c2d9a1e22fb2b176b00a0524177fb037.tar.bz2 |
Further work on voice interaction services.
This makes VoiceInteractionSession a more first-class
concept. Now the flow is that a VoiceInteractionService
calls startSession() when it wants to begin a session.
This will result in a new VoiceInteractionSession via the
VoiceInteractionSessionService containing it, and the
session at that point an decide what to do. It can now
show UI, and it is what has access to the startVoiceActivity
API.
Change-Id: Ie2b85b3020ef1206d3f44b335b128d064e8f9935
Diffstat (limited to 'tests')
4 files changed, 99 insertions, 9 deletions
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..9fcbf3e --- /dev/null +++ b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml @@ -0,0 +1,38 @@ +<?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="fill_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:background="#ffffffff" + > + + <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> + + diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java index 008d97b..d40b05f 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java @@ -17,6 +17,7 @@ package com.android.test.voiceinteraction; import android.content.Intent; +import android.os.Bundle; import android.service.voice.VoiceInteractionService; import android.util.Log; @@ -31,7 +32,9 @@ public class MainInteractionService extends VoiceInteractionService { @Override public int onStartCommand(Intent intent, int flags, int startId) { - startVoiceActivity(new Intent(this, TestInteractionActivity.class), null); + Bundle args = new Bundle(); + args.putParcelable("intent", new Intent(this, TestInteractionActivity.class)); + startSession(args); 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 index 0fc563b..a3af284 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java @@ -17,18 +17,59 @@ 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 { +public class MainInteractionSession extends VoiceInteractionSession + implements View.OnClickListener { static final String TAG = "MainInteractionSession"; - final Bundle mArgs; + Intent mStartIntent; + View mContentView; + TextView mText; + Button mStartButton; - MainInteractionSession(Context context, Bundle args) { + Request mPendingRequest; + boolean mPendingConfirm; + + MainInteractionSession(Context context) { super(context); - mArgs = args; + } + + @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); + return mContentView; + } + + public void onClick(View v) { + if (mPendingRequest == null) { + mStartButton.setEnabled(false); + startVoiceActivity(mStartIntent); + } else { + if (mPendingConfirm) { + mPendingRequest.sendConfirmResult(true, null); + } else { + mPendingRequest.sendCommandResult(true, null); + } + mPendingRequest = null; + mStartButton.setText("Start"); + } } @Override @@ -38,14 +79,22 @@ public class MainInteractionSession extends VoiceInteractionSession { @Override public void onConfirm(Caller caller, Request request, String prompt, Bundle extras) { - Log.i(TAG, "onConform: prompt=" + prompt + " extras=" + extras); - request.sendConfirmResult(true, null); + Log.i(TAG, "onConfirm: prompt=" + prompt + " extras=" + extras); + mText.setText(prompt); + mStartButton.setEnabled(true); + mStartButton.setText("Confirm"); + mPendingRequest = request; + mPendingConfirm = true; } @Override public void onCommand(Caller caller, Request request, String command, Bundle extras) { Log.i(TAG, "onCommand: command=" + command + " extras=" + extras); - request.sendCommandResult(true, null); + mText.setText("Command: " + command); + mStartButton.setEnabled(true); + mStartButton.setText("Finish Command"); + mPendingRequest = request; + mPendingConfirm = false; } @Override diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java index 8864d71..7cf8178 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java @@ -23,6 +23,6 @@ import android.service.voice.VoiceInteractionSessionService; public class MainInteractionSessionService extends VoiceInteractionSessionService { @Override public VoiceInteractionSession onNewSession(Bundle args) { - return new MainInteractionSession(this, args); + return new MainInteractionSession(this); } } |