summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/ChooseLockGeneric.java4
-rw-r--r--src/com/android/settings/DataUsageSummary.java4
-rw-r--r--src/com/android/settings/SecuritySettings.java6
-rw-r--r--src/com/android/settings/SettingsPreferenceFragment.java12
-rw-r--r--src/com/android/settings/TextToSpeechSettings.java709
-rw-r--r--src/com/android/settings/UserDictionarySettings.java7
-rw-r--r--src/com/android/settings/Utils.java29
-rw-r--r--src/com/android/settings/applications/ManageApplications.java26
-rw-r--r--src/com/android/settings/bluetooth/BluetoothSettings.java19
-rw-r--r--src/com/android/settings/fuelgauge/PowerUsageDetail.java14
-rw-r--r--src/com/android/settings/tts/TextToSpeechSettings.java495
-rw-r--r--src/com/android/settings/tts/TtsEnginePreference.java197
-rw-r--r--src/com/android/settings/tts/TtsEngineSettingsFragment.java200
-rw-r--r--src/com/android/settings/wifi/AccessPoint.java15
-rw-r--r--src/com/android/settings/wifi/AdvancedWifiSettings.java2
-rw-r--r--src/com/android/settings/wifi/WifiConfigController.java29
-rw-r--r--src/com/android/settings/wifi/WifiSettings.java20
17 files changed, 1025 insertions, 763 deletions
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 8311c4a..b1bc856 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -16,8 +16,6 @@
package com.android.settings;
-import com.android.internal.widget.LockPatternUtils;
-
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
@@ -29,6 +27,8 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.security.KeyStore;
+import com.android.internal.widget.LockPatternUtils;
+
public class ChooseLockGeneric extends PreferenceActivity {
@Override
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index b99264f..a6170c7 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -43,6 +43,7 @@ import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
import static android.text.format.Time.TIMEZONE_UTC;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+import static com.android.settings.Utils.prepareCustomPreferencesList;
import android.animation.LayoutTransition;
import android.app.AlertDialog;
@@ -272,6 +273,9 @@ public class DataUsageSummary extends Fragment {
mTabWidget = (TabWidget) view.findViewById(android.R.id.tabs);
mListView = (ListView) view.findViewById(android.R.id.list);
+ // adjust padding around tabwidget as needed
+ prepareCustomPreferencesList(container, view, mListView);
+
mTabHost.setup();
mTabHost.setOnTabChangedListener(mTabListener);
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 9a83311..3813ecd 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -37,6 +37,7 @@ import android.security.KeyStore;
import android.telephony.TelephonyManager;
import android.util.Log;
+import com.android.internal.telephony.Phone;
import com.android.internal.widget.LockPatternUtils;
import java.util.ArrayList;
@@ -162,8 +163,9 @@ public class SecuritySettings extends SettingsPreferenceFragment
addPreferencesFromResource(R.xml.security_settings_misc);
// Do not display SIM lock for CDMA phone
- if (TelephonyManager.PHONE_TYPE_CDMA ==
- TelephonyManager.getDefault().getCurrentPhoneType()) {
+ TelephonyManager tm = TelephonyManager.getDefault();
+ if ((TelephonyManager.PHONE_TYPE_CDMA == tm.getCurrentPhoneType()) &&
+ (tm.getLteOnCdmaMode() != Phone.LTE_ON_CDMA_TRUE)) {
root.removePreference(root.findPreference(KEY_SIM_LOCK));
}
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index bd9e331..f7e3b02 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -16,28 +16,22 @@
package com.android.settings;
-import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.ContentResolver;
import android.content.DialogInterface;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
-import android.text.TextUtils;
import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
import android.widget.Button;
/**
* Base class for Settings fragments, with some helper functions and dialog management.
*/
-public class SettingsPreferenceFragment extends PreferenceFragment
- implements DialogCreatable {
+public class SettingsPreferenceFragment extends PreferenceFragment implements DialogCreatable {
private static final String TAG = "SettingsPreferenceFragment";
@@ -241,8 +235,8 @@ public class SettingsPreferenceFragment extends PreferenceFragment
Fragment caller, String fragmentClass, int requestCode, Bundle extras) {
if (getActivity() instanceof PreferenceActivity) {
PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
- preferenceActivity.startPreferencePanel(fragmentClass, extras, 0, null, caller,
- requestCode);
+ preferenceActivity.startPreferencePanel(fragmentClass, extras,
+ R.string.lock_settings_picker_title, null, caller, requestCode);
return true;
} else {
Log.w(TAG, "Parent isn't PreferenceActivity, thus there's no way to launch the "
diff --git a/src/com/android/settings/TextToSpeechSettings.java b/src/com/android/settings/TextToSpeechSettings.java
deleted file mode 100644
index d76f08f..0000000
--- a/src/com/android/settings/TextToSpeechSettings.java
+++ /dev/null
@@ -1,709 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings;
-
-import static android.provider.Settings.Secure.TTS_DEFAULT_COUNTRY;
-import static android.provider.Settings.Secure.TTS_DEFAULT_LANG;
-import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
-import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
-import static android.provider.Settings.Secure.TTS_DEFAULT_VARIANT;
-import static android.provider.Settings.Secure.TTS_USE_DEFAULTS;
-
-import android.app.AlertDialog;
-import android.content.ActivityNotFoundException;
-import android.content.ContentResolver;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.os.Bundle;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceClickListener;
-import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
-import android.speech.tts.TextToSpeech;
-import android.speech.tts.TextToSpeech.EngineInfo;
-import android.speech.tts.TtsEngines;
-import android.text.TextUtils;
-import android.util.Log;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.StringTokenizer;
-
-public class TextToSpeechSettings extends SettingsPreferenceFragment implements
- Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
- TextToSpeech.OnInitListener {
-
- private static final String TAG = "TextToSpeechSettings";
-
- private static final String KEY_TTS_PLAY_EXAMPLE = "tts_play_example";
- private static final String KEY_TTS_INSTALL_DATA = "tts_install_data";
- private static final String KEY_TTS_USE_DEFAULT = "toggle_use_default_tts_settings";
- private static final String KEY_TTS_DEFAULT_RATE = "tts_default_rate";
- private static final String KEY_TTS_DEFAULT_LANG = "tts_default_lang";
- private static final String KEY_TTS_DEFAULT_COUNTRY = "tts_default_country";
- private static final String KEY_TTS_DEFAULT_VARIANT = "tts_default_variant";
- private static final String KEY_TTS_DEFAULT_SYNTH = "tts_default_synth";
- private static final String KEY_TTS_ENGINE_SETTINGS = "tts_engine_settings";
-
- private static final String KEY_PLUGIN_ENABLED_PREFIX = "ENABLED_";
- private static final String KEY_PLUGIN_SETTINGS_PREFIX = "SETTINGS_";
-
- // TODO move default Locale values to TextToSpeech.Engine
- private static final String DEFAULT_LANG_VAL = "eng";
- private static final String DEFAULT_COUNTRY_VAL = "USA";
- private static final String DEFAULT_VARIANT_VAL = "";
-
- private static final String LOCALE_DELIMITER = "-";
-
- private Preference mPlayExample = null;
-
- private ListPreference mDefaultRatePref = null;
- private ListPreference mDefaultLocPref = null;
- private ListPreference mDefaultSynthPref = null;
-
- private Preference mInstallData = null;
- private Preference mEngineSettings = null;
-
- private String mDefaultLanguage = null;
- private String mDefaultCountry = null;
- private String mDefaultLocVariant = null;
- private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
-
- // Index of the current string to use for the demo.
- private int mDemoStringIndex = 0;
-
- private boolean mEnableDemo = false;
- private boolean mVoicesMissing = false;
-
- private TextToSpeech mTts = null;
- private TtsEngines mEnginesHelper = null;
- private boolean mTtsStarted = false;
-
- /**
- * Request code (arbitrary value) for voice data check through
- * startActivityForResult.
- */
- private static final int VOICE_DATA_INTEGRITY_CHECK = 1977;
- private static final int GET_SAMPLE_TEXT = 1983;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.tts_settings);
-
- getActivity().setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
-
- mEnableDemo = false;
- mTtsStarted = false;
-
- Locale currentLocale = Locale.getDefault();
- mDefaultLanguage = currentLocale.getISO3Language();
- mDefaultCountry = currentLocale.getISO3Country();
- mDefaultLocVariant = currentLocale.getVariant();
-
- mPlayExample = findPreference(KEY_TTS_PLAY_EXAMPLE);
- mPlayExample.setOnPreferenceClickListener(this);
-
- mInstallData = findPreference(KEY_TTS_INSTALL_DATA);
- mInstallData.setOnPreferenceClickListener(this);
-
- mDefaultSynthPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
- mDefaultRatePref = (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE);
- mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
-
- mEngineSettings = findPreference(KEY_TTS_ENGINE_SETTINGS);
- mEngineSettings.setEnabled(false);
-
- mTts = new TextToSpeech(getActivity().getApplicationContext(), this);
- mEnginesHelper = new TtsEngines(getActivity().getApplicationContext());
-
- initDefaultSettings();
- initEngineSpecificSettings();
- }
-
- @Override
- public void onStart() {
- super.onStart();
- if (mTtsStarted){
- // 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.
- // TODO make the TTS service listen to "changes in the system", i.e. sd card un/mount
- updateWidgetState();
- checkVoiceData();
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (mTts != null) {
- mTts.shutdown();
- }
- }
-
- @Override
- public 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 initEngineSpecificSettings() {
- final String engineName = mEnginesHelper.getDefaultEngine();
- final EngineInfo engine = mEnginesHelper.getEngineInfo(engineName);
-
- mEngineSettings.setTitle(getResources().getString(R.string.tts_engine_settings_title,
- engine.label));
-
- final Intent settingsIntent = mEnginesHelper.getSettingsIntent(engineName);
- if (settingsIntent != null) {
- mEngineSettings.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference preference) {
- startActivity(settingsIntent);
- return true;
- }
- });
- mEngineSettings.setEnabled(true);
- } else {
- mEngineSettings.setEnabled(false);
- }
-
- }
-
- private void initDefaultSettings() {
- ContentResolver resolver = getContentResolver();
-
- // Find the default TTS values in the settings, initialize and store the
- // settings if they are not found.
-
- // Default synthesis engine
- loadEngines();
- mDefaultSynthPref.setOnPreferenceChangeListener(this);
-
- // Default rate
- try {
- mDefaultRate = Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
- } catch (SettingNotFoundException e) {
- // default rate setting not found, initialize it
- mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
- Settings.Secure.putInt(resolver, TTS_DEFAULT_RATE, mDefaultRate);
- }
- mDefaultRatePref.setValue(String.valueOf(mDefaultRate));
- mDefaultRatePref.setOnPreferenceChangeListener(this);
-
- // Default language / country / variant : these three values map to a single ListPref
- // representing the matching Locale
- initDefaultLang();
- mDefaultLocPref.setOnPreferenceChangeListener(this);
- }
-
- /**
- * Ask the current default engine to launch the matching CHECK_TTS_DATA activity
- * to check the required TTS files are properly installed.
- */
- private void checkVoiceData() {
- String defaultEngine = mTts.getDefaultEngine();
- if (TextUtils.isEmpty(defaultEngine)) return;
- Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
- intent.setPackage(defaultEngine);
- try {
- Log.v(TAG, "Checking voice data: " + intent.toUri(0));
- startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
- } catch (ActivityNotFoundException ex) {
- Log.e(TAG, "Failed to check TTS data, no acitivty found for " + intent + ")");
- }
- }
-
-
- /**
- * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity
- * so the required TTS files are properly installed.
- */
- private void installVoiceData() {
- String defaultEngine = mTts.getDefaultEngine();
- if (TextUtils.isEmpty(defaultEngine)) return;
- Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setPackage(defaultEngine);
- try {
- Log.v(TAG, "Installing voice data: " + intent.toUri(0));
- startActivity(intent);
- } catch (ActivityNotFoundException ex) {
- Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
- }
- }
-
- /**
- * Ask the current default engine to return a string of sample text to be
- * spoken to the user.
- */
- private void getSampleText() {
- String defaultEngine = mTts.getDefaultEngine();
- if (TextUtils.isEmpty(defaultEngine)) return;
- Intent intent = new Intent(TextToSpeech.Engine.ACTION_GET_SAMPLE_TEXT);
- intent.putExtra("language", mDefaultLanguage);
- intent.putExtra("country", mDefaultCountry);
- intent.putExtra("variant", mDefaultLocVariant);
- intent.setPackage(defaultEngine);
-
- try {
- Log.v(TAG, "Getting sample text: " + intent.toUri(0));
- startActivityForResult(intent, GET_SAMPLE_TEXT);
- } catch (ActivityNotFoundException ex) {
- Log.e(TAG, "Failed to get sample text, no acitivty found for " + intent + ")");
- }
- }
-
- /**
- * Called when the TTS engine is initialized.
- */
- public void onInit(int status) {
- if (status == TextToSpeech.SUCCESS) {
- mEnableDemo = true;
- if (mDefaultLanguage == null) {
- mDefaultLanguage = Locale.getDefault().getISO3Language();
- }
- if (mDefaultCountry == null) {
- mDefaultCountry = Locale.getDefault().getISO3Country();
- }
- if (mDefaultLocVariant == null) {
- mDefaultLocVariant = new String();
- }
- mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
- updateWidgetState();
- checkVoiceData();
- mTtsStarted = true;
- Log.v(TAG, "TTS engine for settings screen initialized.");
- } else {
- Log.v(TAG, "TTS engine for settings screen failed to initialize successfully.");
- mEnableDemo = false;
- }
- updateWidgetState();
- }
-
- /**
- * Called when voice data integrity check returns
- */
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
- onVoiceDataIntegrityCheckDone(data);
- } else if (requestCode == GET_SAMPLE_TEXT) {
- onSampleTextReceived(resultCode, data);
- }
- }
-
- private void onVoiceDataIntegrityCheckDone(Intent data) {
- if (data == null){
- Log.e(TAG, "TTS data check failed data = null");
- // The CHECK_TTS_DATA activity for the plugin did not run properly;
- // disable the preview and install controls and return.
- mEnableDemo = false;
- mVoicesMissing = false;
- updateWidgetState();
- return;
- }
- Log.v(TAG, "TTS data check completed, data = " + data.toUri(0));
- ArrayList<String> available =
- data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
- ArrayList<String> unavailable =
- data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
- if (available == null || unavailable == null){
- Log.e(TAG, "TTS data check failed (available == == null)");
- // The CHECK_TTS_DATA activity for the plugin did not run properly;
- // disable the preview and install controls and return.
- mEnableDemo = false;
- mVoicesMissing = false;
- updateWidgetState();
- return;
- }
- if (available.size() > 0){
- if (mTts == null) {
- mTts = new TextToSpeech(getActivity(), this);
- }
-
- updateDefaultLocPref(available);
-
- mEnableDemo = true;
- // Make sure that the default language can be used.
- int languageResult = mTts.setLanguage(
- new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
- if (languageResult < TextToSpeech.LANG_AVAILABLE){
- Locale currentLocale = Locale.getDefault();
- mDefaultLanguage = currentLocale.getISO3Language();
- mDefaultCountry = currentLocale.getISO3Country();
- mDefaultLocVariant = currentLocale.getVariant();
- languageResult = mTts.setLanguage(
- new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
- // If the default Locale isn't supported, just choose the first available
- // language so that there is at least something.
- if (languageResult < TextToSpeech.LANG_AVAILABLE){
- parseLocaleInfo(mDefaultLocPref.getEntryValues()[0].toString());
- mTts.setLanguage(
- new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
- }
- ContentResolver resolver = getContentResolver();
- Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, mDefaultLanguage);
- Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, mDefaultCountry);
- Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, mDefaultLocVariant);
- }
- } else {
- mEnableDemo = false;
- }
-
- if (unavailable.size() > 0){
- mVoicesMissing = true;
- } else {
- mVoicesMissing = false;
- }
-
- updateWidgetState();
- }
-
- private void updateDefaultLocPref(ArrayList<String> availableLangs) {
- CharSequence[] entries = new CharSequence[availableLangs.size()];
- CharSequence[] entryValues = new CharSequence[availableLangs.size()];
- int selectedLanguageIndex = -1;
- String selectedLanguagePref = mDefaultLanguage;
- if (mDefaultCountry.length() > 0) {
- selectedLanguagePref = selectedLanguagePref + LOCALE_DELIMITER +
- mDefaultCountry;
- }
- if (mDefaultLocVariant.length() > 0) {
- selectedLanguagePref = selectedLanguagePref + LOCALE_DELIMITER +
- mDefaultLocVariant;
- }
- for (int i = 0; i < availableLangs.size(); i++) {
- String[] langCountryVariant = availableLangs.get(i).split("-");
- Locale loc = null;
- if (langCountryVariant.length == 1){
- loc = new Locale(langCountryVariant[0]);
- } else if (langCountryVariant.length == 2){
- loc = new Locale(langCountryVariant[0], langCountryVariant[1]);
- } else if (langCountryVariant.length == 3){
- loc = new Locale(langCountryVariant[0], langCountryVariant[1],
- langCountryVariant[2]);
- }
- if (loc != null){
- entries[i] = loc.getDisplayName();
- entryValues[i] = availableLangs.get(i);
- if (entryValues[i].equals(selectedLanguagePref)) {
- selectedLanguageIndex = i;
- }
- }
- }
- mDefaultLocPref.setEntries(entries);
- mDefaultLocPref.setEntryValues(entryValues);
- if (selectedLanguageIndex > -1) {
- mDefaultLocPref.setValueIndex(selectedLanguageIndex);
- }
- }
-
- private void onSampleTextReceived(int resultCode, Intent data) {
- if (resultCode == TextToSpeech.LANG_AVAILABLE) {
- String sample = getActivity().getString(R.string.tts_demo);
- if (data != null && data.getStringExtra("sampleText") != null) {
- sample = data.getStringExtra("sampleText");
- }
- Log.v(TAG, "Got sample text: " + sample);
- if (mTts != null) {
- mTts.speak(sample, TextToSpeech.QUEUE_FLUSH, null);
- }
- } else {
- // TODO: Display an error here to the user.
- Log.e(TAG, "Did not have a sample string for the requested language");
- }
- }
-
- public boolean onPreferenceChange(Preference preference, Object objValue) {
- if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) {
- // "Use Defaults"
- int value = ((Boolean) objValue) ? 1 : 0;
- Settings.Secure.putInt(getContentResolver(), TTS_USE_DEFAULTS, value);
- Log.i(TAG, "TTS 'use default' settings changed, now " + value);
- } else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) {
- // Default rate
- mDefaultRate = Integer.parseInt((String) objValue);
- try {
- Settings.Secure.putInt(getContentResolver(), TTS_DEFAULT_RATE, mDefaultRate);
- if (mTts != null) {
- mTts.setSpeechRate(mDefaultRate / 100.0f);
- }
- Log.v(TAG, "TTS default rate changed, now " + mDefaultRate);
- } catch (NumberFormatException e) {
- Log.e(TAG, "could not persist default TTS rate setting", e);
- }
- } else if (KEY_TTS_DEFAULT_LANG.equals(preference.getKey())) {
- // Default locale
- ContentResolver resolver = getContentResolver();
- parseLocaleInfo((String) objValue);
- Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, mDefaultLanguage);
- Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, mDefaultCountry);
- Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, mDefaultLocVariant);
- Log.v(TAG, "TTS default lang/country/variant set to "
- + mDefaultLanguage + "/" + mDefaultCountry + "/" + mDefaultLocVariant);
- if (mTts != null) {
- mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
- }
- int newIndex = mDefaultLocPref.findIndexOfValue((String)objValue);
- Log.v(TAG, " selected is " + newIndex);
- mDemoStringIndex = newIndex > -1 ? newIndex : 0;
- } else if (KEY_TTS_DEFAULT_SYNTH.equals(preference.getKey())) {
- final String name = objValue.toString();
- final EngineInfo info = mEnginesHelper.getEngineInfo(name);
-
- if (info.system) {
- // For system engines, do away with the alert dialog.
- updateDefaultEngine(name);
- initEngineSpecificSettings();
- } else {
- // For all other engines, display a warning message before
- // turning them on.
- displayDataAlert(preference, name);
- }
-
- // We'll deal with updating the UI ourselves.
- return false;
- }
-
- return true;
- }
-
-
- /**
- * Called when mPlayExample or mInstallData is clicked
- */
- public boolean onPreferenceClick(Preference preference) {
- if (preference == mPlayExample) {
- // Get the sample text from the TTS engine; onActivityResult will do
- // the actual speaking
- getSampleText();
- return true;
- } else if (preference == mInstallData) {
- installVoiceData();
- // quit this activity so it needs to be restarted after installation of the voice data
- finish();
- return true;
- }
-
- return false;
- }
-
- private void updateWidgetState() {
- mPlayExample.setEnabled(mEnableDemo);
- mDefaultRatePref.setEnabled(mEnableDemo);
- mDefaultLocPref.setEnabled(mEnableDemo);
-
- mInstallData.setEnabled(mVoicesMissing);
- }
-
-
- private void parseLocaleInfo(String locale) {
- StringTokenizer tokenizer = new StringTokenizer(locale, LOCALE_DELIMITER);
- mDefaultLanguage = "";
- mDefaultCountry = "";
- mDefaultLocVariant = "";
-
- if (locale != null) {
- String[] components = locale.split(LOCALE_DELIMITER);
- if (components.length > 0) {
- mDefaultLanguage = components[0];
- }
- if (components.length > 1) {
- mDefaultCountry = components[1];
- }
- if (components.length > 2) {
- mDefaultLocVariant = components[2];
- }
- }
- }
-
-
- /**
- * Initialize the default language in the UI and in the preferences.
- * After this method has been invoked, the default language is a supported Locale.
- */
- private void initDefaultLang() {
- // if there isn't already a default language preference
- if (!hasLangPref()) {
- // if the current Locale is supported
- if (isCurrentLocSupported()) {
- // then use the current Locale as the default language
- useCurrentLocAsDefault();
- } else {
- // otherwise use a default supported Locale as the default language
- useSupportedLocAsDefault();
- }
- }
-
- // Update the language preference list with the default language and the matching
- // demo string (at this stage there is a default language pref)
- ContentResolver resolver = getContentResolver();
- mDefaultLanguage = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG);
- mDefaultCountry = Settings.Secure.getString(resolver, TTS_DEFAULT_COUNTRY);
- mDefaultLocVariant = Settings.Secure.getString(resolver, TTS_DEFAULT_VARIANT);
-
- // update the demo string
- mDemoStringIndex = mDefaultLocPref.findIndexOfValue(mDefaultLanguage + LOCALE_DELIMITER
- + mDefaultCountry);
- if (mDemoStringIndex > -1){
- mDefaultLocPref.setValueIndex(mDemoStringIndex);
- }
- }
-
- /**
- * (helper function for initDefaultLang() )
- * Returns whether there is a default language in the TTS settings.
- */
- private boolean hasLangPref() {
- ContentResolver resolver = getContentResolver();
- String language = Settings.Secure.getString(resolver, TTS_DEFAULT_LANG);
- if ((language == null) || (language.length() < 1)) {
- return false;
- }
- String country = Settings.Secure.getString(resolver, TTS_DEFAULT_COUNTRY);
- if (country == null) {
- return false;
- }
- String variant = Settings.Secure.getString(resolver, TTS_DEFAULT_VARIANT);
- if (variant == null) {
- return false;
- }
- return true;
- }
-
- /**
- * (helper function for initDefaultLang() )
- * Returns whether the current Locale is supported by this Settings screen
- */
- private boolean isCurrentLocSupported() {
- String currentLocID = Locale.getDefault().getISO3Language() + LOCALE_DELIMITER
- + Locale.getDefault().getISO3Country();
- return (mDefaultLocPref.findIndexOfValue(currentLocID) > -1);
- }
-
- /**
- * (helper function for initDefaultLang() )
- * Sets the default language in TTS settings to be the current Locale.
- * This should only be used after checking that the current Locale is supported.
- */
- private void useCurrentLocAsDefault() {
- Locale currentLocale = Locale.getDefault();
- ContentResolver resolver = getContentResolver();
- Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, currentLocale.getISO3Language());
- Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, currentLocale.getISO3Country());
- Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, currentLocale.getVariant());
- }
-
- /**
- * (helper function for initDefaultLang() )
- * Sets the default language in TTS settings to be one known to be supported
- */
- private void useSupportedLocAsDefault() {
- ContentResolver resolver = getContentResolver();
- Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, DEFAULT_LANG_VAL);
- Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, DEFAULT_COUNTRY_VAL);
- Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, DEFAULT_VARIANT_VAL);
- }
-
- private void loadEngines() {
- List<EngineInfo> engines = mEnginesHelper.getEngines();
- CharSequence entries[] = new CharSequence[engines.size()];
- CharSequence values[] = new CharSequence[engines.size()];
-
- final int count = engines.size();
- for (int i = 0; i < count; ++i) {
- final EngineInfo engine = engines.get(i);
- entries[i] = engine.label;
- values[i] = engine.name;
- }
-
- mDefaultSynthPref.setEntries(entries);
- mDefaultSynthPref.setEntryValues(values);
-
- // Set the selected engine based on the saved preference
- String selectedEngine = Settings.Secure.getString(getContentResolver(), TTS_DEFAULT_SYNTH);
- int selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(selectedEngine);
- if (selectedEngineIndex == -1){
- selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(
- mEnginesHelper.getHighestRankedEngineName());
- }
- if (selectedEngineIndex >= 0) {
- mDefaultSynthPref.setValueIndex(selectedEngineIndex);
- }
- }
-
- private void displayDataAlert(Preference pref, final String key) {
- Log.v(TAG, "Displaying data alert for :" + key);
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setTitle(android.R.string.dialog_alert_title);
- builder.setIcon(android.R.drawable.ic_dialog_alert);
- builder.setMessage(getActivity().getString(
- R.string.tts_engine_security_warning, pref.getTitle()));
- builder.setCancelable(true);
- builder.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- updateDefaultEngine(key);
- loadEngines();
- initEngineSpecificSettings();
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
-
- AlertDialog dialog = builder.create();
- dialog.show();
- }
-
- private void updateDefaultEngine(String engine) {
- Log.v(TAG, "Updating default synth to : " + engine);
- if (mTts != null) {
- try {
- mTts.shutdown();
- mTts = null;
- } catch (Exception e) {
- Log.e(TAG, "Error shutting down TTS engine" + e);
- }
- }
-
- mTts = new TextToSpeech(getActivity().getApplicationContext(), this, engine);
- mEnableDemo = false;
- mVoicesMissing = false;
-
- // Persist this value to settings and update the UI before we check
- // voice data because if the TTS class connected without any exception, "engine"
- // will be the default engine irrespective of whether the voice check
- // passes or not.
- Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, engine);
- mDefaultSynthPref.setValue(engine);
- updateWidgetState();
-
- checkVoiceData();
-
- Log.v(TAG, "The default synth is now: " + engine);
- }
-
-}
diff --git a/src/com/android/settings/UserDictionarySettings.java b/src/com/android/settings/UserDictionarySettings.java
index be8f453..496947b 100644
--- a/src/com/android/settings/UserDictionarySettings.java
+++ b/src/com/android/settings/UserDictionarySettings.java
@@ -96,6 +96,13 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
}
@Override
+ public View onCreateView(
+ LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(
+ com.android.internal.R.layout.preference_list_fragment, container, false);
+ }
+
+ @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index b725d56..73a9a30 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -20,8 +20,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
@@ -31,13 +31,17 @@ import android.os.BatteryManager;
import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.Preference;
-import android.preference.PreferenceGroup;
import android.preference.PreferenceActivity.Header;
+import android.preference.PreferenceFrameLayout;
+import android.preference.PreferenceGroup;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+import android.widget.TabWidget;
import java.net.InetAddress;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -365,4 +369,23 @@ public class Utils {
return statusString;
}
+
+ /**
+ * Prepare a custom preferences layout, moving padding to {@link ListView}
+ * when outside scrollbars are requested. Usually used to display
+ * {@link ListView} and {@link TabWidget} with correct padding.
+ */
+ public static void prepareCustomPreferencesList(ViewGroup parent, View child, ListView list) {
+ final boolean movePadding = list.getScrollBarStyle() == View.SCROLLBARS_OUTSIDE_OVERLAY;
+ if (movePadding && parent instanceof PreferenceFrameLayout) {
+ ((PreferenceFrameLayout.LayoutParams) child.getLayoutParams()).removeBorders = true;
+
+ final Resources res = list.getResources();
+ final int paddingSide = res.getDimensionPixelSize(
+ com.android.internal.R.dimen.preference_fragment_padding_side);
+ final int paddingBottom = res.getDimensionPixelSize(
+ com.android.internal.R.dimen.preference_fragment_padding_bottom);
+ list.setPadding(paddingSide, 0, paddingSide, paddingBottom);
+ }
+ }
}
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 68c942d..747b406 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -16,11 +16,7 @@
package com.android.settings.applications;
-import com.android.internal.content.PackageHelper;
-import com.android.settings.R;
-import com.android.settings.Settings.RunningServicesActivity;
-import com.android.settings.Settings.StorageUseActivity;
-import com.android.settings.applications.ApplicationsState.AppEntry;
+import static com.android.settings.Utils.prepareCustomPreferencesList;
import android.app.Activity;
import android.app.Fragment;
@@ -58,6 +54,12 @@ import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
+import com.android.internal.content.PackageHelper;
+import com.android.settings.R;
+import com.android.settings.Settings.RunningServicesActivity;
+import com.android.settings.Settings.StorageUseActivity;
+import com.android.settings.applications.ApplicationsState.AppEntry;
+
import java.util.ArrayList;
import java.util.Comparator;
@@ -618,9 +620,8 @@ public class ManageApplications extends Fragment implements
mCreatedRunning = mResumedRunning = false;
mCurView = VIEW_NOTHING;
-
- View tabRoot = mInflater.inflate(R.layout.manage_apps_tab_content, null);
- mTabHost = (TabHost)tabRoot.findViewById(com.android.internal.R.id.tabhost);
+
+ mTabHost = (TabHost) mInflater.inflate(R.layout.manage_apps_tab_content, container, false);
mTabHost.setup();
final TabHost tabHost = mTabHost;
tabHost.addTab(tabHost.newTabSpec(TAB_DOWNLOADED)
@@ -644,7 +645,10 @@ public class ManageApplications extends Fragment implements
tabHost.setCurrentTabByTag(mDefaultTab);
tabHost.setOnTabChangedListener(this);
- return tabRoot;
+ // adjust padding around tabwidget as needed
+ prepareCustomPreferencesList(container, mTabHost, mListView);
+
+ return mTabHost;
}
@Override
@@ -708,10 +712,10 @@ public class ManageApplications extends Fragment implements
// bar UI to be very confusing.
menu.add(0, SORT_ORDER_ALPHA, 1, R.string.sort_order_alpha)
//.setIcon(android.R.drawable.ic_menu_sort_alphabetically)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, SORT_ORDER_SIZE, 2, R.string.sort_order_size)
//.setIcon(android.R.drawable.ic_menu_sort_by_size)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, SHOW_BACKGROUND_PROCESSES, 3, R.string.show_background_processes)
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 4b86a74..9f56f32 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -68,6 +68,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
private PreferenceGroup mAvailableDevicesCategory;
private boolean mAvailableDevicesCategoryIsPresent;
+ private boolean mActivityStarted;
private TextView mEmptyView;
@@ -98,6 +99,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
+ mActivityStarted = true;
super.onActivityCreated(savedInstanceState);
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
@@ -144,7 +146,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
}
getActivity().registerReceiver(mReceiver, mIntentFilter);
- updateContent(mLocalAdapter.getBluetoothState());
+ updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
}
@Override
@@ -226,7 +228,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
preferenceGroup.setEnabled(true);
}
- private void updateContent(int bluetoothState) {
+ private void updateContent(int bluetoothState, boolean scanState) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
int messageId = 0;
@@ -289,7 +291,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
if (numberOfPairedDevices == 0) {
preferenceScreen.removePreference(mPairedDevicesCategory);
- startScanning();
+ if (scanState == true) {
+ mActivityStarted = false;
+ startScanning();
+ } else {
+ if (!mAvailableDevicesCategoryIsPresent) {
+ getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+ }
+ }
}
getActivity().invalidateOptionsMenu();
return; // not break
@@ -316,7 +325,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
@Override
public void onBluetoothStateChanged(int bluetoothState) {
super.onBluetoothStateChanged(bluetoothState);
- updateContent(bluetoothState);
+ updateContent(bluetoothState, true);
}
@Override
@@ -329,7 +338,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
setDeviceListGroup(getPreferenceScreen());
removeAllDevices();
- updateContent(mLocalAdapter.getBluetoothState());
+ updateContent(mLocalAdapter.getBluetoothState(), false);
}
private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {
diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
index 7717503..b70312b 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
@@ -44,8 +44,8 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.DisplaySettings;
+import com.android.settings.LocationSettings;
import com.android.settings.R;
-import com.android.settings.SecuritySettings;
import com.android.settings.WirelessSettings;
import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.bluetooth.BluetoothSettings;
@@ -79,7 +79,7 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
public static final int ACTION_BLUETOOTH_SETTINGS = 3;
public static final int ACTION_WIRELESS_SETTINGS = 4;
public static final int ACTION_APP_DETAILS = 5;
- public static final int ACTION_SECURITY_SETTINGS = 6;
+ public static final int ACTION_LOCATION_SETTINGS = 6;
public static final int ACTION_FORCE_STOP = 7;
public static final int ACTION_REPORT = 8;
@@ -280,9 +280,9 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
case ACTION_APP_DETAILS:
startApplicationDetailsActivity();
break;
- case ACTION_SECURITY_SETTINGS:
- pa.startPreferencePanel(SecuritySettings.class.getName(), null,
- R.string.security_settings_title, null, null, 0);
+ case ACTION_LOCATION_SETTINGS:
+ pa.startPreferencePanel(LocationSettings.class.getName(), null,
+ R.string.location_settings_title, null, null, 0);
break;
case ACTION_FORCE_STOP:
killProcesses();
@@ -348,8 +348,8 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
// TODO:
}
if (mUsesGps) {
- addControl(R.string.security_settings_title,
- R.string.battery_sugg_apps_gps, ACTION_SECURITY_SETTINGS);
+ addControl(R.string.location_settings_title,
+ R.string.battery_sugg_apps_gps, ACTION_LOCATION_SETTINGS);
removeHeader = false;
}
break;
diff --git a/src/com/android/settings/tts/TextToSpeechSettings.java b/src/com/android/settings/tts/TextToSpeechSettings.java
new file mode 100644
index 0000000..e8255bf
--- /dev/null
+++ b/src/com/android/settings/tts/TextToSpeechSettings.java
@@ -0,0 +1,495 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.tts;
+
+import static android.provider.Settings.Secure.TTS_DEFAULT_RATE;
+import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.tts.TtsEnginePreference.RadioButtonGroupState;
+
+import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
+import android.content.ContentResolver;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TextToSpeech.EngineInfo;
+import android.speech.tts.TtsEngines;
+import android.text.TextUtils;
+import android.util.Log;
+import android.widget.Checkable;
+
+import java.util.List;
+import java.util.Locale;
+
+public class TextToSpeechSettings extends SettingsPreferenceFragment implements
+ Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
+ RadioButtonGroupState {
+
+ private static final String TAG = "TextToSpeechSettings";
+ private static final boolean DBG = false;
+
+ /** Preference key for the "play TTS example" preference. */
+ private static final String KEY_PLAY_EXAMPLE = "tts_play_example";
+
+ /** Preference key for the TTS rate selection dialog. */
+ private static final String KEY_DEFAULT_RATE = "tts_default_rate";
+
+ /**
+ * Preference key for the engine selection preference.
+ */
+ private static final String KEY_ENGINE_PREFERENCE_SECTION =
+ "tts_engine_preference_section";
+
+ /**
+ * These look like birth years, but they aren't mine. I'm much younger than this.
+ */
+ private static final int GET_SAMPLE_TEXT = 1983;
+ private static final int VOICE_DATA_INTEGRITY_CHECK = 1977;
+
+ private PreferenceCategory mEnginePreferenceCategory;
+ private ListPreference mDefaultRatePref;
+ private Preference mPlayExample;
+
+ private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
+
+ /**
+ * The currently selected engine.
+ */
+ private String mCurrentEngine;
+
+ /**
+ * The engine checkbox that is currently checked. Saves us a bit of effort
+ * in deducing the right one from the currently selected engine.
+ */
+ private Checkable mCurrentChecked;
+
+ /**
+ * The previously selected TTS engine. Useful for rollbacks if the users
+ * choice is not loaded or fails a voice integrity check.
+ */
+ private String mPreviousEngine;
+
+ private TextToSpeech mTts = null;
+ private TtsEngines mEnginesHelper = null;
+
+ /**
+ * The initialization listener used when we are initalizing the settings
+ * screen for the first time (as opposed to when a user changes his choice
+ * of engine).
+ */
+ private final TextToSpeech.OnInitListener mInitListener = new TextToSpeech.OnInitListener() {
+ @Override
+ public void onInit(int status) {
+ onInitEngine(status);
+ }
+ };
+
+ /**
+ * The initialization listener used when the user changes his choice of
+ * engine (as opposed to when then screen is being initialized for the first
+ * time).
+ */
+ private final TextToSpeech.OnInitListener mUpdateListener = new TextToSpeech.OnInitListener() {
+ @Override
+ public void onInit(int status) {
+ onUpdateEngine(status);
+ }
+ };
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.tts_settings);
+
+ getActivity().setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
+
+ mPlayExample = findPreference(KEY_PLAY_EXAMPLE);
+ mPlayExample.setOnPreferenceClickListener(this);
+
+ mEnginePreferenceCategory = (PreferenceCategory) findPreference(
+ KEY_ENGINE_PREFERENCE_SECTION);
+ mDefaultRatePref = (ListPreference) findPreference(KEY_DEFAULT_RATE);
+
+ mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener);
+ mEnginesHelper = new TtsEngines(getActivity().getApplicationContext());
+
+ initSettings();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (mTts != null) {
+ mTts.shutdown();
+ mTts = null;
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if ((mDefaultRatePref != null) && (mDefaultRatePref.getDialog() != null)) {
+ mDefaultRatePref.getDialog().dismiss();
+ }
+ }
+
+ private void initSettings() {
+ final ContentResolver resolver = getContentResolver();
+
+ // Set up the default rate.
+ try {
+ mDefaultRate = Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
+ } catch (SettingNotFoundException e) {
+ // Default rate setting not found, initialize it
+ mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
+ }
+ mDefaultRatePref.setValue(String.valueOf(mDefaultRate));
+ mDefaultRatePref.setOnPreferenceChangeListener(this);
+
+ mCurrentEngine = mTts.getCurrentEngine();
+
+ PreferenceActivity preferenceActivity = null;
+ if (getActivity() instanceof PreferenceActivity) {
+ preferenceActivity = (PreferenceActivity) getActivity();
+ } else {
+ throw new IllegalStateException("TextToSpeechSettings used outside a " +
+ "PreferenceActivity");
+ }
+
+ mEnginePreferenceCategory.removeAll();
+
+ List<EngineInfo> engines = mEnginesHelper.getEngines();
+ for (EngineInfo engine : engines) {
+ TtsEnginePreference enginePref = new TtsEnginePreference(getActivity(), engine,
+ this, preferenceActivity);
+ mEnginePreferenceCategory.addPreference(enginePref);
+ }
+
+ checkVoiceData(mCurrentEngine);
+ }
+
+ private void maybeUpdateTtsLanguage(String currentEngine) {
+ if (currentEngine != null && mTts != null) {
+ final String localeString = mEnginesHelper.getLocalePrefForEngine(
+ currentEngine);
+ if (localeString != null) {
+ final String[] locale = TtsEngines.parseLocalePref(localeString);
+
+ if (DBG) Log.d(TAG, "Loading language ahead of sample check : " + locale);
+ mTts.setLanguage(new Locale(locale[0], locale[1], locale[2]));
+ }
+ }
+ }
+
+ /**
+ * Ask the current default engine to return a string of sample text to be
+ * spoken to the user.
+ */
+ private void getSampleText() {
+ String currentEngine = mTts.getCurrentEngine();
+
+ if (TextUtils.isEmpty(currentEngine)) currentEngine = mTts.getDefaultEngine();
+
+ maybeUpdateTtsLanguage(currentEngine);
+ Locale currentLocale = mTts.getLanguage();
+
+ // TODO: This is currently a hidden private API. The intent extras
+ // and the intent action should be made public if we intend to make this
+ // a public API. We fall back to using a canned set of strings if this
+ // doesn't work.
+ Intent intent = new Intent(TextToSpeech.Engine.ACTION_GET_SAMPLE_TEXT);
+
+ if (currentLocale != null) {
+ intent.putExtra("language", currentLocale.getLanguage());
+ intent.putExtra("country", currentLocale.getCountry());
+ intent.putExtra("variant", currentLocale.getVariant());
+ }
+ intent.setPackage(currentEngine);
+
+ try {
+ if (DBG) Log.d(TAG, "Getting sample text: " + intent.toUri(0));
+ startActivityForResult(intent, GET_SAMPLE_TEXT);
+ } catch (ActivityNotFoundException ex) {
+ Log.e(TAG, "Failed to get sample text, no activity found for " + intent + ")");
+ }
+ }
+
+ /**
+ * Called when the TTS engine is initialized.
+ */
+ public void onInitEngine(int status) {
+ if (status == TextToSpeech.SUCCESS) {
+ updateWidgetState(true);
+ if (DBG) Log.d(TAG, "TTS engine for settings screen initialized.");
+ } else {
+ if (DBG) Log.d(TAG, "TTS engine for settings screen failed to initialize successfully.");
+ updateWidgetState(false);
+ }
+ }
+
+ /**
+ * Called when voice data integrity check returns
+ */
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == GET_SAMPLE_TEXT) {
+ onSampleTextReceived(resultCode, data);
+ } else if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
+ onVoiceDataIntegrityCheckDone(data);
+ }
+ }
+
+ 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];
+ }
+ }
+ }
+ return null;
+ }
+
+ private void onSampleTextReceived(int resultCode, Intent data) {
+ String sample = getDefaultSampleString();
+
+ if (resultCode == TextToSpeech.LANG_AVAILABLE && data != null) {
+ if (data != null && data.getStringExtra("sampleText") != null) {
+ sample = data.getStringExtra("sampleText");
+ }
+ if (DBG) Log.d(TAG, "Got sample text: " + sample);
+ } else {
+ if (DBG) Log.d(TAG, "Using default sample text :" + sample);
+ }
+
+ if (sample != null && mTts != null) {
+ // The engine is guaranteed to have been initialized here
+ // because this preference is not enabled otherwise.
+ mTts.speak(sample, TextToSpeech.QUEUE_FLUSH, null);
+ } else {
+ // TODO: Display an error here to the user.
+ Log.e(TAG, "Did not have a sample string for the requested language");
+ }
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object objValue) {
+ if (KEY_DEFAULT_RATE.equals(preference.getKey())) {
+ // Default rate
+ mDefaultRate = Integer.parseInt((String) objValue);
+ try {
+ Settings.Secure.putInt(getContentResolver(), TTS_DEFAULT_RATE, mDefaultRate);
+ if (mTts != null) {
+ mTts.setSpeechRate(mDefaultRate / 100.0f);
+ }
+ if (DBG) Log.d(TAG, "TTS default rate changed, now " + mDefaultRate);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "could not persist default TTS rate setting", e);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Called when mPlayExample is clicked
+ */
+ public boolean onPreferenceClick(Preference preference) {
+ if (preference == mPlayExample) {
+ // Get the sample text from the TTS engine; onActivityResult will do
+ // the actual speaking
+ getSampleText();
+ return true;
+ }
+
+ return false;
+ }
+
+ private void updateWidgetState(boolean enable) {
+ mPlayExample.setEnabled(enable);
+ mDefaultRatePref.setEnabled(enable);
+ }
+
+ private void displayDataAlert(final String key) {
+ Log.i(TAG, "Displaying data alert for :" + key);
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(android.R.string.dialog_alert_title);
+ builder.setIcon(android.R.drawable.ic_dialog_alert);
+ builder.setMessage(getActivity().getString(
+ R.string.tts_engine_security_warning, mEnginesHelper.getEngineInfo(key).label));
+ builder.setCancelable(true);
+ builder.setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ updateDefaultEngine(key);
+ }
+ });
+ builder.setNegativeButton(android.R.string.cancel, null);
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+
+ private void updateDefaultEngine(String engine) {
+ if (DBG) Log.d(TAG, "Updating default synth to : " + engine);
+
+ // Disable the "play sample text" preference and the speech
+ // rate preference while the engine is being swapped.
+ updateWidgetState(false);
+
+ // Keep track of the previous engine that was being used. So that
+ // we can reuse the previous engine.
+ //
+ // Note that if TextToSpeech#getCurrentEngine is not null, it means at
+ // the very least that we successfully bound to the engine service.
+ mPreviousEngine = mTts.getCurrentEngine();
+
+ // Step 1: Shut down the existing TTS engine.
+ if (mTts != null) {
+ try {
+ mTts.shutdown();
+ mTts = null;
+ } catch (Exception e) {
+ Log.e(TAG, "Error shutting down TTS engine" + e);
+ }
+ }
+
+ // Step 2: Connect to the new TTS engine.
+ // Step 3 is continued on #onUpdateEngine (below) which is called when
+ // the app binds successfully to the engine.
+ if (DBG) Log.d(TAG, "Updating engine : Attempting to connect to engine: " + engine);
+ mTts = new TextToSpeech(getActivity().getApplicationContext(), mUpdateListener, engine);
+ }
+
+ /*
+ * Step 3: We have now bound to the TTS engine the user requested. We will
+ * attempt to check voice data for the engine if we successfully bound to it,
+ * or revert to the previous engine if we didn't.
+ */
+ public void onUpdateEngine(int status) {
+ if (status == TextToSpeech.SUCCESS) {
+ if (DBG) {
+ Log.d(TAG, "Updating engine: Successfully bound to the engine: " +
+ mTts.getCurrentEngine());
+ }
+ checkVoiceData(mTts.getCurrentEngine());
+ } else {
+ if (DBG) Log.d(TAG, "Updating engine: Failed to bind to engine, reverting.");
+ if (mPreviousEngine != null) {
+ // This is guaranteed to at least bind, since mPreviousEngine would be
+ // null if the previous bind to this engine failed.
+ mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener,
+ mPreviousEngine);
+ }
+ mPreviousEngine = null;
+ }
+ }
+
+ /*
+ * Step 4: Check whether the voice data for the engine is ok.
+ */
+ private void checkVoiceData(String engine) {
+ Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
+ intent.setPackage(engine);
+ try {
+ if (DBG) Log.d(TAG, "Updating engine: Checking voice data: " + intent.toUri(0));
+ startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
+ } catch (ActivityNotFoundException ex) {
+ Log.e(TAG, "Failed to check TTS data, no activity found for " + intent + ")");
+ }
+ }
+
+ /*
+ * Step 5: The voice data check is complete.
+ */
+ private void onVoiceDataIntegrityCheckDone(Intent data) {
+ final String engine = mTts.getCurrentEngine();
+
+ if (engine == null) {
+ Log.e(TAG, "Voice data check complete, but no engine bound");
+ return;
+ }
+
+ if (data == null){
+ Log.e(TAG, "Engine failed voice data integrity check (null return)" +
+ mTts.getCurrentEngine());
+ return;
+ }
+
+ Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, engine);
+
+ final int engineCount = mEnginePreferenceCategory.getPreferenceCount();
+ for (int i = 0; i < engineCount; ++i) {
+ final Preference p = mEnginePreferenceCategory.getPreference(i);
+ if (p instanceof TtsEnginePreference) {
+ TtsEnginePreference enginePref = (TtsEnginePreference) p;
+ if (enginePref.getKey().equals(engine)) {
+ enginePref.setVoiceDataDetails(data);
+ break;
+ }
+ }
+ }
+
+ updateWidgetState(true);
+ }
+
+ private boolean shouldDisplayDataAlert(String engine) {
+ final EngineInfo info = mEnginesHelper.getEngineInfo(engine);
+ return !info.system;
+ }
+
+ @Override
+ public Checkable getCurrentChecked() {
+ return mCurrentChecked;
+ }
+
+ @Override
+ public String getCurrentKey() {
+ return mCurrentEngine;
+ }
+
+ @Override
+ public void setCurrentChecked(Checkable current) {
+ mCurrentChecked = current;
+ }
+
+ @Override
+ public void setCurrentKey(String key) {
+ mCurrentEngine = key;
+ if (shouldDisplayDataAlert(mCurrentEngine)) {
+ displayDataAlert(mCurrentEngine);
+ } else {
+ updateDefaultEngine(mCurrentEngine);
+ }
+ }
+
+}
diff --git a/src/com/android/settings/tts/TtsEnginePreference.java b/src/com/android/settings/tts/TtsEnginePreference.java
new file mode 100644
index 0000000..b98a239
--- /dev/null
+++ b/src/com/android/settings/tts/TtsEnginePreference.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.tts;
+
+import com.android.settings.R;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.speech.tts.TextToSpeech.EngineInfo;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Checkable;
+import android.widget.CompoundButton;
+import android.widget.RadioButton;
+
+
+public class TtsEnginePreference extends Preference {
+
+ /**
+ * Key for the name of the TTS engine passed in to the engine
+ * settings fragment {@link TtsEngineSettingsFragment}.
+ */
+ static final String FRAGMENT_ARGS_NAME = "name";
+
+ /**
+ * Key for the label of the TTS engine passed in to the engine
+ * settings fragment. This is used as the title of the fragment
+ * {@link TtsEngineSettingsFragment}.
+ */
+ static final String FRAGMENT_ARGS_LABEL = "label";
+
+ /**
+ * Key for the voice data data passed in to the engine settings
+ * fragmetn {@link TtsEngineSettingsFragment}.
+ */
+ static final String FRAGMENT_ARGS_VOICES = "voices";
+
+ /**
+ * The preference activity that owns this preference. Required
+ * for instantiating the engine specific settings screen.
+ */
+ private final PreferenceActivity mPreferenceActivity;
+
+ /**
+ * The engine information for the engine this preference represents.
+ * Contains it's name, label etc. which are used for display.
+ */
+ private final EngineInfo mEngineInfo;
+
+ /**
+ * The shared radio button state, which button is checked etc.
+ */
+ private final RadioButtonGroupState mSharedState;
+
+ /**
+ * When true, the change callbacks on the radio button will not
+ * fire.
+ */
+ private volatile boolean mPreventRadioButtonCallbacks;
+
+ private View mSettingsIcon;
+ private RadioButton mRadioButton;
+ private Intent mVoiceCheckData;
+
+ private final CompoundButton.OnCheckedChangeListener mRadioChangeListener =
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ onRadioButtonClicked(buttonView, isChecked);
+ }
+ };
+
+ public TtsEnginePreference(Context context, EngineInfo info, RadioButtonGroupState state,
+ PreferenceActivity prefActivity) {
+ super(context);
+ setLayoutResource(R.layout.preference_tts_engine);
+
+ mSharedState = state;
+ mPreferenceActivity = prefActivity;
+ mEngineInfo = info;
+ mPreventRadioButtonCallbacks = false;
+
+ setKey(mEngineInfo.name);
+ setTitle(mEngineInfo.label);
+ }
+
+ @Override
+ public View getView(View convertView, ViewGroup parent) {
+ if (mSharedState == null) {
+ throw new IllegalStateException("Call to getView() before a call to" +
+ "setSharedState()");
+ }
+
+ View view = super.getView(convertView, parent);
+ final RadioButton rb = (RadioButton) view.findViewById(R.id.tts_engine_radiobutton);
+ rb.setOnCheckedChangeListener(mRadioChangeListener);
+
+ boolean isChecked = getKey().equals(mSharedState.getCurrentKey());
+ if (isChecked) {
+ mSharedState.setCurrentChecked(rb);
+ }
+
+ mPreventRadioButtonCallbacks = true;
+ rb.setChecked(isChecked);
+ mPreventRadioButtonCallbacks = false;
+
+ mRadioButton = rb;
+
+ View textLayout = view.findViewById(R.id.tts_engine_pref_text);
+ textLayout.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onRadioButtonClicked(rb, !rb.isChecked());
+ }
+ });
+
+ mSettingsIcon = view.findViewById(R.id.tts_engine_settings);
+ // Will be enabled only the engine has passed the voice check, and
+ // is currently enabled.
+ mSettingsIcon.setEnabled(isChecked && mVoiceCheckData != null);
+ mSettingsIcon.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Bundle args = new Bundle();
+ args.putString(FRAGMENT_ARGS_NAME, mEngineInfo.name);
+ args.putString(FRAGMENT_ARGS_LABEL, mEngineInfo.label);
+ if (mVoiceCheckData != null) {
+ args.putParcelable(FRAGMENT_ARGS_VOICES, mVoiceCheckData);
+ }
+
+ // Note that we use this instead of the (easier to use)
+ // PreferenceActivity.startPreferenceFragment because the
+ // title will not be updated correctly in the fragment
+ // breadcrumb since it isn't inflated from the XML layout.
+ mPreferenceActivity.startPreferencePanel(
+ TtsEngineSettingsFragment.class.getName(),
+ args, 0, mEngineInfo.label, null, 0);
+ }
+ });
+
+ return view;
+ }
+
+ public void setVoiceDataDetails(Intent data) {
+ mVoiceCheckData = data;
+ mSettingsIcon.setEnabled(mRadioButton.isChecked());
+ }
+
+ private void onRadioButtonClicked(CompoundButton buttonView, boolean isChecked) {
+ if (mPreventRadioButtonCallbacks) {
+ return;
+ }
+
+ if (isChecked) {
+ if (mSharedState.getCurrentChecked() != null) {
+ mSharedState.getCurrentChecked().setChecked(false);
+ }
+ mSharedState.setCurrentChecked(buttonView);
+ mSharedState.setCurrentKey(getKey());
+ callChangeListener(mSharedState.getCurrentKey());
+ }
+
+ mSettingsIcon.setEnabled(isChecked);
+ }
+
+
+ /**
+ * Holds all state that is common to this group of radio buttons, such
+ * as the currently selected key and the currently checked compound button.
+ * (which corresponds to this key).
+ */
+ public interface RadioButtonGroupState {
+ String getCurrentKey();
+ Checkable getCurrentChecked();
+
+ void setCurrentKey(String key);
+ void setCurrentChecked(Checkable current);
+ }
+
+}
diff --git a/src/com/android/settings/tts/TtsEngineSettingsFragment.java b/src/com/android/settings/tts/TtsEngineSettingsFragment.java
new file mode 100644
index 0000000..d78f80d
--- /dev/null
+++ b/src/com/android/settings/tts/TtsEngineSettingsFragment.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.tts;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceScreen;
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TtsEngines;
+import android.text.TextUtils;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+
+public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implements
+ OnPreferenceClickListener, OnPreferenceChangeListener {
+ private static final String TAG = "TtsEngineSettings";
+ private static final boolean DBG = false;
+
+ private static final String KEY_ENGINE_LOCALE = "tts_default_lang";
+ private static final String KEY_ENGINE_SETTINGS = "tts_engine_settings";
+ private static final String KEY_INSTALL_DATA = "tts_install_data";
+
+ private TtsEngines mEnginesHelper;
+ private ListPreference mLocalePreference;
+ private Preference mEngineSettingsPreference;
+ private Preference mInstallVoicesPreference;
+ private Intent mEngineSettingsIntent;
+
+ public TtsEngineSettingsFragment() {
+ super();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.tts_engine_settings);
+ mEnginesHelper = new TtsEngines(getActivity());
+
+ final PreferenceScreen root = getPreferenceScreen();
+ mLocalePreference = (ListPreference) root.findPreference(KEY_ENGINE_LOCALE);
+ mLocalePreference.setOnPreferenceChangeListener(this);
+ mEngineSettingsPreference = root.findPreference(KEY_ENGINE_SETTINGS);
+ mEngineSettingsPreference.setOnPreferenceClickListener(this);
+ mInstallVoicesPreference = root.findPreference(KEY_INSTALL_DATA);
+ mInstallVoicesPreference.setOnPreferenceClickListener(this);
+
+ root.setTitle(getEngineLabel());
+ root.setKey(getEngineName());
+ mEngineSettingsPreference.setTitle(getResources().getString(
+ R.string.tts_engine_settings_title, getEngineLabel()));
+
+ mEngineSettingsIntent = mEnginesHelper.getSettingsIntent(getEngineName());
+ if (mEngineSettingsIntent == null) {
+ mEngineSettingsPreference.setEnabled(false);
+ }
+ mInstallVoicesPreference.setEnabled(false);
+
+ updateVoiceDetails();
+ }
+
+ private void updateVoiceDetails() {
+ final Intent voiceDataDetails = getArguments().getParcelable(
+ TtsEnginePreference.FRAGMENT_ARGS_VOICES);
+ if (DBG) Log.d(TAG, "Parsing voice data details, data: " + voiceDataDetails.toUri(0));
+ ArrayList<String> available = voiceDataDetails.getStringArrayListExtra(
+ TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
+ ArrayList<String> unavailable = voiceDataDetails.getStringArrayListExtra(
+ TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
+
+ if (available == null || unavailable == null){
+ Log.e(TAG, "TTS data check failed (available == null).");
+ return;
+ }
+
+ if (unavailable.size() > 0) {
+ mInstallVoicesPreference.setEnabled(true);
+ }
+
+ if (available.size() > 0) {
+ updateDefaultLocalePref(available);
+ } else {
+ final CharSequence[] empty = new CharSequence[0];
+ mLocalePreference.setEntries(empty);
+ mLocalePreference.setEntryValues(empty);
+ }
+ }
+
+ private void updateDefaultLocalePref(ArrayList<String> availableLangs) {
+ String currentLocale = mEnginesHelper.getLocalePrefForEngine(
+ getEngineName());
+
+ CharSequence[] entries = new CharSequence[availableLangs.size()];
+ CharSequence[] entryValues = new CharSequence[availableLangs.size()];
+
+ int selectedLanguageIndex = -1;
+ for (int i = 0; i < availableLangs.size(); i++) {
+ String[] langCountryVariant = availableLangs.get(i).split("-");
+ Locale loc = null;
+ if (langCountryVariant.length == 1){
+ loc = new Locale(langCountryVariant[0]);
+ } else if (langCountryVariant.length == 2){
+ loc = new Locale(langCountryVariant[0], langCountryVariant[1]);
+ } else if (langCountryVariant.length == 3){
+ loc = new Locale(langCountryVariant[0], langCountryVariant[1],
+ langCountryVariant[2]);
+ }
+ if (loc != null){
+ entries[i] = loc.getDisplayName();
+ entryValues[i] = availableLangs.get(i);
+ if (entryValues[i].equals(currentLocale)) {
+ selectedLanguageIndex = i;
+ }
+ }
+ }
+
+ mLocalePreference.setEntries(entries);
+ mLocalePreference.setEntryValues(entryValues);
+ if (selectedLanguageIndex > -1) {
+ mLocalePreference.setValueIndex(selectedLanguageIndex);
+ } else {
+ mLocalePreference.setValueIndex(0);
+ mEnginesHelper.updateLocalePrefForEngine(getEngineName(),
+ availableLangs.get(0));
+ }
+ }
+
+ /**
+ * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity
+ * so the required TTS files are properly installed.
+ */
+ private void installVoiceData() {
+ if (TextUtils.isEmpty(getEngineName())) return;
+ Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setPackage(getEngineName());
+ try {
+ Log.v(TAG, "Installing voice data: " + intent.toUri(0));
+ startActivity(intent);
+ } catch (ActivityNotFoundException ex) {
+ Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
+ }
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (preference == mInstallVoicesPreference) {
+ installVoiceData();
+ return true;
+ } else if (preference == mEngineSettingsPreference) {
+ startActivity(mEngineSettingsIntent);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mLocalePreference) {
+ mEnginesHelper.updateLocalePrefForEngine(getEngineName(), (String) newValue);
+ return true;
+ }
+
+ return false;
+ }
+
+ private String getEngineName() {
+ return getArguments().getString(TtsEnginePreference.FRAGMENT_ARGS_NAME);
+ }
+
+ private String getEngineLabel() {
+ return getArguments().getString(TtsEnginePreference.FRAGMENT_ARGS_LABEL);
+ }
+
+}
diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java
index 799a8da..03e7ba4 100644
--- a/src/com/android/settings/wifi/AccessPoint.java
+++ b/src/com/android/settings/wifi/AccessPoint.java
@@ -358,4 +358,19 @@ class AccessPoint extends Preference {
setSummary(summary.toString());
}
}
+
+ /**
+ * Generate and save a default wifiConfiguration with common values.
+ * Can only be called for unsecured networks.
+ * @hide
+ */
+ protected void generateOpenNetworkConfig() {
+ if (security != SECURITY_NONE)
+ throw new IllegalStateException();
+ if (mConfig != null)
+ return;
+ mConfig = new WifiConfiguration();
+ mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
+ mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
+ }
}
diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java
index 6c983fd..7ec546b 100644
--- a/src/com/android/settings/wifi/AdvancedWifiSettings.java
+++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java
@@ -78,8 +78,6 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
watchdogEnabled.setChecked(Secure.getInt(getContentResolver(),
Secure.WIFI_WATCHDOG_ON, 1) == 1);
- watchdogEnabled.setEnabled(mWifiManager.isWifiEnabled());
-
ListPreference frequencyPref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
if (mWifiManager.isDualBandSupported()) {
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index f879b85..2cbe260 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -182,8 +182,6 @@ public class WifiConfigController implements TextWatcher,
addRow(group, R.string.wifi_status, Summary.get(mConfigUi.getContext(), state));
}
- addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
-
int level = mAccessPoint.getLevel();
if (level != -1) {
String[] signal = resources.getStringArray(R.array.wifi_signal);
@@ -195,10 +193,14 @@ public class WifiConfigController implements TextWatcher,
addRow(group, R.string.wifi_speed, info.getLinkSpeed() + WifiInfo.LINK_SPEED_UNITS);
}
+ addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
+
+ boolean showAdvancedFields = false;
if (mAccessPoint.networkId != INVALID_NETWORK_ID) {
WifiConfiguration config = mAccessPoint.getConfig();
if (config.ipAssignment == IpAssignment.STATIC) {
mIpSettingsSpinner.setSelection(STATIC_IP);
+ showAdvancedFields = true;
} else {
mIpSettingsSpinner.setSelection(DHCP);
}
@@ -210,6 +212,7 @@ public class WifiConfigController implements TextWatcher,
if (config.proxySettings == ProxySettings.STATIC) {
mProxySettingsSpinner.setSelection(PROXY_STATIC);
+ showAdvancedFields = true;
} else {
mProxySettingsSpinner.setSelection(PROXY_NONE);
}
@@ -224,6 +227,12 @@ public class WifiConfigController implements TextWatcher,
showSecurityFields();
showIpConfigFields();
showProxyFields();
+ mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE);
+ mView.findViewById(R.id.wifi_advanced_togglebox).setOnClickListener(this);
+ if (showAdvancedFields) {
+ ((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox)).setChecked(true);
+ mView.findViewById(R.id.wifi_advanced_fields).setVisibility(View.VISIBLE);
+ }
}
if (mEdit) {
@@ -726,10 +735,18 @@ public class WifiConfigController implements TextWatcher,
@Override
public void onClick(View view) {
- mPasswordView.setInputType(
- InputType.TYPE_CLASS_TEXT | (((CheckBox) view).isChecked() ?
- InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
- InputType.TYPE_TEXT_VARIATION_PASSWORD));
+ if (view.getId() == R.id.show_password) {
+ mPasswordView.setInputType(
+ InputType.TYPE_CLASS_TEXT | (((CheckBox) view).isChecked() ?
+ InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
+ InputType.TYPE_TEXT_VARIATION_PASSWORD));
+ } else if (view.getId() == R.id.wifi_advanced_togglebox) {
+ if (((CheckBox) view).isChecked()) {
+ mView.findViewById(R.id.wifi_advanced_fields).setVisibility(View.VISIBLE);
+ } else {
+ mView.findViewById(R.id.wifi_advanced_fields).setVisibility(View.GONE);
+ }
+ }
}
@Override
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 1b24bf7..188765f 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -270,7 +270,7 @@ public class WifiSettings extends SettingsPreferenceFragment
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
//.setIcon(android.R.drawable.ic_menu_manage)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
}
super.onCreateOptionsMenu(menu, inflater);
}
@@ -353,11 +353,9 @@ public class WifiSettings extends SettingsPreferenceFragment
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
}
} else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
- // Shortcut for open networks.
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = AccessPoint.convertToQuotedString(mSelectedAccessPoint.ssid);
- config.allowedKeyManagement.set(KeyMgmt.NONE);
- mWifiManager.connectNetwork(config);
+ /** Bypass dialog for unsecured networks */
+ mSelectedAccessPoint.generateOpenNetworkConfig();
+ mWifiManager.connectNetwork(mSelectedAccessPoint.getConfig());
} else {
showConfigUi(mSelectedAccessPoint, true);
}
@@ -379,7 +377,14 @@ public class WifiSettings extends SettingsPreferenceFragment
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
if (preference instanceof AccessPoint) {
mSelectedAccessPoint = (AccessPoint) preference;
- showConfigUi(mSelectedAccessPoint, false);
+ /** Bypass dialog for unsecured, unsaved networks */
+ if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE &&
+ mSelectedAccessPoint.networkId == INVALID_NETWORK_ID) {
+ mSelectedAccessPoint.generateOpenNetworkConfig();
+ mWifiManager.connectNetwork(mSelectedAccessPoint.getConfig());
+ } else {
+ showConfigUi(mSelectedAccessPoint, false);
+ }
} else {
return super.onPreferenceTreeClick(screen, preference);
}
@@ -623,6 +628,7 @@ public class WifiSettings extends SettingsPreferenceFragment
}
void forceScan() {
+ removeMessages(0);
sendEmptyMessage(0);
}