diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2013-05-13 17:14:01 +0100 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-05-21 12:30:21 +0000 |
commit | 6dcdfab90627b211e4ba0877c506468030ad806b (patch) | |
tree | 3237451c29146e07e07557dc913a82efd9302f0d /src/com/android/settings/tts | |
parent | 52d8db7fb20e212da05247e2c2e8c036fbdde448 (diff) | |
download | packages_apps_Settings-6dcdfab90627b211e4ba0877c506468030ad806b.zip packages_apps_Settings-6dcdfab90627b211e4ba0877c506468030ad806b.tar.gz packages_apps_Settings-6dcdfab90627b211e4ba0877c506468030ad806b.tar.bz2 |
Make TTS language setting track system language.
TTS engine default locale is set independently from the system locale.
If TTS engine default locale is not set, it defaults to the system locale.
If user decides to set TTS locale, ability to default to the current system
locale is lost (until device is wiped).
This change makes settings wipe the TTS engine default locale value if user
selects language that is system language. This allows TTS to track system
language if user changes it.
If system language is not available in TTS, language field is set to
"language not selected" value.
This change require a small change in framework/base to make previously
private method public (TtsEngines.getDefaultLocale).
+ Selected language is displayed in language preference summary (matches
all other language preferences)
+ Removing and then adding "language" and 'install languages' preferences
looks glitchy, not they are disabled (grayed out) if unavailable.
Bug: 8613986
Change-Id: Ic4bde97ef7406adb64cc03efbe660275360ba3af
Diffstat (limited to 'src/com/android/settings/tts')
-rw-r--r-- | src/com/android/settings/tts/TtsEngineSettingsFragment.java | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/src/com/android/settings/tts/TtsEngineSettingsFragment.java b/src/com/android/settings/tts/TtsEngineSettingsFragment.java index e02b6ae..bb5ac7a 100644 --- a/src/com/android/settings/tts/TtsEngineSettingsFragment.java +++ b/src/com/android/settings/tts/TtsEngineSettingsFragment.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; @@ -62,6 +63,9 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem private TextToSpeech mTts; + private int mSelectedLocaleIndex = -1; + private int mSystemLocaleIndex = -1; + private final TextToSpeech.OnInitListener mTtsInitListener = new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { @@ -105,10 +109,6 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem mEngineSettingsPreference.setOnPreferenceClickListener(this); mInstallVoicesPreference = root.findPreference(KEY_INSTALL_DATA); mInstallVoicesPreference.setOnPreferenceClickListener(this); - // Remove this preference unless voices are indeed available to install. - root.removePreference(mInstallVoicesPreference); - // Remove this preference unless locales are indeed available. - root.removePreference(mLocalePreference); root.setTitle(getEngineLabel()); root.setKey(getEngineName()); @@ -120,8 +120,8 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem mEngineSettingsPreference.setEnabled(false); } mInstallVoicesPreference.setEnabled(false); - mLocalePreference.setEnabled(false); + mLocalePreference.setEntries(new CharSequence[0]); mLocalePreference.setEntryValues(new CharSequence[0]); @@ -130,7 +130,6 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener, getEngineName()); - // Check if data packs changed checkTtsData(); @@ -172,31 +171,26 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem final ArrayList<String> unavailable = mVoiceDataDetails.getStringArrayListExtra( TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES); - if (available == null){ - Log.e(TAG, "TTS data check failed (available == null)."); - mLocalePreference.setEnabled(false); - getPreferenceScreen().removePreference(mLocalePreference); - return; - } - if (unavailable != null && unavailable.size() > 0) { mInstallVoicesPreference.setEnabled(true); - getPreferenceScreen().addPreference(mInstallVoicesPreference); } else { - getPreferenceScreen().removePreference(mInstallVoicesPreference); + mInstallVoicesPreference.setEnabled(false); } - if (available.size() > 0) { - mLocalePreference.setEnabled(true); - getPreferenceScreen().addPreference(mLocalePreference); - updateDefaultLocalePref(available); - } else { + if (available == null){ + Log.e(TAG, "TTS data check failed (available == null)."); mLocalePreference.setEnabled(false); - getPreferenceScreen().removePreference(mLocalePreference); + return; + } else { + updateDefaultLocalePref(available); } } private void updateDefaultLocalePref(ArrayList<String> availableLangs) { + if (availableLangs == null || availableLangs.size() == 0) { + mLocalePreference.setEnabled(false); + return; + } String currentLocale = mEnginesHelper.getLocalePrefForEngine( getEngineName()); @@ -227,14 +221,20 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem } }); + String defaultLocaleStr = mEnginesHelper.getDefaultLocale(); + // Get two arrays out of one of pairs - int selectedLanguageIndex = -1; + mSelectedLocaleIndex = -1; + mSystemLocaleIndex = -1; CharSequence[] entries = new CharSequence[availableLangs.size()]; CharSequence[] entryValues = new CharSequence[availableLangs.size()]; int i = 0; for (Pair<String, String> entry : entryPairs) { if (entry.second.equalsIgnoreCase(currentLocale)) { - selectedLanguageIndex = i; + mSelectedLocaleIndex = i; + } + if (entry.second.equalsIgnoreCase(defaultLocaleStr)) { + mSystemLocaleIndex = i; } entries[i] = entry.first; entryValues[i++] = entry.second; @@ -242,11 +242,18 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem mLocalePreference.setEntries(entries); mLocalePreference.setEntryValues(entryValues); - if (selectedLanguageIndex > -1) { - mLocalePreference.setValueIndex(selectedLanguageIndex); + mLocalePreference.setEnabled(true); + setLocalePreference(mSelectedLocaleIndex); + } + + /** Set entry from entry table in mLocalePreference */ + private void setLocalePreference(int index) { + if (index < 0) { + mLocalePreference.setValue(""); + mLocalePreference.setSummary(R.string.tts_lang_not_selected); } else { - mLocalePreference.setValueIndex(0); - updateLanguageTo(availableLangs.get(0)); + mLocalePreference.setValueIndex(index); + mLocalePreference.setSummary(mLocalePreference.getEntries()[index]); } } @@ -286,12 +293,32 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem updateLanguageTo((String) newValue); return true; } - return false; } private void updateLanguageTo(String locale) { - mEnginesHelper.updateLocalePrefForEngine(getEngineName(), locale); + int selectedLocaleIndex = -1; + for (int i=0; i < mLocalePreference.getEntryValues().length; i++) { + if (locale.equalsIgnoreCase(mLocalePreference.getEntryValues()[i].toString())) { + selectedLocaleIndex = i; + break; + } + } + + if (selectedLocaleIndex == -1) { + Log.w(TAG, "updateLanguageTo called with unknown locale argument"); + return; + } + mLocalePreference.setSummary(mLocalePreference.getEntries()[selectedLocaleIndex]); + mSelectedLocaleIndex = selectedLocaleIndex; + + if (mSelectedLocaleIndex == mSystemLocaleIndex) { + // Use empty locale, it will default to the system language + mEnginesHelper.updateLocalePrefForEngine(getEngineName(), ""); + } else { + mEnginesHelper.updateLocalePrefForEngine(getEngineName(), locale); + } + if (getEngineName().equals(mTts.getCurrentEngine())) { String[] localeArray = TtsEngines.parseLocalePref(locale); if (localeArray != null) { @@ -307,5 +334,4 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem private String getEngineLabel() { return getArguments().getString(TtsEnginePreference.FRAGMENT_ARGS_LABEL); } - } |