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:
committed by
The Android Open Source Project
commit
6b0cdd4e1f
@@ -88,10 +88,10 @@
|
|||||||
<!-- Do not translate. -->
|
<!-- Do not translate. -->
|
||||||
<string-array name="tts_rate_values">
|
<string-array name="tts_rate_values">
|
||||||
<item>60</item>
|
<item>60</item>
|
||||||
|
<item>80</item>
|
||||||
<item>100</item>
|
<item>100</item>
|
||||||
<item>140</item>
|
<item>150</item>
|
||||||
<item>180</item>
|
<item>200</item>
|
||||||
<item>220</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<!-- Default pitch choices -->
|
<!-- Default pitch choices -->
|
||||||
|
@@ -39,6 +39,7 @@ import android.speech.tts.TextToSpeech;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
public class TextToSpeechSettings extends PreferenceActivity implements
|
public class TextToSpeechSettings extends PreferenceActivity implements
|
||||||
@@ -95,14 +96,14 @@ public class TextToSpeechSettings extends PreferenceActivity implements
|
|||||||
initClickers();
|
initClickers();
|
||||||
initDefaultSettings();
|
initDefaultSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
// whenever we return to this screen, we don't know the state of the
|
// 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.
|
// 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();
|
initClickers();
|
||||||
updateWidgetState();
|
updateWidgetState();
|
||||||
checkVoiceData();
|
checkVoiceData();
|
||||||
@@ -174,23 +175,21 @@ public class TextToSpeechSettings extends PreferenceActivity implements
|
|||||||
String variant = null;
|
String variant = null;
|
||||||
mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
|
mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
|
||||||
language = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG);
|
language = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG);
|
||||||
if (language != null) {
|
if (language == null) {
|
||||||
mDefaultLanguage = language;
|
// the default language property isn't set, use that of the current locale
|
||||||
} else {
|
Locale currentLocale = Locale.getDefault();
|
||||||
// default language setting not found, initialize it, as well as the country and variant
|
language = currentLocale.getISO3Language();
|
||||||
language = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_LANG;
|
country = currentLocale.getISO3Country();
|
||||||
country = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY;
|
variant = currentLocale.getVariant();
|
||||||
variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT;
|
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, language);
|
Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, language);
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country);
|
Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, country);
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
|
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
|
||||||
}
|
}
|
||||||
|
mDefaultLanguage = language;
|
||||||
if (country == null) {
|
if (country == null) {
|
||||||
// country wasn't initialized yet because a default language was found
|
// country wasn't initialized yet because a default language was found
|
||||||
country = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_COUNTRY);
|
country = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_COUNTRY);
|
||||||
if (country != null) {
|
if (country == null) {
|
||||||
mDefaultCountry = country;
|
|
||||||
} else {
|
|
||||||
// default country setting not found, initialize it, as well as the variant;
|
// default country setting not found, initialize it, as well as the variant;
|
||||||
country = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY;
|
country = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY;
|
||||||
variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT;
|
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);
|
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mDefaultCountry = country;
|
||||||
if (variant == null) {
|
if (variant == null) {
|
||||||
// variant wasn't initialized yet because a default country was found
|
// variant wasn't initialized yet because a default country was found
|
||||||
variant = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_VARIANT);
|
variant = Settings.Secure.getString(resolver, KEY_TTS_DEFAULT_VARIANT);
|
||||||
if (variant != null) {
|
if (variant == null) {
|
||||||
mDefaultLocVariant = variant;
|
|
||||||
} else {
|
|
||||||
// default variant setting not found, initialize it
|
// default variant setting not found, initialize it
|
||||||
variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT;
|
variant = TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT;
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
|
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, variant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we now have the default lang/country/variant trio, build a string value from it
|
mDefaultLocVariant = variant;
|
||||||
String localeString = new String(language);
|
|
||||||
if (country.compareTo("") != 0) {
|
setDefaultLocalePref(language, country, variant);
|
||||||
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);
|
|
||||||
mDefaultLocPref.setOnPreferenceChangeListener(this);
|
mDefaultLocPref.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,10 +299,10 @@ public class TextToSpeechSettings extends PreferenceActivity implements
|
|||||||
// Default rate
|
// Default rate
|
||||||
int value = Integer.parseInt((String) objValue);
|
int value = Integer.parseInt((String) objValue);
|
||||||
try {
|
try {
|
||||||
Settings.Secure.putInt(getContentResolver(),
|
Settings.Secure.putInt(getContentResolver(),
|
||||||
TTS_DEFAULT_RATE, value);
|
TTS_DEFAULT_RATE, value);
|
||||||
if (mTts != null) {
|
if (mTts != null) {
|
||||||
mTts.setSpeechRate(value);
|
mTts.setSpeechRate((float)(value/100.0f));
|
||||||
}
|
}
|
||||||
Log.i(TAG, "TTS default rate is "+value);
|
Log.i(TAG, "TTS default rate is "+value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@@ -330,10 +318,10 @@ public class TextToSpeechSettings extends PreferenceActivity implements
|
|||||||
Log.v(TAG, "TTS default lang/country/variant set to "
|
Log.v(TAG, "TTS default lang/country/variant set to "
|
||||||
+ mDefaultLanguage + "/" + mDefaultCountry + "/" + mDefaultLocVariant);
|
+ mDefaultLanguage + "/" + mDefaultCountry + "/" + mDefaultLocVariant);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when mPlayExample or mInstallData is clicked
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user