Fix F/C in TTS settings
This is an attempt to fix uncaught MissingResourceException that would be thrown if default language of selected engine is set to a locale that has no 3-letter country/language code. Please see https://code.google.com/p/android/issues/detail?id=63122 Change-Id: Iccb2a55f5f7a97819310fd888559650fe7febe4a Signed-off-by: Shuhrat Dehkanov <k@efir.uz>
This commit is contained in:
@@ -46,6 +46,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
||||||
@@ -278,11 +279,11 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
if (mCurrentDefaultLocale == null || mAvailableStrLocals == null) {
|
if (mCurrentDefaultLocale == null || mAvailableStrLocals == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int defaultAvailable = mTts.setLanguage(mCurrentDefaultLocale);
|
|
||||||
|
|
||||||
|
boolean notInAvailableLangauges = true;
|
||||||
|
try {
|
||||||
// Check if language is listed in CheckVoices Action result as available voice.
|
// Check if language is listed in CheckVoices Action result as available voice.
|
||||||
String defaultLocaleStr = mCurrentDefaultLocale.getISO3Language();
|
String defaultLocaleStr = mCurrentDefaultLocale.getISO3Language();
|
||||||
boolean notInAvailableLangauges = true;
|
|
||||||
if (!TextUtils.isEmpty(mCurrentDefaultLocale.getISO3Country())) {
|
if (!TextUtils.isEmpty(mCurrentDefaultLocale.getISO3Country())) {
|
||||||
defaultLocaleStr += "-" + mCurrentDefaultLocale.getISO3Country();
|
defaultLocaleStr += "-" + mCurrentDefaultLocale.getISO3Country();
|
||||||
}
|
}
|
||||||
@@ -296,7 +297,14 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
if (DBG) Log.wtf(TAG, "MissingResourceException", e);
|
||||||
|
updateEngineStatus(R.string.tts_status_not_supported);
|
||||||
|
updateWidgetState(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int defaultAvailable = mTts.setLanguage(mCurrentDefaultLocale);
|
||||||
if (defaultAvailable == TextToSpeech.LANG_NOT_SUPPORTED ||
|
if (defaultAvailable == TextToSpeech.LANG_NOT_SUPPORTED ||
|
||||||
defaultAvailable == TextToSpeech.LANG_MISSING_DATA ||
|
defaultAvailable == TextToSpeech.LANG_MISSING_DATA ||
|
||||||
notInAvailableLangauges) {
|
notInAvailableLangauges) {
|
||||||
@@ -315,7 +323,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the current default engine to return a string of sample text to be
|
* Ask the current default engine to return a string of sample text to be
|
||||||
* spoken to the user.
|
* spoken to the user.
|
||||||
@@ -358,6 +365,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private String getDefaultSampleString() {
|
private String getDefaultSampleString() {
|
||||||
if (mTts != null && mTts.getLanguage() != null) {
|
if (mTts != null && mTts.getLanguage() != null) {
|
||||||
|
try {
|
||||||
final String currentLang = mTts.getLanguage().getISO3Language();
|
final String currentLang = mTts.getLanguage().getISO3Language();
|
||||||
String[] strings = getActivity().getResources().getStringArray(
|
String[] strings = getActivity().getResources().getStringArray(
|
||||||
R.array.tts_demo_strings);
|
R.array.tts_demo_strings);
|
||||||
@@ -369,6 +377,10 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
return strings[i];
|
return strings[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
if (DBG) Log.wtf(TAG, "MissingResourceException", e);
|
||||||
|
// Ignore and fall back to default sample string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getString(R.string.tts_default_sample_string);
|
return getString(R.string.tts_default_sample_string);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user