Search in sources :

Example 71 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_Settings by LineageOS.

the class OpenvpnEditor method createList.

private ListPreference createList(Context c, int titleResId, String selection, String[] keys, Preference.OnPreferenceChangeListener listener) {
    ListPreference pref = new ListPreference(c);
    pref.setTitle(titleResId);
    pref.setDialogTitle(titleResId);
    pref.setPersistent(true);
    pref.setEntries(keys);
    pref.setEntryValues(keys);
    pref.setValue(selection);
    pref.setOnPreferenceChangeListener(listener);
    return pref;
}
Also used : ListPreference(android.preference.ListPreference)

Example 72 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_Settings by LineageOS.

the class AdvancedSettings method initNumChannelsPreference.

private void initNumChannelsPreference() {
    ListPreference pref = (ListPreference) findPreference(KEY_NUM_CHANNELS);
    pref.setOnPreferenceChangeListener(this);
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    /*
         * Generate the list of valid channel counts to show in the ListPreference.
         * The values are numerical, so the only text to be localized is the
         * "channel_word" resource.
         */
    int[] validChannelCounts = wifiManager.getValidChannelCounts();
    if (validChannelCounts == null) {
        Toast.makeText(this, R.string.wifi_setting_num_channels_error, Toast.LENGTH_SHORT).show();
        pref.setEnabled(false);
        return;
    }
    String[] entries = new String[validChannelCounts.length];
    String[] entryValues = new String[validChannelCounts.length];
    for (int i = 0; i < validChannelCounts.length; i++) {
        entryValues[i] = String.valueOf(validChannelCounts[i]);
        entries[i] = getString(R.string.wifi_setting_num_channels_channel_phrase, validChannelCounts[i]);
    }
    pref.setEntries(entries);
    pref.setEntryValues(entryValues);
    pref.setEnabled(true);
    int numChannels = wifiManager.getNumAllowedChannels();
    if (numChannels >= 0) {
        pref.setValue(String.valueOf(numChannels));
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) ListPreference(android.preference.ListPreference)

Example 73 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_Settings by LineageOS.

the class ApplicationSettings method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.application_settings);
    mToggleAppInstallation = (CheckBoxPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
    mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
    mInstallLocation = (ListPreference) findPreference(KEY_APP_INSTALL_LOCATION);
    // Is app default install location set?
    boolean userSetInstLocation = (Settings.System.getInt(getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION, 0) != 0);
    if (!userSetInstLocation) {
        getPreferenceScreen().removePreference(mInstallLocation);
    } else {
        mInstallLocation.setValue(getAppInstallLocation());
        mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String value = (String) newValue;
                handleUpdateAppInstallLocation(value);
                return false;
            }
        });
    }
    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS) {
        // No hard keyboard, remove the setting for quick launch
        Preference quickLaunchSetting = findPreference(KEY_QUICK_LAUNCH);
        getPreferenceScreen().removePreference(quickLaunchSetting);
    }
}
Also used : ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 74 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_Settings by LineageOS.

the class TextToSpeechSettings method onActivityResult.

/**
 * Called when voice data integrity check returns
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
        if (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;
        }
        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)) {
            // 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(this, this);
            }
            ListPreference ttsLanguagePref = (ListPreference) findPreference("tts_default_lang");
            CharSequence[] entries = new CharSequence[available.size()];
            CharSequence[] entryValues = new CharSequence[available.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 < available.size(); i++) {
                String[] langCountryVariant = available.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] = available.get(i);
                    if (entryValues[i].equals(selectedLanguagePref)) {
                        selectedLanguageIndex = i;
                    }
                }
            }
            ttsLanguagePref.setEntries(entries);
            ttsLanguagePref.setEntryValues(entryValues);
            if (selectedLanguageIndex > -1) {
                ttsLanguagePref.setValueIndex(selectedLanguageIndex);
            }
            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));
                // language so that there is at least something.
                if (languageResult < TextToSpeech.LANG_AVAILABLE) {
                    parseLocaleInfo(ttsLanguagePref.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();
    } else if (requestCode == GET_SAMPLE_TEXT) {
        if (resultCode == TextToSpeech.LANG_AVAILABLE) {
            String sample = getString(R.string.tts_demo);
            if ((data != null) && (data.getStringExtra("sampleText") != null)) {
                sample = data.getStringExtra("sampleText");
            }
            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");
        }
    }
}
Also used : Locale(java.util.Locale) ListPreference(android.preference.ListPreference) TextToSpeech(android.speech.tts.TextToSpeech) ContentResolver(android.content.ContentResolver)

Example 75 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_Settings by LineageOS.

the class SoundSettings method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver resolver = getContentResolver();
    int activePhoneType = TelephonyManager.getDefault().getPhoneType();
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    addPreferencesFromResource(R.xml.sound_settings);
    if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
        // device is not CDMA, do not display CDMA emergency_tone
        getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE));
    }
    mSilent = (CheckBoxPreference) findPreference(KEY_SILENT);
    mVibrate = (ListPreference) findPreference(KEY_VIBRATE);
    mVibrate.setOnPreferenceChangeListener(this);
    mVolumeControlSilent = (CheckBoxPreference) findPreference(KEY_VOLUME_CONTROL_SILENT);
    mVolumeControlSilent.setChecked(Settings.System.getInt(resolver, Settings.System.VOLUME_CONTROL_SILENT, 0) == 1);
    mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE);
    mDtmfTone.setPersistent(false);
    mDtmfTone.setChecked(Settings.System.getInt(resolver, Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0);
    mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS);
    mSoundEffects.setPersistent(false);
    mSoundEffects.setChecked(Settings.System.getInt(resolver, Settings.System.SOUND_EFFECTS_ENABLED, 0) != 0);
    mHapticFeedback = (CheckBoxPreference) findPreference(KEY_HAPTIC_FEEDBACK);
    mHapticFeedback.setPersistent(false);
    mHapticFeedback.setChecked(Settings.System.getInt(resolver, Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0);
    mLockSounds = (CheckBoxPreference) findPreference(KEY_LOCK_SOUNDS);
    mLockSounds.setPersistent(false);
    mLockSounds.setChecked(Settings.System.getInt(resolver, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) != 0);
    if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) {
        ListPreference emergencyTonePreference = (ListPreference) findPreference(KEY_EMERGENCY_TONE);
        emergencyTonePreference.setValue(String.valueOf(Settings.System.getInt(resolver, Settings.System.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE)));
        emergencyTonePreference.setOnPreferenceChangeListener(this);
    }
    mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);
    mNotificationPulse = (CheckBoxPreference) mSoundSettings.findPreference(KEY_NOTIFICATION_PULSE);
    mNotificationBlink = (CheckBoxPreference) mSoundSettings.findPreference(KEY_NOTIFICATION_BLINK);
    mNotificationAlwaysOn = (CheckBoxPreference) mSoundSettings.findPreference(KEY_NOTIFICATION_ALWAYS_ON);
    mNotificationCharging = (CheckBoxPreference) mSoundSettings.findPreference(KEY_NOTIFICATION_CHARGING);
    boolean amberGreenLight = getResources().getBoolean(com.android.internal.R.bool.config_amber_green_light);
    if (amberGreenLight) {
        mSoundSettings.removePreference(mNotificationPulse);
        mNotificationBlink.setChecked(Settings.System.getInt(resolver, Settings.System.NOTIFICATION_LIGHT_BLINK, 1) == 1);
        mNotificationBlink.setOnPreferenceChangeListener(this);
        mNotificationAlwaysOn.setChecked(Settings.System.getInt(resolver, Settings.System.NOTIFICATION_LIGHT_ALWAYS_ON, 1) == 1);
        mNotificationAlwaysOn.setOnPreferenceChangeListener(this);
        mNotificationCharging.setChecked(Settings.System.getInt(resolver, Settings.System.NOTIFICATION_LIGHT_CHARGING, 1) == 1);
        mNotificationCharging.setOnPreferenceChangeListener(this);
    } else {
        mSoundSettings.removePreference(mNotificationBlink);
        mSoundSettings.removePreference(mNotificationAlwaysOn);
        mSoundSettings.removePreference(mNotificationCharging);
        if (mNotificationPulse != null && getResources().getBoolean(R.bool.has_intrusive_led) == false) {
            mSoundSettings.removePreference(mNotificationPulse);
        } else {
            try {
                mNotificationPulse.setChecked(Settings.System.getInt(resolver, Settings.System.NOTIFICATION_LIGHT_PULSE) == 1);
                mNotificationPulse.setOnPreferenceChangeListener(this);
            } catch (SettingNotFoundException snfe) {
                Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
            }
        }
    }
}
Also used : ListPreference(android.preference.ListPreference) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) ContentResolver(android.content.ContentResolver)

Aggregations

ListPreference (android.preference.ListPreference)167 Preference (android.preference.Preference)80 CheckBoxPreference (android.preference.CheckBoxPreference)50 EditTextPreference (android.preference.EditTextPreference)35 PreferenceScreen (android.preference.PreferenceScreen)21 SharedPreferences (android.content.SharedPreferences)20 ArrayList (java.util.ArrayList)19 Intent (android.content.Intent)16 PreferenceCategory (android.preference.PreferenceCategory)16 SuppressLint (android.annotation.SuppressLint)13 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)9 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 File (java.io.File)8 Bundle (android.os.Bundle)7 SwitchPreference (android.preference.SwitchPreference)7 View (android.view.View)7 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 RingtonePreference (android.preference.RingtonePreference)6