TestInteractionActivity.java revision 18f0d357f9693fe787a3e3777d8fdf01357a6e3f
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.test.voiceinteraction;
18
19import android.app.Activity;
20import android.app.VoiceInteractor;
21import android.os.Bundle;
22import android.util.Log;
23
24public class TestInteractionActivity extends Activity {
25    static final String TAG = "TestInteractionActivity";
26
27    VoiceInteractor mInteractor;
28
29    @Override
30    public void onCreate(Bundle savedInstanceState) {
31        super.onCreate(savedInstanceState);
32
33        if (!isVoiceInteraction()) {
34            Log.w(TAG, "Not running as a voice interaction!");
35            finish();
36            return;
37        }
38
39        setContentView(R.layout.test_interaction);
40
41        mInteractor = getVoiceInteractor();
42        VoiceInteractor.ConfirmationRequest req = new VoiceInteractor.ConfirmationRequest(
43                "This is a confirmation", null) {
44            @Override
45            public void onCancel() {
46                Log.i(TAG, "Canceled!");
47                getActivity().finish();
48            }
49
50            @Override
51            public void onConfirmationResult(boolean confirmed, Bundle result) {
52                Log.i(TAG, "Confirmation result: confirmed=" + confirmed + " result=" + result);
53                getActivity().finish();
54            }
55        };
56        mInteractor.submitRequest(req);
57    }
58
59    @Override
60    public void onResume() {
61        super.onResume();
62    }
63
64    @Override
65    public void onDestroy() {
66        super.onDestroy();
67    }
68}
69