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

The following examples show how to use android.preference.Preference#getOnPreferenceChangeListener() . 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: PreferencesNative.java    From javaide with GNU General Public License v3.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
 */
public static void bindPreferenceSummaryToValue(Preference preference) {
    if (preference == null) return;
    if (preference.getOnPreferenceChangeListener() == null) {
        // Set the listener to watch for value changes.
        preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
    }
    try {
        // Trigger the listener immediately with the preference's
        // current value.
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: KeyboardShortcutDialogPreference.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void notifyListener(String key, Object newValue) {
  Preference preference = getPreferenceManager().findPreference(key);
  if (preference == null || !(preference instanceof KeyboardShortcutDialogPreference)) {
    return;
  }

  OnPreferenceChangeListener listener = preference.getOnPreferenceChangeListener();
  if (listener != null) {
    listener.onPreferenceChange(preference, newValue);
  }
}
 
Example 3
Source File: PreferenceHelper.java    From xpra-client with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Allows to call a {@link OnPreferenceChangeListener}.
 * 
 * @param p
 * @param newValue
 * @return 
 */
public static boolean callChangeListener(Preference p, Object newValue) {
	OnPreferenceChangeListener listener = p.getOnPreferenceChangeListener();
	return listener == null ? true : listener.onPreferenceChange(p, newValue);
}
 
Example 4
Source File: PreferenceHelper.java    From xpra-client with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Allows to call a {@link OnPreferenceChangeListener}.
 * 
 * @param p
 * @param newValue
 * @return 
 */
public static boolean callChangeListener(Preference p, Object newValue) {
	OnPreferenceChangeListener listener = p.getOnPreferenceChangeListener();
	return listener == null || listener.onPreferenceChange(p, newValue);
}