am 879f7bcf: Merge change 6272 into donut

Merge commit '879f7bcf41782940fff3ffcb3586d606361360c6'

* commit '879f7bcf41782940fff3ffcb3586d606361360c6':
  Fix bug 1946195 by making use of the current Locale to set a default value
This commit is contained in:
Android (Google) Code Review
2009-07-06 17:05:23 -07:00
committed by The Android Open Source Project
2 changed files with 45 additions and 36 deletions

View File

@@ -88,10 +88,10 @@
<!-- Do not translate. -->
<string-array name="tts_rate_values">
<item>60</item>
<item>80</item>
<item>100</item>
<item>140</item>
<item>180</item>
<item>220</item>
<item>150</item>
<item>200</item>
</string-array>
<!-- Default pitch choices -->

View File

@@ -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
@@ -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);
}
@@ -314,7 +302,7 @@ public class TextToSpeechSettings extends PreferenceActivity implements
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) {
@@ -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);
}
}