content: package com.example.android.quakereport;
  
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.preference.ListPreference;
  import android.preference.Preference;
  import android.preference.PreferenceFragment;
  import android.preference.PreferenceManager;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  
  public class SettingsActivity extends AppCompatActivity {
  
      private static String LOG_TAG = SettingsActivity.class.getSimpleName();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_settings);
      }
  
      public static class EarthquakePreferenceFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              addPreferencesFromResource(R.xml.settings_main);
  
              Preference minMagnitude = findPreference(getString(R.string.settings_min_magnitude_key));
              bindPreferenceSummaryToValue(minMagnitude);
  
              Preference orderBy = findPreference(getString(R.string.settings_order_by_key));
              bindPreferenceSummaryToValue(orderBy);
          }
  
          private void bindPreferenceSummaryToValue(Preference preference) {
              preference.setOnPreferenceChangeListener(this);
              SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(preference.getContext());
  
              String preferenceString = preferences.getString(preference.getKey(), "");
              onPreferenceChange(preference, preferenceString);
          }
  
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
              String stringValue = newValue.toString();
  
              Log.v(LOG_TAG, "String Value: " + stringValue);
  
              if (preference instanceof ListPreference) {
                  ListPreference listPreference = (ListPreference) preference;
                  int prefIndex = listPreference.findIndexOfValue(stringValue);
                  if (prefIndex >= 0) {
                      CharSequence[] labels = listPreference.getEntries();
                      Log.v(LOG_TAG, "Labels:  " + labels.length);
                      preference.setSummary(labels[prefIndex]);
                  }
              } else {
                  preference.setSummary(stringValue);
              }
              return true;
          }
      }
  }
  