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

Side by Side Diff: src/org/adblockplus/android/SummarizedPreferences.java

Issue 8493083: ABP/Android UI (Closed)
Patch Set: Created Oct. 5, 2012, 9:42 a.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 /**
13 * PreferencesActivity which automatically sets preference summaries according
14 * to its current values.
15 */
16 public class SummarizedPreferences extends PreferenceActivity implements OnShare dPreferenceChangeListener
17 {
18 @Override
19 public void onResume()
20 {
21 super.onResume();
22 // initialize list summaries
Felix Dahlke 2012/10/09 14:27:29 Why not call initSummaries() initListSummaries() t
Andrey Novikov 2012/10/12 13:19:14 The comment was wrong, I've coped it from my old c
23 initSummaries(getPreferenceScreen());
24 getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChang eListener(this);
25 }
26
27 @Override
28 public void onPause()
29 {
30 super.onPause();
31 getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceCha ngeListener(this);
32 }
33
34 @Override
35 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key)
36 {
37 Preference pref = findPreference(key);
38 setPrefSummary(pref);
39 }
40
41 protected void setPrefSummary(Preference pref)
42 {
43 if (pref instanceof ListPreference)
44 {
45 CharSequence summary = ((ListPreference) pref).getEntry();
46 if (summary != null)
47 {
48 pref.setSummary(summary);
49 }
50 }
51 if (pref instanceof EditTextPreference)
52 {
53 CharSequence summary = ((EditTextPreference) pref).getText();
54 if (summary != null)
55 {
56 pref.setSummary(summary);
57 }
58 }
59 }
60
61 protected void initSummaries(PreferenceGroup preference)
62 {
63 for (int i = preference.getPreferenceCount() - 1; i >= 0; i--)
64 {
65 Preference pref = preference.getPreference(i);
66
67 if (pref instanceof PreferenceGroup || pref instanceof PreferenceScreen)
68 {
69 initSummaries((PreferenceGroup) pref);
70 }
71 else
72 {
73 setPrefSummary(pref);
74 }
75 }
76 }
77
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld