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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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
Felix Dahlke 2012/09/18 15:32:49 I don't think this comment is necessary.
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld