Example usage for android.preference ListPreference setDefaultValue

List of usage examples for android.preference ListPreference setDefaultValue

Introduction

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

Prototype

public void setDefaultValue(Object defaultValue) 

Source Link

Document

Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage.

Usage

From source file:com.nttec.everychan.chans.synch.SynchModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setEntries(DOMAINS);//www .  j a va2  s  . c  o  m
    domainPref.setEntryValues(DOMAINS);
    domainPref.setDefaultValue(DOMAINS[0]);
    preferenceGroup.addPreference(domainPref);
    super.addPreferencesOnScreen(preferenceGroup);
}

From source file:com.nttec.everychan.chans.dobrochan.DobroModule.java

private void addRatingPreference(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateRatingListener = new Preference.OnPreferenceChangeListener() {
        @Override/*from   w  w w  .j  a  va2 s  . c  o  m*/
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_MAX_RATING))) {
                setMaxRating((String) newValue);
                return true;
            }
            return false;
        }
    };
    ListPreference ratingPref = new LazyPreferences.ListPreference(context);
    ratingPref.setTitle(R.string.dobrochan_prefs_max_rating);
    ratingPref.setSummary(preferences.getString(getSharedKey(PREF_KEY_MAX_RATING), "R-15"));
    ratingPref.setEntries(RATINGS);
    ratingPref.setEntryValues(RATINGS);
    ratingPref.setDefaultValue("R-15");
    ratingPref.setKey(getSharedKey(PREF_KEY_MAX_RATING));
    ratingPref.setOnPreferenceChangeListener(updateRatingListener);
    group.addPreference(ratingPref);
}

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   ww w .jav  a 2 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//ww  w. j  a  v  a  2 s. 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:com.nttec.everychan.chans.ponyach.PonyachModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    ListPreference captchaLevel = new LazyPreferences.ListPreference(context);
    captchaLevel.setTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setDialogTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setKey(getSharedKey(PREF_KEY_CAPTCHA_LEVEL));
    captchaLevel.setEntryValues(new String[] { "3", "2", "1" });
    captchaLevel.setEntries(new String[] { "Easy", "Easy++", "Medium" });
    captchaLevel.setDefaultValue("1");
    preferenceGroup.addPreference(captchaLevel);

    EditTextPreference passcodePref = new EditTextPreference(context);
    passcodePref.setTitle(R.string.ponyach_prefs_passcode);
    passcodePref.setDialogTitle(R.string.ponyach_prefs_passcode);
    passcodePref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
    passcodePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override/*  w w w  . j a v  a  2  s.c  o  m*/
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String newPasscode = (String) newValue;
            final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask();
            final ProgressDialog passAuthProgressDialog = new ProgressDialog(context);
            passAuthProgressDialog.setMessage("Logging in");
            passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    passAuthTask.cancel();
                }
            });
            passAuthProgressDialog.setCanceledOnTouchOutside(false);
            passAuthProgressDialog.show();
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (passAuthTask.isCancelled())
                            return;
                        String url = getUsingUrl() + "passcode.php";
                        List<BasicNameValuePair> pairs = Collections
                                .singletonList(new BasicNameValuePair("passcode_just_set", newPasscode));
                        HttpRequestModel request = HttpRequestModel.builder()
                                .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build();
                        HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, null,
                                passAuthTask, false);
                        savePhpCookies();
                    } catch (final Exception e) {
                        if (context instanceof Activity) {
                            ((Activity) context).runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String message = e.getMessage() == null
                                            ? resources.getString(R.string.error_unknown)
                                            : e.getMessage();
                                    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    } finally {
                        passAuthProgressDialog.dismiss();
                    }
                }
            });
            return false;
        }
    });
    preferenceGroup.addPreference(passcodePref);

    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setEntryValues(DOMAINS);
    domainPref.setEntries(DOMAINS);
    domainPref.setDefaultValue(DEFAULT_DOMAIN);
    domainPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            loadPhpCookies((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(domainPref);

    addHttpsPreference(preferenceGroup, useHttpsDefaultValue());
    addProxyPreferences(preferenceGroup);
    captchaLevel.setSummary(captchaLevel.getEntry());
    domainPref.setSummary(domainPref.getEntry());
}

From source file:co.taqat.call.AccountPreferencesFragment.java

private void initializeTransportPreference(ListPreference pref) {
    List<CharSequence> entries = new ArrayList<CharSequence>();
    List<CharSequence> values = new ArrayList<CharSequence>();
    entries.add(getString(R.string.pref_transport_udp));
    values.add(getString(R.string.pref_transport_udp_key));
    entries.add(getString(R.string.pref_transport_tcp));
    values.add(getString(R.string.pref_transport_tcp_key));

    if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
        entries.add(getString(R.string.pref_transport_tls));
        values.add(getString(R.string.pref_transport_tls_key));
    }/*from   ww  w . j a  v  a 2  s  . c om*/
    setListPreferenceValues(pref, entries, values);

    if (!isNewAccount) {
        pref.setSummary(mPrefs.getAccountTransportString(n));
        pref.setDefaultValue(mPrefs.getAccountTransportKey(n));
        pref.setValueIndex(entries.indexOf(mPrefs.getAccountTransportString(n)));
    } else {

        pref.setSummary(getString(R.string.pref_transport_udp));
        pref.setDefaultValue(getString(R.string.pref_transport_udp));
        pref.setValueIndex(entries.indexOf(getString(R.string.pref_transport_udp)));
    }
}

From source file:com.fastbootmobile.encore.app.fragments.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getPreferenceManager().setSharedPreferencesName(SettingsKeys.PREF_SETTINGS);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.settings);

    // Load Bluetooth paired devices
    final ListPreference btNameList = (ListPreference) findPreference(
            SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

    if (adapter == null) {
        // No Bluetooth adapter, remove preferences
        getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_ENABLE));
        getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_ACTION));
        getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME));
        getPreferenceScreen().removePreference(findPreference("category_bluetooth"));
    } else {/*from   w w w  .  ja  v a2  s .  co m*/
        Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
        CharSequence[] entries = new CharSequence[pairedDevices.size()];

        String currentPreferred = getPrefs().getString(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME, null);

        int i = 0;
        for (BluetoothDevice device : pairedDevices) {
            entries[i] = device.getName();
            ++i;
        }
        btNameList.setEntries(entries);
        btNameList.setEntryValues(entries);

        if (currentPreferred != null) {
            btNameList.setDefaultValue(currentPreferred);
        }
    }
}

From source file:jackpal.androidterm.TermPreferences.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    final TermSettings settings = new TermSettings(getResources(), mPrefs);
    if (mFirst && settings.getColorTheme() == 0)
        setTheme(R.style.Theme_AppCompat);
    mFirst = false;/*from www .j av  a  2  s .co m*/
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    if (FLAVOR_VIM) {
        addPreferencesFromResource(R.xml.preferences_apps);

        Resources res = getResources();
        String[] array = res.getStringArray(R.array.entries_app_filepicker_preference);

        OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Resources res = getResources();
                String[] array = res.getStringArray(R.array.entries_app_filepicker_preference);
                int value = Integer.valueOf((String) newValue);
                String summary = array[value];
                preference.setSummary(summary);
                return true;
            }
        };

        String id = "cloud_dropbox_filepicker";
        Preference filePicker = findPreference(id);
        String summary = array[settings.getDropboxFilePicker()];
        filePicker.setSummary(summary);
        filePicker.setOnPreferenceChangeListener(listener);

        id = "cloud_googledrive_filepicker";
        filePicker = findPreference(id);
        summary = array[settings.getGoogleDriveFilePicker()];
        filePicker.setSummary(summary);
        filePicker.setOnPreferenceChangeListener(listener);

        id = "cloud_onedrive_filepicker";
        filePicker = findPreference(id);
        summary = array[settings.getOneDriveFilePicker()];
        filePicker.setSummary(summary);
        filePicker.setOnPreferenceChangeListener(listener);

        id = "external_app_button";
        filePicker = findPreference(id);
        final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        OnPreferenceChangeListener AppButtonListener = new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                sp.edit().putBoolean(EXTERNAL_APP_BUTTON, (Boolean) newValue).apply();
                return true;
            }
        };
        filePicker.setOnPreferenceChangeListener(AppButtonListener);

        id = "external_app_package_name";
        Preference pref = getPreferenceScreen().findPreference(id);
        String appId = mPrefs.getString(id, "");
        setAppPickerLabel(pref, appId);
        new Thread() {
            @Override
            public void run() {
                setAppPickerList();
            }
        }.start();
        pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                setAppPickerLabel(preference, (String) newValue);
                return true;
            }
        });

    }

    if (AndroidCompat.SDK >= 19) {
        addPreferencesFromResource(R.xml.preferences_prefs);
        final String PREFS_KEY = "prefs_rw";
        Preference prefsPicker = getPreferenceScreen().findPreference(PREFS_KEY);
        prefsPicker.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                prefsPicker();
                return true;
            }
        });

        final String LICENSE_KEY = "license";
        Preference licensePrefs = getPreferenceScreen().findPreference(LICENSE_KEY);
        licensePrefs.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                licensePrefs();
                return true;
            }
        });
    }

    // Remove the action bar pref on older platforms without an action bar
    Preference actionBarPref = findPreference(ACTIONBAR_KEY);
    PreferenceCategory screenCategory = (PreferenceCategory) findPreference(CATEGORY_SCREEN_KEY);
    if ((actionBarPref != null) && (screenCategory != null)) {
        screenCategory.removePreference(actionBarPref);
    }

    Preference statusBarPref = findPreference(STATUSBAR_KEY);
    if ((statusBarPref != null) && (screenCategory != null)) {
        screenCategory.removePreference(statusBarPref);
    }

    PreferenceCategory keyboardCategory = (PreferenceCategory) findPreference("categoryKeyboard");
    Preference controlKeyPref = findPreference("controlkey");
    if ((controlKeyPref != null) && (keyboardCategory != null)) {
        keyboardCategory.removePreference(controlKeyPref);
    }
    Preference fnKeyPref = findPreference("fnkey");
    if ((fnKeyPref != null) && (keyboardCategory != null)) {
        keyboardCategory.removePreference(fnKeyPref);
    }

    if (FLAVOR_VIM) {
        findPreference("functionbar_vim_paste").setDefaultValue(true);
    }

    // FIXME:
    if (AndroidCompat.SDK < 19 && !new File(FONTPATH).exists())
        new File(FONTPATH).mkdirs();
    Preference fontPicker = getPreferenceScreen().findPreference("fontfile_picker");
    fontPicker.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            filePicker();
            return true;
        }
    });

    ListPreference fontFileList = (ListPreference) getPreferenceScreen().findPreference("fontfile");
    setFontList(fontFileList);

    Preference fontSelect = findPreference("fontfile");
    Resources res = getResources();
    fontSelect
            .setSummary(res.getString(R.string.summary_fontfile_preference) + String.format(" (%s)", FONTPATH));
    fontSelect.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ListPreference fontFileList = (ListPreference) preference;
            setFontList(fontFileList);
            return true;
        }
    });

    fontSelect.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            ListPreference fontFileList = (ListPreference) preference;
            setFontList(fontFileList);
            fontFileList.setDefaultValue(newValue);
            return true;
        }
    });

    PreferenceCategory textCategory = (PreferenceCategory) findPreference(CATEGORY_TEXT_KEY);
    Preference fontPref;
    if (AndroidCompat.SDK >= 19) {
        fontPref = findPreference("fontfile");
    } else {
        fontPref = findPreference("fontfile_picker");
    }
    if ((fontPref != null) && (textCategory != null)) {
        textCategory.removePreference(fontPref);
    }

}