summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/tts
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/tts')
-rw-r--r--src/com/android/settings/tts/TextToSpeechSettings.java18
-rw-r--r--src/com/android/settings/tts/TtsEngineSettingsFragment.java44
2 files changed, 40 insertions, 22 deletions
diff --git a/src/com/android/settings/tts/TextToSpeechSettings.java b/src/com/android/settings/tts/TextToSpeechSettings.java
index 517eade..fbcdb4f 100644
--- a/src/com/android/settings/tts/TextToSpeechSettings.java
+++ b/src/com/android/settings/tts/TextToSpeechSettings.java
@@ -192,23 +192,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
checkVoiceData(mCurrentEngine);
}
- private void maybeUpdateTtsLanguage(String currentEngine) {
- if (currentEngine != null && mTts != null) {
- final String localeString = mEnginesHelper.getLocalePrefForEngine(
- currentEngine);
- if (localeString != null) {
- final String[] locale = TtsEngines.parseLocalePref(localeString);
- final Locale newLocale = new Locale(locale[0], locale[1], locale[2]);
- final Locale engineLocale = mTts.getLanguage();
-
- if (!newLocale.equals(engineLocale)) {
- if (DBG) Log.d(TAG, "Loading language ahead of sample check : " + locale);
- mTts.setLanguage(newLocale);
- }
- }
- }
- }
-
/**
* Ask the current default engine to return a string of sample text to be
* spoken to the user.
@@ -218,7 +201,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
if (TextUtils.isEmpty(currentEngine)) currentEngine = mTts.getDefaultEngine();
- maybeUpdateTtsLanguage(currentEngine);
Locale currentLocale = mTts.getLanguage();
// TODO: This is currently a hidden private API. The intent extras
diff --git a/src/com/android/settings/tts/TtsEngineSettingsFragment.java b/src/com/android/settings/tts/TtsEngineSettingsFragment.java
index 3f740d7..4bbc13c 100644
--- a/src/com/android/settings/tts/TtsEngineSettingsFragment.java
+++ b/src/com/android/settings/tts/TtsEngineSettingsFragment.java
@@ -51,6 +51,25 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
private Preference mInstallVoicesPreference;
private Intent mEngineSettingsIntent;
+ private TextToSpeech mTts;
+
+ private final TextToSpeech.OnInitListener mTtsInitListener = new TextToSpeech.OnInitListener() {
+ @Override
+ public void onInit(int status) {
+ if (status != TextToSpeech.SUCCESS) {
+ finishFragment();
+ } else {
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mLocalePreference.setEnabled(true);
+ updateVoiceDetails();
+ }
+ });
+ }
+ }
+ };
+
public TtsEngineSettingsFragment() {
super();
}
@@ -83,7 +102,15 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
}
mInstallVoicesPreference.setEnabled(false);
- updateVoiceDetails();
+ mLocalePreference.setEnabled(false);
+ mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener,
+ getEngineName());
+ }
+
+ @Override
+ public void onDestroy() {
+ mTts.shutdown();
+ super.onDestroy();
}
private void updateVoiceDetails() {
@@ -153,8 +180,7 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
mLocalePreference.setValueIndex(selectedLanguageIndex);
} else {
mLocalePreference.setValueIndex(0);
- mEnginesHelper.updateLocalePrefForEngine(getEngineName(),
- availableLangs.get(0));
+ updateLanguageTo(availableLangs.get(0));
}
}
@@ -191,13 +217,23 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mLocalePreference) {
- mEnginesHelper.updateLocalePrefForEngine(getEngineName(), (String) newValue);
+ updateLanguageTo((String) newValue);
return true;
}
return false;
}
+ private void updateLanguageTo(String locale) {
+ mEnginesHelper.updateLocalePrefForEngine(getEngineName(), locale);
+ if (getEngineName().equals(mTts.getCurrentEngine())) {
+ String[] localeArray = TtsEngines.parseLocalePref(locale);
+ if (localeArray != null) {
+ mTts.setLanguage(new Locale(localeArray[0], localeArray[1], localeArray[2]));
+ }
+ }
+ }
+
private String getEngineName() {
return getArguments().getString(TtsEnginePreference.FRAGMENT_ARGS_NAME);
}