- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (key.equals(KEY_PREF_DIFF)) {
- @SuppressWarnings("deprecation")
- Preference myPref = findPreference(key);
- // Set summary to be the user-description for the selected value
- myPref.setSummary(sharedPreferences.getString(key, ""));
- }
- if (key.equals(KEY_PREF_SIZE)) {
- @SuppressWarnings("deprecation")
- Preference myPref = findPreference(key);
- // Set summary to be the user-description for the selected value
- myPref.setSummary(sharedPreferences.getString(key, ""));
- }
- }
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties);
+ updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes);
+ }
+
+ private void updateSummary(SharedPreferences sharedPreferences, String changedkey, String mykey, int myresource) {
+ if (changedkey.equals(mykey)) {
+ // FIXME: handle NumberFormatException here?
+ int i = Integer.parseInt(sharedPreferences.getString(changedkey, "1"));
+
+ Resources res = getResources();
+ String[] mystrings = res.getStringArray(myresource);
+ String name = mystrings[i-1];
+
+ @SuppressWarnings("deprecation")
+ Preference myPref = findPreference(changedkey);
+ myPref.setSummary("Currently: " + name);
+ }
+ }