Example usage for android.preference ListPreference setValue

List of usage examples for android.preference ListPreference setValue

Introduction

In this page you can find the example usage for android.preference ListPreference setValue.

Prototype

public void setValue(String value) 

Source Link

Document

Sets the value of the key.

Usage

From source file:org.linphone.SettingsFragment.java

private void initAudioSettings() {
    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_codecs_key));
    if (codecs == null)
        return;//w w w  .  j  a v a2s . co  m

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getAudioCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());
        codec.setSummary(pt.getRate() + " Hz");
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(
            getString(R.string.pref_echo_cancellation_key));
    echoCancellation.setChecked(mPrefs.isEchoCancellationEnabled());

    if (mPrefs.isEchoCancellationEnabled()) {
        Preference echoCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
        echoCalibration
                .setSummary(String.format(getString(R.string.ec_calibrated), mPrefs.getEchoCalibration()));
    }

    CheckBoxPreference adaptiveRateControl = (CheckBoxPreference) findPreference(
            getString(R.string.pref_adaptive_rate_control_key));
    adaptiveRateControl.setChecked(mPrefs.isAdaptiveRateControlEnabled());

    ListPreference adaptiveRateAlgorithm = (ListPreference) findPreference(
            getString(R.string.pref_adaptive_rate_algorithm_key));
    adaptiveRateAlgorithm.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));
    adaptiveRateAlgorithm.setValue(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));

    ListPreference bitrateLimit = (ListPreference) findPreference(
            getString(R.string.pref_codec_bitrate_limit_key));
    bitrateLimit.setSummary(String.valueOf(mPrefs.getCodecBitrateLimit()));
    bitrateLimit.setValue(String.valueOf(mPrefs.getCodecBitrateLimit()));
}

From source file:org.linphone.SettingsFragment.java

private void initializePreferredVideoSizePreferences(ListPreference pref) {
    List<CharSequence> entries = new ArrayList<CharSequence>();
    List<CharSequence> values = new ArrayList<CharSequence>();
    for (String name : LinphoneManager.getLc().getSupportedVideoSizes()) {
        entries.add(name);/*from   w  w w.ja  v  a  2  s .  c om*/
        values.add(name);
    }

    setListPreferenceValues(pref, entries, values);

    String value = mPrefs.getPreferredVideoSize();
    if (pref != null) {
        pref.setSummary(value);
        pref.setValue(value);
    }
}

From source file:com.nttec.everychan.chans.allchan.AllchanModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addOnlyNewPostsPreference(preferenceGroup, true);
    final ListPreference captchaPreference = new LazyPreferences.ListPreference(context); //captcha_type
    captchaPreference.setTitle(R.string.pref_captcha_type);
    captchaPreference.setDialogTitle(R.string.pref_captcha_type);
    captchaPreference.setKey(getSharedKey(PREF_KEY_CAPTCHA_TYPE));
    captchaPreference.setEntryValues(CAPTCHA_TYPES_KEYS);
    captchaPreference.setEntries(CAPTCHA_TYPES);
    captchaPreference.setDefaultValue(CAPTCHA_TYPE_DEFAULT);
    int i = Arrays.asList(CAPTCHA_TYPES_KEYS)
            .indexOf(preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT));
    if (i >= 0)
        captchaPreference.setSummary(CAPTCHA_TYPES[i]);
    preferenceGroup.addPreference(captchaPreference);
    addHttpsPreference(preferenceGroup, true);
    addCloudflareRecaptchaFallbackPreference(preferenceGroup);
    addProxyPreferences(preferenceGroup);

    final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup
            .findPreference(getSharedKey(PREF_KEY_USE_PROXY));
    proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//from  w w  w  . ja  v  a2 s  .  c  o  m
        public boolean onPreferenceClick(Preference preference) {
            if (proxyPreference.isChecked() && captchaPreference.getValue().equals("recaptcha")) {
                captchaPreference.setValue("recaptcha-fallback");
            }
            return false;
        }
    });
    captchaPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (proxyPreference.isChecked() && newValue.equals("recaptcha")) {
                captchaPreference.setValue("recaptcha-fallback");
                return false;
            }
            return true;
        }
    });
}

From source file:nya.miku.wishmaster.chans.tumbach.TumbachModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addOnlyNewPostsPreference(preferenceGroup, true);
    final ListPreference captchaPreference = new LazyPreferences.ListPreference(context); //captcha_type
    captchaPreference.setTitle(R.string.pref_captcha_type);
    captchaPreference.setDialogTitle(R.string.pref_captcha_type);
    captchaPreference.setKey(getSharedKey(PREF_KEY_CAPTCHA_TYPE));
    captchaPreference.setEntryValues(CAPTCHA_TYPES_KEYS);
    captchaPreference.setEntries(CAPTCHA_TYPES);
    captchaPreference.setDefaultValue(CAPTCHA_TYPE_DEFAULT);
    int i = Arrays.asList(CAPTCHA_TYPES_KEYS)
            .indexOf(preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT));
    if (i >= 0)
        captchaPreference.setSummary(CAPTCHA_TYPES[i]);
    preferenceGroup.addPreference(captchaPreference);
    addPasswordPreference(preferenceGroup);
    addHttpsPreference(preferenceGroup, true);
    addCloudflareRecaptchaFallbackPreference(preferenceGroup);
    addProxyPreferences(preferenceGroup);

    final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup
            .findPreference(getSharedKey(PREF_KEY_USE_PROXY));
    proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/*from   w w  w .  j a v  a 2s. co m*/
        public boolean onPreferenceClick(Preference preference) {
            if (proxyPreference.isChecked() && captchaPreference.getValue().equals("recaptcha")) {
                captchaPreference.setValue("recaptcha-fallback");
            }
            return false;
        }
    });
    captchaPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (proxyPreference.isChecked() && newValue.equals("recaptcha")) {
                captchaPreference.setValue("recaptcha-fallback");
                return false;
            }
            return true;
        }
    });
}

From source file:org.linphone.SettingsFragment.java

private void initMediaEncryptionPreference(ListPreference pref) {
    List<CharSequence> entries = new ArrayList<CharSequence>();
    List<CharSequence> values = new ArrayList<CharSequence>();
    entries.add(getString(R.string.media_encryption_none));
    values.add(getString(R.string.pref_media_encryption_key_none));

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
        setListPreferenceValues(pref, entries, values);
        return;/*w w  w  .j  a  v a2s  .c o m*/
    }

    boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
    boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
    if (!hasSrtp && !hasZrtp) {
        pref.setEnabled(false);
    } else {
        if (hasSrtp) {
            entries.add(getString(R.string.media_encryption_srtp));
            values.add(getString(R.string.pref_media_encryption_key_srtp));
        }
        if (hasZrtp) {
            entries.add(getString(R.string.media_encryption_zrtp));
            values.add(getString(R.string.pref_media_encryption_key_zrtp));
        }
        setListPreferenceValues(pref, entries, values);
    }

    MediaEncryption value = mPrefs.getMediaEncryption();
    pref.setSummary(value.toString());

    String key = getString(R.string.pref_media_encryption_key_none);
    if (value.toString().equals(getString(R.string.media_encryption_srtp)))
        key = getString(R.string.pref_media_encryption_key_srtp);
    else if (value.toString().equals(getString(R.string.media_encryption_zrtp)))
        key = getString(R.string.pref_media_encryption_key_zrtp);
    pref.setValue(key);
}

From source file:com.olearyp.gusto.Expsetup.java

/** Called when the activity is first created. */
@Override//from w w w. j a v a2 s . c o m
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    settings = getSharedPreferences("serverState", MODE_PRIVATE);
    addPreferencesFromResource(R.xml.preferences);
    final Map<String, String> config = getCurrentConfig();

    // Tack version number on to titlebar at top level
    try {
        this.setTitle(getTitle() + " v" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
    } catch (final NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String ramhack_file;
    // ROM-specific settings
    if (config.get("GLB_EP_VERSION_EPDATA").contains("-TMO")) {
        findPreference("launcher").setEnabled(false);
        findPreference("phone").setEnabled(false);
        findPreference("contacts").setEnabled(false);
        findPreference("teeter").setEnabled(false);
        findPreference("quickoffice").setEnabled(false);
        ramhack_file = "10mb_kernel_patch_tmo262.zip";
    } else {
        ramhack_file = "10mb_kernel_patch_adp262.zip";
    }
    // QuickCommands menu
    {
        findPreference("reboot").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.reboot_alert_title, R.string.reboot_msg, R.string.reboot));
        findPreference("reboot_recovery").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.reboot_alert_title, R.string.reboot_recovery_msg, R.string.reboot_recovery));
        findPreference("reboot_bootloader").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.reboot_alert_title, R.string.reboot_bootloader_msg, R.string.reboot_bootload));
        findPreference("reboot_poweroff").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.shutdown_alert_title, R.string.shutdown_msg, R.string.shutdown));
        findPreference("rwsystem").setOnPreferenceClickListener(
                new ExpPreferenceListener(R.string.rwsystem, "setting /system read-write"));
        findPreference("rosystem").setOnPreferenceClickListener(
                new ExpPreferenceListener(R.string.rosystem, "setting /system read-only"));
    }
    // CPU options
    {
        findPreference("freq_sample").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | set_ep_cyan_ond_mod", "setting frequency scaling"));
        ((CheckBoxPreference) findPreference("freq_sample"))
                .setChecked(isTrueish(config, "GLB_EP_ENABLE_CYAN_OND_MOD"));
        final List<String> freqs = Arrays.asList(getResources().getStringArray(R.array.cpu_freqs_str));
        final ListPreference minFreqPref = (ListPreference) findPreference("cpu_freq_min");
        final ListPreference maxFreqPref = (ListPreference) findPreference("cpu_freq_max");
        minFreqPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                sendCommand("GLB_EP_MIN_CPU=" + newValue.toString() + " && " + "write_out_ep_config && "
                        + "echo \"$GLB_EP_MIN_CPU\" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq",
                        "setting minimum CPU frequency", "none");
                final String[] legalfreqs = freqs.subList(freqs.indexOf(newValue), freqs.size())
                        .toArray(new String[0]);
                maxFreqPref.setEntries(legalfreqs);
                maxFreqPref.setEntryValues(legalfreqs);
                return true;
            }
        });
        maxFreqPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                sendCommand("GLB_EP_MAX_CPU=" + newValue.toString() + " && " + "write_out_ep_config && "
                        + "echo \"$GLB_EP_MAX_CPU\" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq",
                        "setting maximum CPU frequency", "none");
                final String[] legalfreqs = freqs.subList(0, freqs.indexOf(newValue) + 1)
                        .toArray(new String[0]);
                minFreqPref.setEntries(legalfreqs);
                minFreqPref.setEntryValues(legalfreqs);
                return true;
            }
        });
        final String[] maxfreqs = freqs.subList(freqs.indexOf(config.get("GLB_EP_MIN_CPU")), freqs.size())
                .toArray(new String[0]);
        maxFreqPref.setEntries(maxfreqs);
        maxFreqPref.setEntryValues(maxfreqs);
        final String[] minfreqs = freqs.subList(0, freqs.indexOf(config.get("GLB_EP_MAX_CPU")) + 1)
                .toArray(new String[0]);
        minFreqPref.setEntries(minfreqs);
        minFreqPref.setEntryValues(minfreqs);
        maxFreqPref.setValue(config.get("GLB_EP_MAX_CPU"));
        minFreqPref.setValue(config.get("GLB_EP_MIN_CPU"));
    }
    // Downloadables
    {
        DownloadPreference p;
        p = ((DownloadPreference) findPreference("ramhack_kernel"));
        p.setParams(ASPIN_URL + "RESOURCE/" + ramhack_file, "/sdcard/" + ramhack_file);
        p.setOnPreferenceClickListener(new RamhackPreferenceListener(testRamhack(config), p));
        p = ((DownloadPreference) findPreference("kernel_mods"));
        p.setParams(ASPIN_URL + "ROM/kmods_v211_vsapp.zip", "/sdcard/epvsapps/available/kmods_v211_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/kmods_v211_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("teeter"));
        p.setParams(ASPIN_URL + "APPS/teeter_vsapp.zip", "/sdcard/epvsapps/available/teeter_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/teeter_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("quickoffice"));
        p.setParams(ASPIN_URL + "APPS/quickoffice_vsapp.zip",
                "/sdcard/epvsapps/available/quickoffice_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/quickoffice_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("ext_widgets"));
        p.setParams(ASPIN_URL + "APPS/widgetpack_v2_vsapp.zip",
                "/sdcard/epvsapps/available/widgetpack_v2_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/widgetpack_v2_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("xdan_java"));
        p.setParams(ASPIN_URL + "APPS/jbed_vsapp.zip", "/sdcard/epvsapps/available/jbed_vsapp.zip");
        p.setOnPreferenceClickListener(
                new VsappPreferenceListener(new File("/sdcard/epvsapps/available/jbed_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("iwnn_ime_jp"));
        p.setParams(ASPIN_URL + "APPS/iwnnime_vsapp.zip", "/sdcard/epvsapps/available/iwnnime_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/iwnnime_vsapp.zip").exists(), p));
    }
    // Theme profile settings
    {
        findPreference("launcher").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Launcher.apk", "changing Launcher"));
        ((CheckBoxPreference) findPreference("launcher")).setChecked(isTrueish(config, "Launcher.apk"));
        findPreference("phone").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Phone.apk", "changing Phone"));
        ((CheckBoxPreference) findPreference("phone")).setChecked(isTrueish(config, "Phone.apk"));
        findPreference("contacts").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Contacts.apk", "changing Contacts"));
        ((CheckBoxPreference) findPreference("contacts")).setChecked(isTrueish(config, "Contacts.apk"));
        findPreference("browser").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Browser.apk", "changing the Browser"));
        ((CheckBoxPreference) findPreference("browser")).setChecked(isTrueish(config, "Browser.apk"));
        findPreference("mms")
                .setOnPreferenceChangeListener(new ExpThemeProfileChangeListener("Mms.apk", "changing MMS"));
        ((CheckBoxPreference) findPreference("mms")).setChecked(isTrueish(config, "Mms.apk"));
    }
    // Advanced Options
    {
        // Swappiness
        findPreference("swappiness").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                sendCommand("yes '" + newValue.toString() + "' | set_ep_swappiness", "setting swappiness",
                        "none");
                return true;
            }
        });
        ((EditTextPreference) findPreference("swappiness")).setText(config.get("GLB_EP_SWAPPINESS"));
        ((EditTextPreference) findPreference("swappiness")).getEditText()
                .setKeyListener(new SwappinessKeyListener());
        // Compcache
        findPreference("compcache").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_compcache", "setting compcache", true));
        ((CheckBoxPreference) findPreference("compcache"))
                .setChecked(isTrueish(config, "GLB_EP_ENABLE_COMPCACHE"));
        // Linux swap
        findPreference("linux_swap").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_linuxswap", "setting Linux-swap"));
        ((CheckBoxPreference) findPreference("linux_swap"))
                .setChecked(isTrueish(config, "GLB_EP_ENABLE_LINUXSWAP"));
        // userinit.sh
        findPreference("userinit").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_userinit", "setting userinit"));
        ((CheckBoxPreference) findPreference("userinit")).setChecked(isTrueish(config, "GLB_EP_RUN_USERINIT"));
        // Remove odex on boot
        findPreference("odex").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_odex_boot_removal", "setting ODEX removal"));
        ((CheckBoxPreference) findPreference("odex")).setChecked(isTrueish(config, "GLB_EP_ODEX_BOOT_REMOVAL"));
        // Odex now
        findPreference("reodex").setOnPreferenceClickListener(
                new ExpPreferenceListener("yes | odex_ep_data_apps", "re-ODEXing apps"));
        // Set pid priorities
        findPreference("pid_prioritize").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_pid_prioritizer", "setting PID prioritizer"));
        ((CheckBoxPreference) findPreference("pid_prioritize"))
                .setChecked(isTrueish(config, "GLB_EP_PID_PRIORITIZE"));
    }
    // Generate and send ep_log
    findPreference("ep_log").setOnPreferenceClickListener(new EpLogListener());
}