private void initializeRingtonePreference() {
    Preference.OnPreferenceChangeListener ringtoneChangedListener =
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object value) {
            if ("".equals(value)) {
              preference.setSummary(R.string.silent);
            } else {
              Ringtone ringtone =
                  RingtoneManager.getRingtone(
                      ReminderPreferences.this,
                      value == null
                          ? RingtoneManager.getActualDefaultRingtoneUri(
                              getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION)
                          : Uri.parse((String) value));
              preference.setSummary(
                  ringtone == null ? "" : ringtone.getTitle(ReminderPreferences.this));
            }
            return true;
          }
        };

    String ringtoneKey = getString(R.string.p_rmd_ringtone);
    Preference ringtonePreference = findPreference(ringtoneKey);
    ringtonePreference.setOnPreferenceChangeListener(ringtoneChangedListener);
    ringtoneChangedListener.onPreferenceChange(
        ringtonePreference,
        PreferenceManager.getDefaultSharedPreferences(this).getString(ringtoneKey, null));
  }
  /**
   * 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.
   */
  public static void bindPreferenceSummaryToValue(SharedPreferences prefs, Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sSetSummaryListener);

    // Trigger the listener immediately with the preference's current value.
    sSetSummaryListener.onPreferenceChange(preference, prefs.getString(preference.getKey(), ""));
  }
  private static void bindPreferenceSummaryToValue(Preference preference) {
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    sBindPreferenceSummaryToValueListener.onPreferenceChange(
        preference,
        PreferenceManager.getDefaultSharedPreferences(preference.getContext())
            .getString(preference.getKey(), ""));
  }
  /**
   * 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, Object value) {
    // Set the listener to watch for value changes
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    if (value != null) {
      sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
    }
  }
  /*
   * 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(), ""));
  }
  /**
   * When the preference's value is changed, trigger the given listener. The listener is also
   * immediately called with the preference's current value upon calling this method.
   */
  public static void setAndCallPreferenceChangeListener(
      Preference preference, Preference.OnPreferenceChangeListener listener) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(listener);

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