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