Left: | ||
Right: |
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 27 matching lines...) Expand all Loading... | |
38 import android.text.TextUtils; | 38 import android.text.TextUtils; |
39 import android.util.Log; | 39 import android.util.Log; |
40 import android.view.View; | 40 import android.view.View; |
41 import android.widget.ScrollView; | 41 import android.widget.ScrollView; |
42 import android.widget.TextView; | 42 import android.widget.TextView; |
43 import android.widget.Toast; | 43 import android.widget.Toast; |
44 | 44 |
45 /** | 45 /** |
46 * Advanced settings UI. | 46 * Advanced settings UI. |
47 */ | 47 */ |
48 @SuppressWarnings("deprecation") | |
48 public class AdvancedPreferences extends SummarizedPreferences | 49 public class AdvancedPreferences extends SummarizedPreferences |
49 { | 50 { |
50 private static final String TAG = "AdvancedPreferences"; | 51 private final static String TAG = Utils.getTag(AdvancedPreferences.class); |
51 | 52 private final static int CONFIGURATION_DIALOG = 1; |
52 private static final int CONFIGURATION_DIALOG = 1; | |
53 | 53 |
54 private ProxyService proxyService = null; | 54 private ProxyService proxyService = null; |
55 | 55 |
56 @Override | 56 @Override |
57 public void onCreate(Bundle savedInstanceState) | 57 public void onCreate(final Bundle savedInstanceState) |
58 { | 58 { |
59 super.onCreate(savedInstanceState); | 59 super.onCreate(savedInstanceState); |
60 | 60 |
61 addPreferencesFromResource(R.xml.preferences_advanced); | 61 this.addPreferencesFromResource(R.xml.preferences_advanced); |
Felix Dahlke
2014/04/16 15:24:25
ALso a bunch of unrelated changes here, same as be
René Jeschke
2014/04/16 17:51:47
Done.
| |
62 | 62 |
63 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); | 63 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); |
64 | 64 |
65 PreferenceScreen screen = getPreferenceScreen(); | 65 final PreferenceScreen screen = this.getPreferenceScreen(); |
66 if (ProxyService.NATIVE_PROXY_SUPPORTED) | 66 if (ProxyService.NATIVE_PROXY_SUPPORTED) |
67 { | 67 { |
68 screen.removePreference(findPreference(getString(R.string.pref_proxy))); | 68 screen.removePreference(this.findPreference(this.getString(R.string.pref_p roxy))); |
69 if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) | 69 if (prefs.getBoolean(this.getString(R.string.pref_proxyautoconfigured), fa lse)) |
70 { | 70 { |
71 screen.removePreference(findPreference(getString(R.string.pref_proxyenab led))); | 71 screen.removePreference(this.findPreference(this.getString(R.string.pref _proxyenabled))); |
72 } | 72 } |
73 } | 73 } |
74 if (getResources().getBoolean(R.bool.def_release)) | 74 if (this.getResources().getBoolean(R.bool.def_release)) |
75 { | 75 { |
76 screen.removePreference(findPreference(getString(R.string.pref_support))); | 76 screen.removePreference(this.findPreference(this.getString(R.string.pref_s upport))); |
77 } | 77 } |
78 else | 78 else |
79 { | 79 { |
80 Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate )); | 80 final Preference prefUpdate = this.findPreference(this.getString(R.string. pref_checkupdate)); |
81 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() | 81 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() |
82 { | 82 { |
83 public boolean onPreferenceClick(Preference preference) | 83 @Override |
Felix Dahlke
2014/04/16 15:24:25
Does that mean we're on Java 6 now?
René Jeschke
2014/04/16 17:51:47
The whole code base (please have a look) is a mixt
| |
84 public boolean onPreferenceClick(final Preference preference) | |
84 { | 85 { |
85 AdblockPlus application = AdblockPlus.getApplication(); | 86 final AdblockPlus application = AdblockPlus.getApplication(); |
86 application.checkUpdates(); | 87 application.checkUpdates(); |
87 return true; | 88 return true; |
88 } | 89 } |
89 }); | 90 }); |
90 | 91 |
91 Preference prefConfiguration = findPreference(getString(R.string.pref_conf iguration)); | 92 final Preference prefConfiguration = this.findPreference(this.getString(R. string.pref_configuration)); |
92 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er() | 93 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er() |
93 { | 94 { |
94 public boolean onPreferenceClick(Preference preference) | 95 @Override |
96 public boolean onPreferenceClick(final Preference preference) | |
95 { | 97 { |
96 showDialog(CONFIGURATION_DIALOG); | 98 AdvancedPreferences.this.showDialog(CONFIGURATION_DIALOG); |
97 return true; | 99 return true; |
98 } | 100 } |
99 }); | 101 }); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 @Override | 105 @Override |
104 public void onResume() | 106 public void onResume() |
105 { | 107 { |
106 super.onResume(); | 108 super.onResume(); |
107 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); | 109 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); |
108 int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_refres h), "0")); | 110 final int refresh = Integer.valueOf(prefs.getString(this.getString(R.string. pref_refresh), "0")); |
109 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ; | 111 this.findPreference(this.getString(R.string.pref_wifirefresh)).setEnabled(re fresh > 0); |
110 connect(); | 112 this.connect(); |
111 } | 113 } |
112 | 114 |
113 @Override | 115 @Override |
114 public void onPause() | 116 public void onPause() |
115 { | 117 { |
116 super.onPause(); | 118 super.onPause(); |
117 disconnect(); | 119 this.disconnect(); |
118 } | 120 } |
119 | 121 |
120 @Override | 122 @Override |
121 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key) | 123 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference s, final String key) |
122 { | 124 { |
123 if (getString(R.string.pref_proxyenabled).equals(key)) | 125 if (this.getString(R.string.pref_proxyenabled).equals(key)) |
124 { | 126 { |
125 AdblockPlus application = AdblockPlus.getApplication(); | 127 final AdblockPlus application = AdblockPlus.getApplication(); |
126 boolean enabled = sharedPreferences.getBoolean(key, false); | 128 final boolean enabled = sharedPreferences.getBoolean(key, false); |
127 boolean serviceRunning = application.isServiceRunning(); | 129 final boolean serviceRunning = application.isServiceRunning(); |
128 if (enabled) | 130 if (enabled) |
129 { | 131 { |
130 if (!serviceRunning) | 132 if (!serviceRunning) |
131 startService(new Intent(this, ProxyService.class)); | 133 { |
134 this.startService(new Intent(this, ProxyService.class)); | |
135 } | |
132 } | 136 } |
133 else | 137 else |
134 { | 138 { |
135 if (serviceRunning) | 139 if (serviceRunning) |
136 stopService(new Intent(this, ProxyService.class)); | 140 { |
141 this.stopService(new Intent(this, ProxyService.class)); | |
142 } | |
137 // If disabled, disable filtering as well | 143 // If disabled, disable filtering as well |
138 SharedPreferences.Editor editor = sharedPreferences.edit(); | 144 final SharedPreferences.Editor editor = sharedPreferences.edit(); |
139 editor.putBoolean(getString(R.string.pref_enabled), false); | 145 editor.putBoolean(this.getString(R.string.pref_enabled), false); |
140 editor.commit(); | 146 editor.commit(); |
141 application.setFilteringEnabled(false); | 147 application.setFilteringEnabled(false); |
142 } | 148 } |
143 } | 149 } |
144 if (getString(R.string.pref_refresh).equals(key)) | 150 if (this.getString(R.string.pref_refresh).equals(key)) |
145 { | 151 { |
146 int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")); | 152 final int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")) ; |
147 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); | 153 this.findPreference(this.getString(R.string.pref_wifirefresh)).setEnabled( refresh > 0); |
148 } | 154 } |
149 if (getString(R.string.pref_crashreport).equals(key)) | 155 if (this.getString(R.string.pref_crashreport).equals(key)) |
150 { | 156 { |
151 boolean report = sharedPreferences.getBoolean(key, getResources().getBoole an(R.bool.def_crashreport)); | 157 final boolean report = sharedPreferences.getBoolean(key, this.getResources ().getBoolean(R.bool.def_crashreport)); |
152 try | 158 try |
153 { | 159 { |
154 CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtException Handler(); | 160 final CrashHandler handler = (CrashHandler)Thread.getDefaultUncaughtExce ptionHandler(); |
155 handler.generateReport(report); | 161 handler.generateReport(report); |
156 } | 162 } |
157 catch (ClassCastException e) | 163 catch (final ClassCastException e) |
158 { | 164 { |
159 // ignore - default handler in use | 165 // ignore - default handler in use |
160 } | 166 } |
161 } | 167 } |
162 super.onSharedPreferenceChanged(sharedPreferences, key); | 168 super.onSharedPreferenceChanged(sharedPreferences, key); |
163 } | 169 } |
164 | 170 |
165 @Override | 171 @Override |
166 protected Dialog onCreateDialog(int id) | 172 protected Dialog onCreateDialog(final int id) |
167 { | 173 { |
168 Dialog dialog = null; | 174 Dialog dialog = null; |
169 switch (id) | 175 switch (id) |
170 { | 176 { |
171 case CONFIGURATION_DIALOG: | 177 case CONFIGURATION_DIALOG: |
172 List<String> items = new ArrayList<String>(); | 178 final List<String> items = new ArrayList<String>(); |
173 items.add(AdblockPlus.getDeviceName()); | 179 items.add(AdblockPlus.getDeviceName()); |
174 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl ockPlus.getApplication().getBuildNumber())); | 180 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl ockPlus.getApplication().getBuildNumber())); |
175 if (proxyService != null) | 181 if (this.proxyService != null) |
176 { | 182 { |
177 items.add(String.format("Local port: %d", proxyService.port)); | 183 items.add(String.format("Local port: %d", this.proxyService.port)); |
178 if (proxyService.isTransparent()) | 184 if (this.proxyService.isTransparent()) |
179 { | 185 { |
180 items.add("Running in root mode"); | 186 items.add("Running in root mode"); |
181 items.add("iptables output:"); | 187 items.add("iptables output:"); |
182 List<String> output = proxyService.getIptablesOutput(); | 188 final List<String> output = this.proxyService.getIptablesOutput(); |
183 if (output != null) | 189 if (output != null) |
184 { | 190 { |
185 for (String line : output) | 191 for (final String line : output) |
186 { | 192 { |
187 if (!"".equals(line)) | 193 if (!"".equals(line)) |
194 { | |
188 items.add(line); | 195 items.add(line); |
196 } | |
189 } | 197 } |
190 } | 198 } |
191 } | 199 } |
192 if (proxyService.isNativeProxyAutoConfigured()) | 200 if (this.proxyService.isNativeProxyAutoConfigured()) |
193 { | 201 { |
194 items.add("Has native proxy auto configured"); | 202 items.add("Has native proxy auto configured"); |
195 } | 203 } |
196 if (ProxyService.NATIVE_PROXY_SUPPORTED) | 204 if (ProxyService.NATIVE_PROXY_SUPPORTED) |
197 { | 205 { |
198 String[] px = ProxySettings.getUserProxy(getApplicationContext()); | 206 final String[] px = ProxySettings.getUserProxy(this.getApplicationCo ntext()); |
199 if (px != null) | 207 if (px != null) |
200 { | 208 { |
201 items.add("System settings:"); | 209 items.add("System settings:"); |
202 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2])); | 210 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2])); |
203 } | 211 } |
204 } | 212 } |
205 items.add("Proxy settings:"); | 213 items.add("Proxy settings:"); |
206 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"), | 214 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", this.proxy Service.proxy.props.getProperty("adblock.proxyHost"), |
207 proxyService.proxy.props.getProperty("adblock.proxyExcl"))); | 215 this.proxyService.proxy.props.getProperty("adblock.proxyPort"), |
208 if (proxyService.proxy.props.getProperty("adblock.auth") != null) | 216 this.proxyService.proxy.props.getProperty("adblock.proxyExcl"))); |
217 if (this.proxyService.proxy.props.getProperty("adblock.auth") != null) | |
218 { | |
209 items.add("Auth: yes"); | 219 items.add("Auth: yes"); |
220 } | |
210 } | 221 } |
211 else | 222 else |
212 { | 223 { |
213 items.add("Service not running"); | 224 items.add("Service not running"); |
214 } | 225 } |
215 | 226 |
216 ScrollView scrollPane = new ScrollView(this); | 227 final ScrollView scrollPane = new ScrollView(this); |
217 TextView messageText = new TextView(this); | 228 final TextView messageText = new TextView(this); |
218 messageText.setPadding(12, 6, 12, 6); | 229 messageText.setPadding(12, 6, 12, 6); |
219 messageText.setText(TextUtils.join("\n", items)); | 230 messageText.setText(TextUtils.join("\n", items)); |
220 messageText.setOnClickListener(new View.OnClickListener() | 231 messageText.setOnClickListener(new View.OnClickListener() |
221 { | 232 { |
222 | |
223 @Override | 233 @Override |
224 public void onClick(View v) | 234 public void onClick(final View v) |
225 { | 235 { |
226 ClipboardManager manager = (ClipboardManager) getSystemService(CLIPB OARD_SERVICE); | 236 final ClipboardManager manager = (ClipboardManager)AdvancedPreferenc es.this.getSystemService(CLIPBOARD_SERVICE); |
227 TextView showTextParam = (TextView) v; | 237 final TextView showTextParam = (TextView)v; |
228 manager.setText(showTextParam.getText()); | 238 manager.setText(showTextParam.getText()); |
229 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); | 239 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); |
230 } | 240 } |
231 }); | 241 }); |
232 scrollPane.addView(messageText); | 242 scrollPane.addView(messageText); |
233 | 243 |
234 AlertDialog.Builder builder = new AlertDialog.Builder(this); | 244 final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
235 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false) | 245 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false) |
236 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) | 246 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) |
237 { | 247 { |
238 public void onClick(DialogInterface dialog, int id) | 248 @Override |
249 public void onClick(final DialogInterface dialog, final int id) | |
239 { | 250 { |
240 dialog.cancel(); | 251 dialog.cancel(); |
241 } | 252 } |
242 }); | 253 }); |
243 dialog = builder.create(); | 254 dialog = builder.create(); |
244 break; | 255 break; |
245 } | 256 } |
246 return dialog; | 257 return dialog; |
247 } | 258 } |
248 | 259 |
249 private void connect() | 260 private void connect() |
250 { | 261 { |
251 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ; | 262 this.bindService(new Intent(this, ProxyService.class), this.proxyServiceConn ection, 0); |
252 } | 263 } |
253 | 264 |
254 private void disconnect() | 265 private void disconnect() |
255 { | 266 { |
256 unbindService(proxyServiceConnection); | 267 this.unbindService(this.proxyServiceConnection); |
257 proxyService = null; | 268 this.proxyService = null; |
258 } | 269 } |
259 | 270 |
260 private ServiceConnection proxyServiceConnection = new ServiceConnection() | 271 private final ServiceConnection proxyServiceConnection = new ServiceConnection () |
261 { | 272 { |
262 public void onServiceConnected(ComponentName className, IBinder service) | 273 @Override |
274 public void onServiceConnected(final ComponentName className, final IBinder service) | |
263 { | 275 { |
264 proxyService = ((ProxyService.LocalBinder) service).getService(); | 276 AdvancedPreferences.this.proxyService = ((ProxyService.LocalBinder)service ).getService(); |
265 Log.d(TAG, "Proxy service connected"); | 277 Log.d(TAG, "Proxy service connected"); |
266 } | 278 } |
267 | 279 |
268 public void onServiceDisconnected(ComponentName className) | 280 @Override |
281 public void onServiceDisconnected(final ComponentName className) | |
269 { | 282 { |
270 proxyService = null; | 283 AdvancedPreferences.this.proxyService = null; |
271 Log.d(TAG, "Proxy service disconnected"); | 284 Log.d(TAG, "Proxy service disconnected"); |
272 } | 285 } |
273 }; | 286 }; |
274 } | 287 } |
OLD | NEW |