• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
17 package com.example.android.leanback;
18 
19 import android.support.v4.app.FragmentActivity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.support.v17.leanback.app.SearchSupportFragment;
23 import android.support.v17.leanback.widget.SpeechRecognitionCallback;
24 import android.util.Log;
25 
26 public class SearchSupportActivity extends FragmentActivity
27 {
28     private static final String TAG = "SearchSupportActivity";
29     private static boolean DEBUG = true;
30 
31     /** If using internal speech recognizer, you must have RECORD_AUDIO permission */
32     private static final boolean USE_INTERNAL_SPEECH_RECOGNIZER = true;
33     private static final int REQUEST_SPEECH = 1;
34 
35     private SearchSupportFragment mFragment;
36     private SpeechRecognitionCallback mSpeechRecognitionCallback;
37 
38     /** Called when the activity is first created. */
39     @Override
onCreate(Bundle savedInstanceState)40     public void onCreate(Bundle savedInstanceState)
41     {
42         super.onCreate(savedInstanceState);
43         setContentView(R.layout.search_support);
44 
45         mFragment = (SearchSupportFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment);
46 
47         if (!USE_INTERNAL_SPEECH_RECOGNIZER) {
48             mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
49                 @Override
50                 public void recognizeSpeech() {
51                     if (DEBUG) Log.v(TAG, "recognizeSpeech");
52                     startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
53                 }
54             };
55             mFragment.setSpeechRecognitionCallback(mSpeechRecognitionCallback);
56         }
57     }
58 
59     @Override
onActivityResult(int requestCode, int resultCode, Intent data)60     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
61         if (DEBUG) Log.v(TAG, "onActivityResult requestCode=" + requestCode +
62                 " resultCode=" + resultCode +
63                 " data=" + data);
64         if (requestCode == REQUEST_SPEECH && resultCode == RESULT_OK) {
65             mFragment.setSearchQuery(data, true);
66         }
67     }
68 
69 }
70