diff options
author | Narayan Kamath <narayan@google.com> | 2012-01-05 15:14:04 +0000 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2012-01-05 15:14:04 +0000 |
commit | 5a38df2648f5e8246d20a46675bd99cc5ea368e0 (patch) | |
tree | 9e0e5fbc04c084612eaf2269d840ad26accf9727 /src/com/android/settings/tts | |
parent | c9ac3ca0f198d62e16591e7867210251a853c0d1 (diff) | |
download | packages_apps_Settings-5a38df2648f5e8246d20a46675bd99cc5ea368e0.zip packages_apps_Settings-5a38df2648f5e8246d20a46675bd99cc5ea368e0.tar.gz packages_apps_Settings-5a38df2648f5e8246d20a46675bd99cc5ea368e0.tar.bz2 |
Call setLanguage() when the TTS locale is changed in settings.
This is required to fix the case where an app has instantiated
and is using a TextToSpeech instance, and the user switches to
settings and changes the language for that instance. If no
app was using TTS, then onCreate() would have be called when
TTS is used next, and the correct locale will be loaded.
bug:5823836
Change-Id: I62adf3f7f0f14b67450ba08b8743e0d31e615a7e
Diffstat (limited to 'src/com/android/settings/tts')
-rw-r--r-- | src/com/android/settings/tts/TextToSpeechSettings.java | 18 | ||||
-rw-r--r-- | src/com/android/settings/tts/TtsEngineSettingsFragment.java | 44 |
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); } |