Skip to content

Instantly share code, notes, and snippets.

@TomTasche
Created April 25, 2014 12:40
Show Gist options
  • Save TomTasche/20ff4802c1002c381f6f to your computer and use it in GitHub Desktop.
Save TomTasche/20ff4802c1002c381f6f to your computer and use it in GitHub Desktop.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_navigate: {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getResources().getString(R.string.voice_prompt_zones));
startActivityForResult(intent, SPEECH_REQUEST_CODE);
break;
}
default: {
return super.onOptionsItemSelected(item);
}
}
return true;
}
private void parseVoiceResults(Intent voiceResultIntent) {
if (voiceResultIntent != null && voiceResultIntent.getExtras() != null) {
lastVoiceResults = voiceResultIntent.getExtras().getStringArrayList(
RecognizerIntent.EXTRA_RESULTS);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
parseVoiceResults(data);
findZone();
}
super.onActivityResult(requestCode, resultCode, data);
}
private void findZone() {
if (lastVoiceResults == null || lastVoiceResults.isEmpty()) {
return;
}
List<Zone> zones = getZones();
if (zones == null) {
return;
}
for (Zone zone : zones) {
if (lastVoiceResults.contains(zone.getName().toLowerCase())) {
// TODO: do something
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment