Commits

Przemyslaw Szczepaniak  committed 6829c48 Merge

Merge "Fix F/C in TTS settings"

  • Participants
  • Parent commits c776bbb, f365216

Comments (0)

Files changed (1)

File src/com/android/settings/tts/TextToSpeechSettings.java

 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.MissingResourceException;
 import java.util.Set;
 
 public class TextToSpeechSettings extends SettingsPreferenceFragment implements
         if (mCurrentDefaultLocale == null || mAvailableStrLocals == null) {
             return false;
         }
-        int defaultAvailable = mTts.setLanguage(mCurrentDefaultLocale);
 
-        // Check if language is listed in CheckVoices Action result as available voice.
-        String defaultLocaleStr = mCurrentDefaultLocale.getISO3Language();
         boolean notInAvailableLangauges = true;
-        if (!TextUtils.isEmpty(mCurrentDefaultLocale.getISO3Country())) {
-            defaultLocaleStr += "-" + mCurrentDefaultLocale.getISO3Country();
-        }
-        if (!TextUtils.isEmpty(mCurrentDefaultLocale.getVariant())) {
-            defaultLocaleStr += "-" + mCurrentDefaultLocale.getVariant();
-        }
+        try {
+            // Check if language is listed in CheckVoices Action result as available voice.
+            String defaultLocaleStr = mCurrentDefaultLocale.getISO3Language();
+            if (!TextUtils.isEmpty(mCurrentDefaultLocale.getISO3Country())) {
+                defaultLocaleStr += "-" + mCurrentDefaultLocale.getISO3Country();
+            }
+            if (!TextUtils.isEmpty(mCurrentDefaultLocale.getVariant())) {
+                defaultLocaleStr += "-" + mCurrentDefaultLocale.getVariant();
+            }
 
-        for (String loc : mAvailableStrLocals) {
-            if (loc.equalsIgnoreCase(defaultLocaleStr)) {
-              notInAvailableLangauges = false;
-              break;
+            for (String loc : mAvailableStrLocals) {
+                if (loc.equalsIgnoreCase(defaultLocaleStr)) {
+                  notInAvailableLangauges = false;
+                  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 ||
                 defaultAvailable == TextToSpeech.LANG_MISSING_DATA ||
                 notInAvailableLangauges) {
         }
     }
 
-
     /**
      * Ask the current default engine to return a string of sample text to be
      * spoken to the user.
 
     private String getDefaultSampleString() {
         if (mTts != null && mTts.getLanguage() != null) {
-            final String currentLang = mTts.getLanguage().getISO3Language();
-            String[] strings = getActivity().getResources().getStringArray(
-                    R.array.tts_demo_strings);
-            String[] langs = getActivity().getResources().getStringArray(
-                    R.array.tts_demo_string_langs);
-
-            for (int i = 0; i < strings.length; ++i) {
-                if (langs[i].equals(currentLang)) {
-                    return strings[i];
+            try {
+                final String currentLang = mTts.getLanguage().getISO3Language();
+                String[] strings = getActivity().getResources().getStringArray(
+                        R.array.tts_demo_strings);
+                String[] langs = getActivity().getResources().getStringArray(
+                        R.array.tts_demo_string_langs);
+
+                for (int i = 0; i < strings.length; ++i) {
+                    if (langs[i].equals(currentLang)) {
+                        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);