PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/paw/src/com/google/marvin/paw/RecoInvokerActivity.java

http://eyes-free.googlecode.com/
Java | 39 lines | 30 code | 7 blank | 2 comment | 2 complexity | 7815a460f3113c9a73d8f4d1730f841b MD5 | raw file
 1package com.google.marvin.paw;
 2
 3import java.util.ArrayList;
 4
 5import android.app.Activity;
 6import android.content.Intent;
 7import android.speech.RecognizerIntent;
 8import android.util.Log;
 9import android.widget.Toast;
10
11public class RecoInvokerActivity extends Activity {
12  @Override
13  protected void onResume() {
14    super.onResume();
15    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
16    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
17        RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
18    startActivityForResult(intent, 0);
19  }
20
21  @Override
22  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
23    if (resultCode != Activity.RESULT_OK) {
24      // Something went wrong, bail!
25      finish();
26      return;
27    }
28    ArrayList<String> results = data.getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
29
30    // TODO: make this take the reco result
31    Intent queryIntent = new Intent("com.google.marvin.paw.action.websearch");
32    queryIntent.putExtra("query", results.get(0));
33    sendBroadcast(queryIntent);
34
35    Toast.makeText(this, "Processing: " + results.get(0), 1).show();
36
37    finish();
38  }
39}