Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/org/adblockplus/android/SummarizedPreferences.java

Issue 8363097: ABP/Android preferences UI (Closed) Base URL: https://hg.adblockplus.org/adblockplusandroid/
Patch Set: Created Sept. 14, 2012, 8:20 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/org/adblockplus/android/SummarizedPreferences.java
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/org/adblockplus/android/SummarizedPreferences.java
@@ -0,0 +1,74 @@
+package org.adblockplus.android;
+
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceGroup;
+import android.preference.PreferenceScreen;
+
+public class SummarizedPreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener
+{
+ @Override
+ public void onResume()
+ {
+ super.onResume();
+ // initialize list summaries
Felix Dahlke 2012/09/18 15:32:49 I don't think this comment is necessary.
+ initSummaries(getPreferenceScreen());
+ getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onPause()
+ {
+ super.onPause();
+ getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
+ {
+ Preference pref = findPreference(key);
+ setPrefSummary(pref);
+ }
+
+ protected void setPrefSummary(Preference pref)
+ {
+ if (pref instanceof ListPreference)
+ {
+ CharSequence summary = ((ListPreference) pref).getEntry();
+ if (summary != null)
+ {
+ pref.setSummary(summary);
+ }
+ }
+ if (pref instanceof EditTextPreference)
+ {
+ CharSequence summary = ((EditTextPreference) pref).getText();
+ if (summary != null)
+ {
+ pref.setSummary(summary);
+ }
+ }
+ }
+
+ protected void initSummaries(PreferenceGroup preference)
+ {
+ for (int i = preference.getPreferenceCount() - 1; i >= 0; i--)
+ {
+ Preference pref = preference.getPreference(i);
+
+ if (pref instanceof PreferenceGroup || pref instanceof PreferenceScreen)
+ {
+ initSummaries((PreferenceGroup) pref);
+ }
+ else
+ {
+ setPrefSummary(pref);
+ }
+ }
+ }
+
+}

Powered by Google App Engine
This is Rietveld