Fix for setting TTS language to recently downloaded one

If user added new voice pack, then set it as a default language,
went level back and went to TTS settings again, it ended in crash.

This is because first updateVoiceDetails uses old voice data details
that settings retreived long time ago.

locales preference is hidden until TTs engine returns list of locales.

Change-Id: I33a81ff259c69adb4c051ee693b6c41b93f302d0
This commit is contained in:
Przemyslaw Szczepaniak
2012-08-13 16:56:02 +01:00
committed by Android (Google) Code Review
parent 1c7d15e841
commit ccd80ec95f
2 changed files with 14 additions and 12 deletions

View File

@@ -19,16 +19,19 @@
android:key="tts_default_lang" android:key="tts_default_lang"
android:title="@string/tts_default_lang_title" android:title="@string/tts_default_lang_title"
android:summary="@string/tts_default_lang_summary" android:summary="@string/tts_default_lang_summary"
android:persistent="false" /> android:persistent="false"
android:order="100" />
<Preference <Preference
android:key="tts_engine_settings" android:key="tts_engine_settings"
android:persistent="false" android:persistent="false"
android:title="@string/tts_engine_settings_title" /> android:title="@string/tts_engine_settings_title"
android:order="200" />
<Preference <Preference
android:key="tts_install_data" android:key="tts_install_data"
android:persistent="false" android:persistent="false"
android:title="@string/tts_install_data_title" android:title="@string/tts_install_data_title"
android:summary="@string/tts_install_data_summary" /> android:summary="@string/tts_install_data_summary"
android:order="300" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -104,7 +104,8 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
mInstallVoicesPreference.setOnPreferenceClickListener(this); mInstallVoicesPreference.setOnPreferenceClickListener(this);
// Remove this preference unless voices are indeed available to install. // Remove this preference unless voices are indeed available to install.
root.removePreference(mInstallVoicesPreference); root.removePreference(mInstallVoicesPreference);
// Remove this preference unless locales are indeed available.
root.removePreference(mLocalePreference);
root.setTitle(getEngineLabel()); root.setTitle(getEngineLabel());
root.setKey(getEngineName()); root.setKey(getEngineName());
@@ -121,8 +122,6 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
mVoiceDataDetails = getArguments().getParcelable(TtsEnginePreference.FRAGMENT_ARGS_VOICES); mVoiceDataDetails = getArguments().getParcelable(TtsEnginePreference.FRAGMENT_ARGS_VOICES);
updateVoiceDetails();
mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener, mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener,
getEngineName()); getEngineName());
@@ -169,9 +168,8 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
if (available == null){ if (available == null){
Log.e(TAG, "TTS data check failed (available == null)."); Log.e(TAG, "TTS data check failed (available == null).");
final CharSequence[] empty = new CharSequence[0]; mLocalePreference.setEnabled(false);
mLocalePreference.setEntries(empty); getPreferenceScreen().removePreference(mLocalePreference);
mLocalePreference.setEntryValues(empty);
return; return;
} }
@@ -183,11 +181,12 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
} }
if (available.size() > 0) { if (available.size() > 0) {
mLocalePreference.setEnabled(true);
getPreferenceScreen().addPreference(mLocalePreference);
updateDefaultLocalePref(available); updateDefaultLocalePref(available);
} else { } else {
final CharSequence[] empty = new CharSequence[0]; mLocalePreference.setEnabled(false);
mLocalePreference.setEntries(empty); getPreferenceScreen().removePreference(mLocalePreference);
mLocalePreference.setEntryValues(empty);
} }
} }