OSDN Git Service

Fixing bugs 2577511 and 2581920.
authorCharles Chen <clchen@google.com>
Thu, 8 Apr 2010 23:51:35 +0000 (16:51 -0700)
committerCharles Chen <clchen@google.com>
Thu, 8 Apr 2010 23:51:35 +0000 (16:51 -0700)
Making sure that the language, country, and variant defaults are always
set to something to ensure that there won't be an NPE.
Dismissing the ListPreference dialogs before a rotation to avoid list
data corruption caused by the list being displayed while its data is
being re-initialized.

Change-Id: Iecdb3b4d415542dc8a4db162c930e6a6570a55f2

res/values/arrays.xml
res/xml/tts_settings.xml
src/com/android/settings/TextToSpeechSettings.java

index ed80892..0ae8eb4 100644 (file)
         <item>Questo è un esempio di sintesi vocale in italiano.</item>
         <item>Este es un ejemplo de síntesis de voz en español.</item>
     </string-array>
+    <!-- Do not translate. -->
+    <string-array name="tts_engine_entries">
+        <item>Pico TTS</item>
+    </string-array>
+    <!-- Do not translate. -->
+    <string-array name="tts_engine_values">
+        <item>com.svox.pico</item>
+    </string-array>
+
 
     <!-- Wi-Fi settings -->
 
index 8974cfe..c378f64 100644 (file)
@@ -35,7 +35,9 @@
                 android:key="tts_default_synth"
                 android:title="@string/tts_default_synth_title"
                 android:summary="@string/tts_default_synth_summary"
-                android:persistent="false" />
+                android:persistent="false"
+                android:entries="@array/tts_engine_entries"
+                android:entryValues="@array/tts_engine_values" />
 
             <Preference
                 android:key="tts_install_data"
index d6e11d7..8b30a5a 100644 (file)
@@ -123,6 +123,11 @@ public class TextToSpeechSettings extends PreferenceActivity implements
         mEnableDemo = false;
         mTtsStarted = false;
 
+        Locale currentLocale = Locale.getDefault();
+        mDefaultLanguage = currentLocale.getISO3Language();
+        mDefaultCountry = currentLocale.getISO3Country();
+        mDefaultLocVariant = currentLocale.getVariant();
+
         mTts = new TextToSpeech(this, this);
     }
 
@@ -149,6 +154,21 @@ public class TextToSpeechSettings extends PreferenceActivity implements
         }
     }
 
+    @Override
+    protected void onPause() {
+        super.onPause();
+        if ((mDefaultRatePref != null) && (mDefaultRatePref.getDialog() != null)) {
+            mDefaultRatePref.getDialog().dismiss();
+        }
+        if ((mDefaultLocPref != null) && (mDefaultLocPref.getDialog() != null)) {
+            mDefaultLocPref.getDialog().dismiss();
+        }
+        if ((mDefaultSynthPref != null) && (mDefaultSynthPref.getDialog() != null)) {
+            mDefaultSynthPref.getDialog().dismiss();
+        }
+    }
+
+
 
     private void addEngineSpecificSettings() {
         PreferenceGroup enginesCategory = (PreferenceGroup) findPreference("tts_engines_section");
@@ -673,7 +693,7 @@ public class TextToSpeechSettings extends PreferenceActivity implements
 
 
     private void loadEngines() {
-        ListPreference enginesPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
+        mDefaultSynthPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
 
         // TODO (clchen): Try to see if it is possible to be more efficient here
         // and not search for plugins again.
@@ -705,16 +725,16 @@ public class TextToSpeechSettings extends PreferenceActivity implements
         CharSequence entriesArray[] = new CharSequence[entries.size()];
         CharSequence valuesArray[] = new CharSequence[values.size()];
 
-        enginesPref.setEntries(entries.toArray(entriesArray));
-        enginesPref.setEntryValues(values.toArray(valuesArray));
+        mDefaultSynthPref.setEntries(entries.toArray(entriesArray));
+        mDefaultSynthPref.setEntryValues(values.toArray(valuesArray));
 
         // Set the selected engine based on the saved preference
         String selectedEngine = Settings.Secure.getString(getContentResolver(), TTS_DEFAULT_SYNTH);
-        int selectedEngineIndex = enginesPref.findIndexOfValue(selectedEngine);
+        int selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(selectedEngine);
         if (selectedEngineIndex == -1){
-            selectedEngineIndex = enginesPref.findIndexOfValue(SYSTEM_TTS);
+            selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(SYSTEM_TTS);
         }
-        enginesPref.setValueIndex(selectedEngineIndex);
+        mDefaultSynthPref.setValueIndex(selectedEngineIndex);
     }
 
 }