Java Code Examples for android.preference.Preference#setOnPreferenceChangeListener()

The following examples show how to use android.preference.Preference#setOnPreferenceChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationActivity.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Accountant.getInstance(getActivity());
    getActivity().setTitle(getString(R.string.labs_title));
    addPreferencesFromResource(R.xml.lab_preferences);

    // Set whether the preference should be checked or not.
    Preference pref = findPreference("MediaControllerService");

    // For builds other than KitKat, hide RemoteController API.
    if (null != pref) pref.setOnPreferenceChangeListener(this);

    // Add out listeners and state change stuff.
    if (pref instanceof TwoStatePreference) {
        notifPref = (TwoStatePreference) pref;
        updateNotifPref();
    }
}
 
Example 2
Source File: SettingsActivity.java    From homeDash with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    if (preference instanceof SwitchPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getBoolean(preference.getKey(), false));
    } else {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    }

}
 
Example 3
Source File: SettingsFragment.java    From secrecy with Apache License 2.0 5 votes vote down vote up
private void preparePreferenceMaxImageSize(){
    Preference image_size = findPreference(Config.IMAGE_SIZE);
    image_size.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            Util.loadSelectedImageSize((String) o);
            return true;
        }
    });
}
 
Example 4
Source File: SuntimesSettingsActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private static void initPref_timeFormat(final Activity context, final Preference timeformatPref)
{
    timeformatPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o)
        {
            timeformatPref.setSummary(timeFormatPrefSummary(WidgetSettings.TimeFormatMode.valueOf((String)o), context));
            return true;
        }
    });
}
 
Example 5
Source File: PreferencesActivity.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 *
 * @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(), ""));
}
 
Example 6
Source File: UserSettingsActivity.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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.
 *
 * @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(), ""));
}
 
Example 7
Source File: SettingsActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
private void setPreferenceCategoryChangeListener(
        Preference category, Preference.OnPreferenceChangeListener listener) {
    PreferenceScreen ps = (PreferenceScreen) category;
    for (int i = 0; i < ps.getPreferenceCount(); i++) {
        Preference p = ps.getPreference(i);
        p.setOnPreferenceChangeListener(listener);
    }
}
 
Example 8
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void bindPreferenceSummaryToValueAndEnsureNumeric(Preference preference) {
    preference.setOnPreferenceChangeListener(sBindNumericPreferenceSummaryToValueListener);
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
            PreferenceManager
                    .getDefaultSharedPreferences(preference.getContext())
                    .getString(preference.getKey(), ""));
}
 
Example 9
Source File: SettingsActivity.java    From M365-Power with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 *
 * @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(), ""));
}
 
Example 10
Source File: Preferences.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private static void bindPreferenceSummaryToValue(Preference preference) {
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
            PreferenceManager
                    .getDefaultSharedPreferences(preference.getContext())
                    .getString(preference.getKey(), ""));
}
 
Example 11
Source File: MonitoringSettingsFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attaches a listener so the summary is always updated with the preference value.
 * Also fires the listener once, to initialize the summary (so it shows up before the value
 * is changed.)
 */
private void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes
    preference.setOnPreferenceChangeListener(this);
    // Update and set summary of the preference
    updatePreference(preference, null);
}
 
Example 12
Source File: PreferencesUtil.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
public static void bindPreferenceSummaryToValue(Preference preference) {
    if (preference == null) return;
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    try {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager.getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } catch (Exception e) {
    }
}
 
Example 13
Source File: SettingsActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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.
 * 
 * @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(),
					""));
}
 
Example 14
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void bindPreferenceTitleAppendToStringValue(Preference preference) {
    try {
        preference.setOnPreferenceChangeListener(sBindPreferenceTitleAppendToStringValueListener);
        sBindPreferenceTitleAppendToStringValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } catch (Exception e) {
        Log.e(TAG, "Got exception binding preference title: " + e.toString());
    }
}
 
Example 15
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void bindPreferenceTitleAppendToIntegerValue(Preference preference) {
    try {
        preference.setOnPreferenceChangeListener(sBindPreferenceTitleAppendToIntegerValueListener);
        sBindPreferenceTitleAppendToIntegerValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getInt(preference.getKey(), 0));
    } catch (Exception e) {
        Log.e(TAG, "Got exception binding preference title: " + e.toString());
    }
}
 
Example 16
Source File: SettingsActivity.java    From GitJourney with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 *
 * @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(), ""));
}
 
Example 17
Source File: SettingsActivity.java    From Weather with GNU General Public License v3.0 5 votes vote down vote up
private static void bindPreferenceSummaryToValue(Preference preference) {
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
            PreferenceManager
                    .getDefaultSharedPreferences(preference.getContext())
                    .getString(preference.getKey(), ""));
}
 
Example 18
Source File: BasePreferenceFragment.java    From Panoramic-Screenshot with GNU General Public License v3.0 4 votes vote down vote up
protected void register(Preference... preferences) {
	for (Preference p : preferences) {
		p.setOnPreferenceChangeListener(this);
		p.setOnPreferenceClickListener(this);
	}
}
 
Example 19
Source File: AdvancedSettingsActivity.java    From prevent with Do What The F*ck You Want To Public License 4 votes vote down vote up
private void setOnPreferenceChangeListener(String key) {
    Preference preference = DeprecatedUtils.findPreference(this, key);
    if (preference != null) {
        preference.setOnPreferenceChangeListener(this);
    }
}
 
Example 20
Source File: SettingsFragment.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
    sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
            preference.getContext().getSharedPreferences("CONFIG", Context.MODE_PRIVATE).getString(preference.getKey(), ""));
}