OLD | NEW |
(Empty) | |
| 1 package org.adblockplus.android; |
| 2 |
| 3 import android.content.SharedPreferences; |
| 4 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
| 5 import android.preference.EditTextPreference; |
| 6 import android.preference.ListPreference; |
| 7 import android.preference.Preference; |
| 8 import android.preference.PreferenceActivity; |
| 9 import android.preference.PreferenceGroup; |
| 10 import android.preference.PreferenceScreen; |
| 11 |
| 12 public class SummarizedPreferences extends PreferenceActivity implements OnShare
dPreferenceChangeListener |
| 13 { |
| 14 @Override |
| 15 public void onResume() |
| 16 { |
| 17 super.onResume(); |
| 18 // initialize list summaries |
| 19 initSummaries(getPreferenceScreen()); |
| 20 getPreferenceScreen().getSharedPreferences().registerOnSharedPre
ferenceChangeListener(this); |
| 21 } |
| 22 |
| 23 @Override |
| 24 public void onPause() |
| 25 { |
| 26 super.onPause(); |
| 27 getPreferenceScreen().getSharedPreferences().unregisterOnSharedP
referenceChangeListener(this); |
| 28 } |
| 29 |
| 30 @Override |
| 31 public void onSharedPreferenceChanged(SharedPreferences sharedPreference
s, String key) |
| 32 { |
| 33 Preference pref = findPreference(key); |
| 34 setPrefSummary(pref); |
| 35 } |
| 36 |
| 37 protected void setPrefSummary(Preference pref) |
| 38 { |
| 39 if (pref instanceof ListPreference) |
| 40 { |
| 41 CharSequence summary = ((ListPreference) pref).getEntry(
); |
| 42 if (summary != null) |
| 43 { |
| 44 pref.setSummary(summary); |
| 45 } |
| 46 } |
| 47 if (pref instanceof EditTextPreference) |
| 48 { |
| 49 CharSequence summary = ((EditTextPreference) pref).getTe
xt(); |
| 50 if (summary != null) |
| 51 { |
| 52 pref.setSummary(summary); |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 protected void initSummaries(PreferenceGroup preference) |
| 58 { |
| 59 for (int i = preference.getPreferenceCount() - 1; i >= 0; i--) |
| 60 { |
| 61 Preference pref = preference.getPreference(i); |
| 62 |
| 63 if (pref instanceof PreferenceGroup || pref instanceof P
referenceScreen) |
| 64 { |
| 65 initSummaries((PreferenceGroup) pref); |
| 66 } |
| 67 else |
| 68 { |
| 69 setPrefSummary(pref); |
| 70 } |
| 71 } |
| 72 } |
| 73 |
| 74 } |
OLD | NEW |