Example usage for android.preference Preference setOnPreferenceChangeListener

List of usage examples for android.preference Preference setOnPreferenceChangeListener

Introduction

In this page you can find the example usage for android.preference Preference setOnPreferenceChangeListener.

Prototype

public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener) 

Source Link

Document

Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).

Usage

From source file:Main.java

/**
 * Gets a preference and sets the {@link android.preference.Preference.OnPreferenceChangeListener}.
 */// ww w.  j  ava2 s.  c om
public static Preference getPrefAndSetChangeListener(PreferenceFragment prefFrag, int id,
        Preference.OnPreferenceChangeListener listener) {
    Preference pref = prefFrag.findPreference(prefFrag.getString(id));
    if (pref != null)
        pref.setOnPreferenceChangeListener(listener);
    return pref;
}

From source file:org.projectbuendia.client.ui.SettingsActivity.java

/**
 * Shows a preference's string value on its summary line (below the title
 * of the preference), and keep the summary updated when the value changes.
 *
 * @see #sListener/*from w  ww . ja v a 2  s  . com*/
 */
private static void showValueAsSummary(Preference pref) {
    // Set the listener to watch for value changes.
    pref.setOnPreferenceChangeListener(sListener);

    // Trigger the listener immediately with the preference's current value.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(pref.getContext());
    sListener.onPreferenceChange(pref, prefs.getAll().get(pref.getKey()));
}

From source file:com.concavenp.nanodegree.popularmovies.SettingsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference./*ww  w .j a v a2 s  .  c om*/
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference, String defaultValue) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
            .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), defaultValue));
}

From source file:org.segin.ttleditor.SettingsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference./*from   w w  w . j  a  va2  s  . c  o m*/
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger thelistener  immediately with the preference's
    // current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
            .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
}

From source file:com.ofalvai.bpinfo.ui.settings.SettingsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.//from w  w  w. j a  v a  2  s. c om
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(@NonNull Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
            .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
}

From source file:com.xengar.android.englishverbs.ui.SettingsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.// w ww . j  a  v  a2s  .  co m
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference' current value.
    if (preference instanceof ListPreference || preference instanceof EditTextPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
                .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
    } else if (preference instanceof SwitchPreference || preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
                .getDefaultSharedPreferences(preference.getContext()).getBoolean(preference.getKey(), true));
    }
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.settings.PrefsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.//from w  w  w .j av  a2  s.  c  om
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
public static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
            .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
}

From source file:de.domjos.schooltools.activities.SettingsActivity.java

private static void bindPreferenceSummaryToValueSet(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
            PreferenceManager.getDefaultSharedPreferences(preference.getContext())
                    .getStringSet(preference.getKey(), new HashSet<String>()));
}

From source file:com.xengar.android.stocktracker.ui.SettingsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.//from   w ww  .  j  a v  a  2s  . c  o  m
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's current value.
    if (preference instanceof ListPreference || preference instanceof EditTextPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
                .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
    } else if (preference instanceof SwitchPreference || preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
                .getDefaultSharedPreferences(preference.getContext()).getBoolean(preference.getKey(), true));
    }
}

From source file:com.example.android.DroidCafeWithSettings.SettingsActivity.java

/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference./*from   www .  j  a  v  a2 s . c o  m*/
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's current value.
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager
            .getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
}