1/* This file is auto-generated from SearchActivity.java.  DO NOT MODIFY. */
2
3/*
4 * Copyright (C) 2014 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software distributed under the License
12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.example.android.leanback;
17
18import android.support.v4.app.FragmentActivity;
19import android.content.Intent;
20import android.os.Bundle;
21import android.support.v17.leanback.app.SearchSupportFragment;
22import android.support.v17.leanback.widget.SpeechRecognitionCallback;
23import android.util.Log;
24
25public class SearchSupportActivity extends FragmentActivity
26{
27    private static final String TAG = "SearchSupportActivity";
28    private static boolean DEBUG = true;
29
30    /** If using internal speech recognizer, you must have RECORD_AUDIO permission */
31    private static boolean USE_INTERNAL_SPEECH_RECOGNIZER = true;
32    private static final int REQUEST_SPEECH = 1;
33
34    private SearchSupportFragment mFragment;
35    private SpeechRecognitionCallback mSpeechRecognitionCallback;
36
37    /** Called when the activity is first created. */
38    @Override
39    public void onCreate(Bundle savedInstanceState)
40    {
41        super.onCreate(savedInstanceState);
42        setContentView(R.layout.search_support);
43
44        mFragment = (SearchSupportFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment);
45
46        if (!USE_INTERNAL_SPEECH_RECOGNIZER) {
47            mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
48                @Override
49                public void recognizeSpeech() {
50                    if (DEBUG) Log.v(TAG, "recognizeSpeech");
51                    startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
52                }
53            };
54            mFragment.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
55        }
56    }
57
58    @Override
59    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
60        if (DEBUG) Log.v(TAG, "onActivityResult requestCode=" + requestCode +
61                " resultCode=" + resultCode +
62                " data=" + data);
63        if (requestCode == REQUEST_SPEECH && resultCode == RESULT_OK) {
64            mFragment.setSearchQuery(data, true);
65        }
66    }
67
68}
69