Search in sources :

Example 36 with EditTextPreference

use of android.preference.EditTextPreference in project Anki-Android by Ramblurr.

the class CramDeckOptions method updateSummaries.

protected void updateSummaries() {
    mAllowCommit = false;
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry().toString();
        } else {
            value = this.mPref.getString(key, "");
        }
        // update value for EditTexts
        if (pref instanceof EditTextPreference) {
            ((EditTextPreference) pref).setText(value);
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    mAllowCommit = true;
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) StepsPreference(com.ichi2.preferences.StepsPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference)

Example 37 with EditTextPreference

use of android.preference.EditTextPreference in project double-espresso by JakeWharton.

the class PreferenceMatchersTest method testIsEnabled.

public void testIsEnabled() {
    CheckBoxPreference pref = new CheckBoxPreference(getInstrumentation().getContext());
    pref.setEnabled(true);
    assertThat(pref, isEnabled());
    pref.setEnabled(false);
    assertThat(pref, not(isEnabled()));
    EditTextPreference pref2 = new EditTextPreference(getInstrumentation().getContext());
    pref2.setEnabled(true);
    assertThat(pref2, isEnabled());
    pref2.setEnabled(false);
    assertThat(pref2, not(isEnabled()));
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference)

Example 38 with EditTextPreference

use of android.preference.EditTextPreference in project KeepScore by nolanlawson.

the class SettingsActivity method setUpPreferences.

private void setUpPreferences() {
    plusButtonPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_plus_button);
    minusButtonPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_minus_button);
    button1Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_1);
    button2Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_2);
    button3Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_3);
    button4Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_button_4);
    twoPlayerButton1Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_1);
    twoPlayerButton2Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_2);
    twoPlayerButton3Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_3);
    twoPlayerButton4Pref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_2p_button_4);
    greenTextPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_green_text);
    showRoundTotalsPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_show_round_totals);
    showInitialMessagePref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_initial_message);
    disableHighlightTagPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_disable_highlight_tag);
    showColorsPref = (CheckBoxPreference) findPreferenceById(R.string.CONSTANT_pref_show_colors);
    updateDelayPref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_update_delay);
    initialScorePref = (EditTextPreference) findPreferenceById(R.string.CONSTANT_pref_initial_score);
    resetPref = findPreferenceById(R.string.CONSTANT_pref_reset);
    aboutPref = findPreferenceById(R.string.CONSTANT_pref_about);
    colorSchemePref = (ListPreference) findPreferenceById(R.string.CONSTANT_pref_color_scheme);
    orientationPref = (ListPreference) findPreferenceById(R.string.CONSTANT_pref_orientation);
    loadSettingsPref = findPreferenceById(R.string.CONSTANT_pref_load_settings);
    saveSettingsPref = findPreferenceById(R.string.CONSTANT_pref_save_settings);
    // changed
    for (EditTextPreference pref : new EditTextPreference[] { button1Pref, button2Pref, button3Pref, button4Pref, twoPlayerButton1Pref, twoPlayerButton2Pref, twoPlayerButton3Pref, twoPlayerButton4Pref, plusButtonPref, minusButtonPref }) {
        setDynamicSummary(pref);
    }
    // do a special check for the update delay value
    updateDelayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!IntegerUtil.validInt(newValue.toString()) || Integer.parseInt(newValue.toString()) < 1 || Integer.parseInt(newValue.toString()) > 600) {
                ToastHelper.showLong(SettingsActivity.this, R.string.toast_valid_update_delay_values);
                return false;
            }
            PreferenceHelper.resetCache();
            return true;
        }
    });
    // do another special check for the initial score value
    initialScorePref.setSummary(initialScorePref.getText());
    initialScorePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!IntegerUtil.validInt(newValue.toString())) {
                ToastHelper.showLong(SettingsActivity.this, R.string.toast_valid_initial_score);
                return false;
            }
            preference.setSummary(newValue.toString());
            return true;
        }
    });
    // show the version number in the "about" summary text
    String version = String.format(getString(R.string.text_version_number), PackageHelper.getVersionName(this));
    aboutPref.setSummary(version);
    // do a special popup for the reset preference
    resetPref.setOnPreferenceClickListener(this);
    loadSettingsPref.setOnPreferenceClickListener(this);
    saveSettingsPref.setOnPreferenceClickListener(this);
    setDynamicListPreferenceSummary(colorSchemePref);
    setDynamicListPreferenceSummary(orientationPref);
    // go to the about activity if the about pref is pressed
    aboutPref.setOnPreferenceClickListener(this);
    greenTextPref.setOnPreferenceChangeListener(this);
    showRoundTotalsPref.setOnPreferenceChangeListener(this);
    disableHighlightTagPref.setOnPreferenceChangeListener(this);
    showInitialMessagePref.setOnPreferenceChangeListener(this);
    showColorsPref.setOnPreferenceChangeListener(this);
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) EditTextPreference(android.preference.EditTextPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 39 with EditTextPreference

use of android.preference.EditTextPreference in project diary by billthefarmer.

the class SettingsFragment method onSharedPreferenceChanged.

// On shared preference changed
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
    if (key.equals(Settings.PREF_FOLDER)) {
        // Get folder summary
        EditTextPreference folder = (EditTextPreference) findPreference(key);
        // Set folder in text view
        folder.setSummary(preferences.getString(key, Diary.DIARY));
    }
    if (key.equals(Settings.PREF_INDEX_PAGE)) {
        // Get index preference
        DatePickerPreference entry = (DatePickerPreference) findPreference(key);
        // Get value
        long value = preferences.getLong(key, DatePickerPreference.DEFAULT_VALUE);
        Date date = new Date(value);
        // Set summary
        DateFormat format = DateFormat.getDateInstance();
        String s = format.format(date);
        entry.setSummary(s);
    }
    if (key.equals(Settings.PREF_TEMPLATE_PAGE)) {
        // Get template preference
        DatePickerPreference entry = (DatePickerPreference) findPreference(key);
        // Get value
        long value = preferences.getLong(key, DatePickerPreference.DEFAULT_VALUE);
        Date date = new Date(value);
        // Set summary
        DateFormat format = DateFormat.getDateInstance();
        String s = format.format(date);
        entry.setSummary(s);
    }
    if (key.equals(Settings.PREF_DARK_THEME)) {
        if (Build.VERSION.SDK_INT != Build.VERSION_CODES.M)
            getActivity().recreate();
    }
}
Also used : DateFormat(java.text.DateFormat) EditTextPreference(android.preference.EditTextPreference) Date(java.util.Date)

Example 40 with EditTextPreference

use of android.preference.EditTextPreference in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class Settings method onStart.

@Override
protected void onStart() {
    Log.d(MetaWatch.TAG, "set onstart");
    editTextMac = (EditTextPreference) preferenceScreen.findPreference("MAC");
    editTextMac.setText(MetaWatchService.Preferences.watchMacAddress);
    discovery = preferenceScreen.findPreference("Discovery");
    discovery.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            Log.d(MetaWatch.TAG, "discovery click");
            startActivity(new Intent(context, DeviceSelection.class));
            return false;
        }
    });
    super.onStart();
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) EditTextPreference(android.preference.EditTextPreference) Preference(android.preference.Preference) Intent(android.content.Intent)

Aggregations

EditTextPreference (android.preference.EditTextPreference)77 ListPreference (android.preference.ListPreference)32 Preference (android.preference.Preference)32 CheckBoxPreference (android.preference.CheckBoxPreference)17 SharedPreferences (android.content.SharedPreferences)11 PreferenceScreen (android.preference.PreferenceScreen)11 Test (org.junit.Test)9 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)8 Intent (android.content.Intent)7 ArrayList (java.util.ArrayList)7 DialogInterface (android.content.DialogInterface)6 Bundle (android.os.Bundle)6 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)5 View (android.view.View)5 SwitchPreference (android.preference.SwitchPreference)4 EditText (android.widget.EditText)4 File (java.io.File)4 Activity (android.app.Activity)3 AlertDialog (android.app.AlertDialog)3