OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 import android.content.SharedPreferences; | 22 import android.content.SharedPreferences; |
23 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; | 23 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
24 import android.preference.EditTextPreference; | 24 import android.preference.EditTextPreference; |
25 import android.preference.ListPreference; | 25 import android.preference.ListPreference; |
26 import android.preference.Preference; | 26 import android.preference.Preference; |
27 import android.preference.PreferenceGroup; | 27 import android.preference.PreferenceGroup; |
28 import android.preference.PreferenceScreen; | 28 import android.preference.PreferenceScreen; |
29 | 29 |
30 /** | 30 /** |
31 * PreferencesActivity which automatically sets preference summaries according | 31 * PreferencesActivity which automatically sets preference summaries according t
o its current |
32 * to its current values. | 32 * values. |
33 */ | 33 */ |
34 public class SummarizedPreferences extends SherlockPreferenceActivity implements
OnSharedPreferenceChangeListener | 34 public class SummarizedPreferences extends SherlockPreferenceActivity implements
OnSharedPreferenceChangeListener |
35 { | 35 { |
| 36 @SuppressWarnings("deprecation") |
36 @Override | 37 @Override |
37 public void onResume() | 38 public void onResume() |
38 { | 39 { |
39 super.onResume(); | 40 super.onResume(); |
40 initSummaries(getPreferenceScreen()); | 41 initSummaries(getPreferenceScreen()); |
41 getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChang
eListener(this); | 42 getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChang
eListener(this); |
42 } | 43 } |
43 | 44 |
| 45 @SuppressWarnings("deprecation") |
44 @Override | 46 @Override |
45 public void onPause() | 47 public void onPause() |
46 { | 48 { |
47 super.onPause(); | 49 super.onPause(); |
48 getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceCha
ngeListener(this); | 50 getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceCha
ngeListener(this); |
49 } | 51 } |
50 | 52 |
51 @Override | 53 @Override |
52 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str
ing key) | 54 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
s, final String key) |
53 { | 55 { |
54 Preference pref = findPreference(key); | 56 @SuppressWarnings("deprecation") |
| 57 final Preference pref = findPreference(key); |
55 setPrefSummary(pref); | 58 setPrefSummary(pref); |
56 } | 59 } |
57 | 60 |
58 protected void setPrefSummary(Preference pref) | 61 protected void setPrefSummary(final Preference pref) |
59 { | 62 { |
60 if (pref instanceof ListPreference) | 63 if (pref instanceof ListPreference) |
61 { | 64 { |
62 CharSequence summary = ((ListPreference) pref).getEntry(); | 65 final CharSequence summary = ((ListPreference) pref).getEntry(); |
63 if (summary != null) | 66 if (summary != null) |
64 { | 67 { |
65 pref.setSummary(summary); | 68 pref.setSummary(summary); |
66 } | 69 } |
67 } | 70 } |
68 if (pref instanceof EditTextPreference) | 71 if (pref instanceof EditTextPreference) |
69 { | 72 { |
70 CharSequence summary = ((EditTextPreference) pref).getText(); | 73 final CharSequence summary = ((EditTextPreference) pref).getText(); |
71 if (summary != null) | 74 if (summary != null) |
72 { | 75 { |
73 pref.setSummary(summary); | 76 pref.setSummary(summary); |
74 } | 77 } |
75 } | 78 } |
76 } | 79 } |
77 | 80 |
78 protected void initSummaries(PreferenceGroup preference) | 81 protected void initSummaries(final PreferenceGroup preference) |
79 { | 82 { |
80 for (int i = preference.getPreferenceCount() - 1; i >= 0; i--) | 83 for (int i = preference.getPreferenceCount() - 1; i >= 0; i--) |
81 { | 84 { |
82 Preference pref = preference.getPreference(i); | 85 final Preference pref = preference.getPreference(i); |
83 | 86 |
84 if (pref instanceof PreferenceGroup || pref instanceof PreferenceScreen) | 87 if (pref instanceof PreferenceGroup || pref instanceof PreferenceScreen) |
85 { | 88 { |
86 initSummaries((PreferenceGroup) pref); | 89 initSummaries((PreferenceGroup) pref); |
87 } | 90 } |
88 else | 91 else |
89 { | 92 { |
90 setPrefSummary(pref); | 93 setPrefSummary(pref); |
91 } | 94 } |
92 } | 95 } |
93 } | 96 } |
94 | 97 |
95 } | 98 } |
OLD | NEW |