From 44fbbea071611f33fb8004b5684f5e342763d278 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Mon, 6 Jul 2009 14:04:54 -0700 Subject: Fix bug 1946195 by making use of the current Locale to set a default value in the language pref list (bug was no selection in the default language list). Fix half of bug 1956707 where speech rate value as read from the settings was translated to a ratio, which applied an improper speech rate on the TTS engine (bug was setting a default rate makes the TTS demo unintelligible). Moved logic to set the default value in the language pref list in a separate private method to improve readability. Changed default rate values so that normal is 1x and the fastest is 2x. --- src/com/android/settings/TextToSpeechSettings.java | 75 ++++++++++++---------- 1 file changed, 42 insertions(+), 33 deletions(-) (limited to 'src/com') diff --git a/src/com/android/settings/TextToSpeechSettings.java b/src/com/android/settings/TextToSpeechSettings.java index ec0fc8c..11998a3 100644 --- a/src/com/android/settings/TextToSpeechSettings.java +++ b/src/com/android/settings/TextToSpeechSettings.java @@ -39,6 +39,7 @@ import android.speech.tts.TextToSpeech; import android.util.Log; import java.util.List; +import java.util.Locale; import java.util.StringTokenizer; public class TextToSpeechSettings extends PreferenceActivity implements @@ -95,14 +96,14 @@ public class TextToSpeechSettings extends PreferenceActivity implements initClickers(); initDefaultSettings(); } - - + + @Override protected void onStart() { super.onStart(); // whenever we return to this screen, we don't know the state of the // system, so we have to recheck that we can play the demo, or it must be disabled. - // TODO make the TTS service listen to "changes in the system", i.e. sd card un/mount + // TODO make the TTS service listen to "changes in the system", i.e. sd card un/mount initClickers(); updateWidgetState(); checkVoiceData(); @@ -174,23 +175,21 @@ public class TextToSpeechSettings extends PreferenceActivity implements String variant = null; mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG); language = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG); - if (language != null) { - mDefaultLanguage = language; - } else { - // default language setting not found, initialize it, as well as the country and variant - language = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_LANG; - country = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY; - variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT; + if (language == null) { + // the default language property isn't set, use that of the current locale + Locale currentLocale = Locale.getDefault(); + language = currentLocale.getISO3Language(); + country = currentLocale.getISO3Country(); + variant = currentLocale.getVariant(); Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, language); Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country); Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant); } + mDefaultLanguage = language; if (country == null) { // country wasn't initialized yet because a default language was found country = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_COUNTRY); - if (country != null) { - mDefaultCountry = country; - } else { + if (country == null) { // default country setting not found, initialize it, as well as the variant; country = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY; variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT; @@ -198,30 +197,19 @@ public class TextToSpeechSettings extends PreferenceActivity implements Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant); } } + mDefaultCountry = country; if (variant == null) { // variant wasn't initialized yet because a default country was found variant = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_VARIANT); - if (variant != null) { - mDefaultLocVariant = variant; - } else { + if (variant == null) { // default variant setting not found, initialize it variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT; Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant); } } - // we now have the default lang/country/variant trio, build a string value from it - String localeString = new String(language); - if (country.compareTo("") != 0) { - localeString += LOCALE_DELIMITER + country; - } else { - localeString += LOCALE_DELIMITER + " "; - } - if (variant.compareTo("") != 0) { - localeString += LOCALE_DELIMITER + variant; - } - Log.v(TAG, "In initDefaultSettings: localeString=" + localeString); - // TODO handle the case where localeString isn't in the existing entries - mDefaultLocPref.setValue(localeString); + mDefaultLocVariant = variant; + + setDefaultLocalePref(language, country, variant); mDefaultLocPref.setOnPreferenceChangeListener(this); } @@ -311,10 +299,10 @@ public class TextToSpeechSettings extends PreferenceActivity implements // Default rate int value = Integer.parseInt((String) objValue); try { - Settings.Secure.putInt(getContentResolver(), + Settings.Secure.putInt(getContentResolver(), TTS_DEFAULT_RATE, value); if (mTts != null) { - mTts.setSpeechRate(value); + mTts.setSpeechRate((float)(value/100.0f)); } Log.i(TAG, "TTS default rate is "+value); } catch (NumberFormatException e) { @@ -330,10 +318,10 @@ public class TextToSpeechSettings extends PreferenceActivity implements Log.v(TAG, "TTS default lang/country/variant set to " + mDefaultLanguage + "/" + mDefaultCountry + "/" + mDefaultLocVariant); } - + return true; } - + /** * Called when mPlayExample or mInstallData is clicked @@ -384,4 +372,25 @@ public class TextToSpeechSettings extends PreferenceActivity implements } + private void setDefaultLocalePref(String language, String country, String variant) { + // build a string from the default lang/country/variant trio, + String localeString = new String(language); + if (country.compareTo("") != 0) { + localeString += LOCALE_DELIMITER + country; + } else { + localeString += LOCALE_DELIMITER + " "; + } + if (variant.compareTo("") != 0) { + localeString += LOCALE_DELIMITER + variant; + } + + if (mDefaultLocPref.findIndexOfValue(localeString) > -1) { + mDefaultLocPref.setValue(localeString); + } else { + mDefaultLocPref.setValueIndex(0); + } + + Log.v(TAG, "In initDefaultSettings: localeString=" + localeString); + } + } -- cgit v1.1