Created
April 25, 2014 12:40
-
-
Save TomTasche/20ff4802c1002c381f6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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