Settings for TextToSpeech now uses the results returned by the

engine's CheckVoiceData activity to determine which languages are
available and whether or not to make "Install Data" clickable.
This commit is contained in:
Charles Chen
2010-02-10 13:58:23 -08:00
parent 07c61c6dbb
commit c8298717bc

View File

@@ -38,6 +38,7 @@ import android.provider.Settings.SettingNotFoundException;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.util.Log; import android.util.Log;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@@ -84,6 +85,7 @@ public class TextToSpeechSettings extends PreferenceActivity implements
private int mDemoStringIndex = 0; private int mDemoStringIndex = 0;
private boolean mEnableDemo = false; private boolean mEnableDemo = false;
private boolean mVoicesMissing = false;
private TextToSpeech mTts = null; private TextToSpeech mTts = null;
@@ -278,16 +280,50 @@ public class TextToSpeechSettings extends PreferenceActivity implements
*/ */
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_DATA_INTEGRITY_CHECK) { if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { // TODO (clchen): Add these extras to TextToSpeech.Engine
Log.v(TAG, "Voice data check passed"); ArrayList<String> available =
data.getStringArrayListExtra("TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES");
ArrayList<String> unavailable =
data.getStringArrayListExtra("TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES");
if (available.size() > 0){
if (mTts == null) { if (mTts == null) {
mTts = new TextToSpeech(this, this); mTts = new TextToSpeech(this, this);
} }
} else { ListPreference ttsLanguagePref =
Log.v(TAG, "Voice data check failed"); (ListPreference) findPreference("tts_default_lang");
mEnableDemo = false; CharSequence[] entries = new CharSequence[available.size()];
updateWidgetState(); CharSequence[] entryValues = new CharSequence[available.size()];
for (int i=0; i<available.size(); i++){
String[] langCountryVariant = available.get(i).split("-");
Locale loc = null;
if (langCountryVariant.length == 1){
loc = new Locale(langCountryVariant[0]);
} else if (langCountryVariant.length == 2){
loc = new Locale(langCountryVariant[0], langCountryVariant[1]);
} else if (langCountryVariant.length == 3){
loc = new Locale(langCountryVariant[0], langCountryVariant[1],
langCountryVariant[2]);
} }
if (loc != null){
entries[i] = loc.getDisplayName();
entryValues[i] = available.get(i);
}
}
ttsLanguagePref.setEntries(entries);
ttsLanguagePref.setEntryValues(entryValues);
mEnableDemo = true;
} else {
mEnableDemo = false;
}
if (unavailable.size() > 0){
mVoicesMissing = true;
} else {
mVoicesMissing = false;
}
updateWidgetState();
} else if (requestCode == GET_SAMPLE_TEXT) { } else if (requestCode == GET_SAMPLE_TEXT) {
if (resultCode == TextToSpeech.LANG_AVAILABLE) { if (resultCode == TextToSpeech.LANG_AVAILABLE) {
if (mTts != null) { if (mTts != null) {
@@ -377,7 +413,7 @@ public class TextToSpeechSettings extends PreferenceActivity implements
mDefaultRatePref.setEnabled(mEnableDemo); mDefaultRatePref.setEnabled(mEnableDemo);
mDefaultLocPref.setEnabled(mEnableDemo); mDefaultLocPref.setEnabled(mEnableDemo);
mInstallData.setEnabled(!mEnableDemo); mInstallData.setEnabled(mVoicesMissing);
} }