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
This commit is contained in:
Narayan Kamath
2012-01-05 15:14:04 +00:00
parent c9ac3ca0f1
commit 5a38df2648
2 changed files with 40 additions and 22 deletions

View File

@@ -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