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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 import com.actionbarsherlock.view.Menu; | 56 import com.actionbarsherlock.view.Menu; |
57 import com.actionbarsherlock.view.MenuInflater; | 57 import com.actionbarsherlock.view.MenuInflater; |
58 import com.actionbarsherlock.view.MenuItem; | 58 import com.actionbarsherlock.view.MenuItem; |
59 | 59 |
60 /** | 60 /** |
61 * Main settings UI. | 61 * Main settings UI. |
62 */ | 62 */ |
63 public class Preferences extends SummarizedPreferences | 63 public class Preferences extends SummarizedPreferences |
64 { | 64 { |
65 private static final String TAG = "Preferences"; | 65 private final static String TAG = Utils.getTag(Preferences.class); |
66 | 66 private final static int ABOUT_DIALOG = 1; |
67 private static final int ABOUT_DIALOG = 1; | 67 private final static int HIDEICONWARNING_DIALOG = 2; |
68 private static final int HIDEICONWARNING_DIALOG = 2; | |
69 | 68 |
70 private static ProxyService proxyService = null; | 69 private static ProxyService proxyService = null; |
71 | |
72 private static boolean firstRunActionsPending = true; | 70 private static boolean firstRunActionsPending = true; |
73 | 71 |
74 private RefreshableListPreference subscriptionList; | 72 private RefreshableListPreference subscriptionList; |
75 | |
76 private String subscriptionSummary; | 73 private String subscriptionSummary; |
77 | 74 |
| 75 @SuppressWarnings("deprecation") |
78 @Override | 76 @Override |
79 public void onCreate(Bundle savedInstanceState) | 77 public void onCreate(final Bundle savedInstanceState) |
80 { | 78 { |
81 super.onCreate(savedInstanceState); | 79 super.onCreate(savedInstanceState); |
82 | 80 |
83 PreferenceManager.setDefaultValues(this, R.xml.preferences, true); | 81 PreferenceManager.setDefaultValues(this, R.xml.preferences, true); |
84 PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true); | 82 PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true); |
85 setContentView(R.layout.preferences); | 83 this.setContentView(R.layout.preferences); |
86 addPreferencesFromResource(R.xml.preferences); | 84 this.addPreferencesFromResource(R.xml.preferences); |
87 | 85 |
88 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this
); | 86 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(this); |
89 | 87 |
90 // Check if we need to update assets | 88 // Check if we need to update assets |
91 int lastVersion = prefs.getInt(getString(R.string.pref_version), 0); | 89 final int lastVersion = prefs.getInt(this.getString(R.string.pref_version),
0); |
92 try | 90 try |
93 { | 91 { |
94 int thisVersion = getPackageManager().getPackageInfo(getPackageName(), 0).
versionCode; | 92 final int thisVersion = this.getPackageManager().getPackageInfo(this.getPa
ckageName(), 0).versionCode; |
95 if (lastVersion != thisVersion) | 93 if (lastVersion != thisVersion) |
96 { | 94 { |
97 copyAssets(); | 95 this.copyAssets(); |
98 SharedPreferences.Editor editor = prefs.edit(); | 96 final SharedPreferences.Editor editor = prefs.edit(); |
99 editor.putInt(getString(R.string.pref_version), thisVersion); | 97 editor.putInt(this.getString(R.string.pref_version), thisVersion); |
100 editor.commit(); | 98 editor.commit(); |
101 } | 99 } |
102 } | 100 } |
103 catch (NameNotFoundException e) | 101 catch (final NameNotFoundException e) |
104 { | 102 { |
105 copyAssets(); | 103 this.copyAssets(); |
106 } | 104 } |
| 105 Log.d(TAG, "onCreateDone"); |
107 } | 106 } |
108 | 107 |
| 108 @SuppressWarnings("deprecation") |
109 @Override | 109 @Override |
110 protected void onStart() | 110 protected void onStart() |
111 { | 111 { |
112 super.onStart(); | 112 super.onStart(); |
113 AdblockPlus application = AdblockPlus.getApplication(); | 113 final AdblockPlus application = AdblockPlus.getApplication(); |
114 application.startEngine(); | 114 application.startEngine(); |
115 | 115 |
116 // Initialize subscription list | 116 // Initialize subscription list |
117 subscriptionList = (RefreshableListPreference) findPreference(getString(R.st
ring.pref_subscription)); | 117 this.subscriptionList = (RefreshableListPreference)this.findPreference(this.
getString(R.string.pref_subscription)); |
118 Subscription[] subscriptions = application.getRecommendedSubscriptions(); | 118 final Subscription[] subscriptions = application.getRecommendedSubscriptions
(); |
119 String[] entries = new String[subscriptions.length]; | 119 |
120 String[] entryValues = new String[subscriptions.length]; | 120 final String[] entries = new String[subscriptions.length]; |
| 121 final String[] entryValues = new String[subscriptions.length]; |
121 int i = 0; | 122 int i = 0; |
122 for (Subscription subscription : subscriptions) | 123 for (final Subscription subscription : subscriptions) |
123 { | 124 { |
124 entries[i] = subscription.title; | 125 entries[i] = subscription.title; |
125 entryValues[i] = subscription.url; | 126 entryValues[i] = subscription.url; |
126 i++; | 127 i++; |
127 } | 128 } |
128 subscriptionList.setEntries(entries); | 129 this.subscriptionList.setEntries(entries); |
129 subscriptionList.setEntryValues(entryValues); | 130 this.subscriptionList.setEntryValues(entryValues); |
130 | 131 |
131 // Set Acceptable Ads FAQ link | 132 // Set Acceptable Ads FAQ link |
132 HelpfulCheckBoxPreference acceptableAdsCheckBox = | 133 final HelpfulCheckBoxPreference acceptableAdsCheckBox = |
133 (HelpfulCheckBoxPreference) findPreference(getString(R.string.pref_accep
tableads)); | 134 (HelpfulCheckBoxPreference)this.findPreference(this.getString(R.string.p
ref_acceptableads)); |
134 acceptableAdsCheckBox.setHelpUrl(AdblockPlus.getApplication().getAcceptableA
dsUrl()); | 135 acceptableAdsCheckBox.setHelpUrl(AdblockPlus.getApplication().getAcceptableA
dsUrl()); |
135 } | 136 } |
136 | 137 |
| 138 @SuppressWarnings("deprecation") |
137 @Override | 139 @Override |
138 public void onResume() | 140 public void onResume() |
139 { | 141 { |
140 super.onResume(); | 142 super.onResume(); |
141 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this
); | 143 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(this); |
142 | 144 |
143 final AdblockPlus application = AdblockPlus.getApplication(); | 145 final AdblockPlus application = AdblockPlus.getApplication(); |
144 | 146 |
145 Subscription current = null; | 147 Subscription current = null; |
146 Subscription[] subscriptions = application.getListedSubscriptions(); | 148 final Subscription[] subscriptions = application.getListedSubscriptions(); |
147 if (subscriptions.length > 0) | 149 if (subscriptions.length > 0) |
148 { | 150 { |
149 current = subscriptions[0]; | 151 current = subscriptions[0]; |
150 } | 152 } |
151 | 153 |
152 boolean firstRun = firstRunActionsPending && application.isFirstRun(); | 154 final boolean firstRun = firstRunActionsPending && application.isFirstRun(); |
153 firstRunActionsPending = false; | 155 firstRunActionsPending = false; |
154 | 156 |
155 if (firstRun && current != null) | 157 if (firstRun && current != null) |
156 { | 158 { |
157 showNotificationDialog(getString(R.string.install_name), | 159 this.showNotificationDialog(this.getString(R.string.install_name), |
158 String.format(getString(R.string.msg_subscription_offer, current.title
)), | 160 String.format(this.getString(R.string.msg_subscription_offer), current
.title), |
159 application.getAcceptableAdsUrl()); | 161 application.getAcceptableAdsUrl()); |
160 application.setNotifiedAboutAcceptableAds(true); | 162 application.setNotifiedAboutAcceptableAds(true); |
161 setAcceptableAdsEnabled(true); | 163 this.setAcceptableAdsEnabled(true); |
162 } | 164 } |
163 else if (!application.isNotifiedAboutAcceptableAds()) | 165 else if (!application.isNotifiedAboutAcceptableAds()) |
164 { | 166 { |
165 showNotificationDialog(getString(R.string.acceptableads_name), | 167 this.showNotificationDialog(this.getString(R.string.acceptableads_name), |
166 getString(R.string.msg_acceptable_ads), application.getAcceptableAdsUr
l()); | 168 this.getString(R.string.msg_acceptable_ads), application.getAcceptable
AdsUrl()); |
167 application.setNotifiedAboutAcceptableAds(true); | 169 application.setNotifiedAboutAcceptableAds(true); |
168 setAcceptableAdsEnabled(true); | 170 this.setAcceptableAdsEnabled(true); |
169 } | 171 } |
170 | 172 |
171 // Enable manual subscription refresh | 173 // Enable manual subscription refresh |
172 subscriptionList.setOnRefreshClickListener(new View.OnClickListener() | 174 this.subscriptionList.setOnRefreshClickListener(new View.OnClickListener() |
173 { | 175 { |
174 @Override | 176 @Override |
175 public void onClick(View v) | 177 public void onClick(final View v) |
176 { | 178 { |
177 application.refreshSubscriptions(); | 179 application.refreshSubscriptions(); |
178 } | 180 } |
179 }); | 181 }); |
180 | 182 |
181 // Set subscription status message | 183 // Set subscription status message |
182 if (subscriptionSummary != null) | 184 if (this.subscriptionSummary != null) |
183 subscriptionList.setSummary(subscriptionSummary); | 185 { |
| 186 this.subscriptionList.setSummary(this.subscriptionSummary); |
| 187 } |
184 else | 188 else |
185 setPrefSummary(subscriptionList); | 189 { |
| 190 this.setPrefSummary(this.subscriptionList); |
| 191 } |
186 | 192 |
187 // Time to start listening for events | 193 // Time to start listening for events |
188 registerReceiver(receiver, new IntentFilter(AdblockPlus.BROADCAST_SUBSCRIPTI
ON_STATUS)); | 194 this.registerReceiver(this.receiver, new IntentFilter(AdblockPlus.BROADCAST_
SUBSCRIPTION_STATUS)); |
189 registerReceiver(receiver, new IntentFilter(ProxyService.BROADCAST_STATE_CHA
NGED)); | 195 this.registerReceiver(this.receiver, new IntentFilter(ProxyService.BROADCAST
_STATE_CHANGED)); |
190 registerReceiver(receiver, new IntentFilter(ProxyService.BROADCAST_PROXY_FAI
LED)); | 196 this.registerReceiver(this.receiver, new IntentFilter(ProxyService.BROADCAST
_PROXY_FAILED)); |
191 | 197 |
192 // Update service and UI state according to user settings | 198 // Update service and UI state according to user settings |
193 if (current != null) | 199 if (current != null) |
194 { | 200 { |
195 subscriptionList.setValue(current.url); | 201 this.subscriptionList.setValue(current.url); |
196 application.actualizeSubscriptionStatus(current.url); | 202 application.updateSubscriptionStatus(current.url); |
197 } | 203 } |
198 boolean enabled = prefs.getBoolean(getString(R.string.pref_enabled), false); | 204 final boolean enabled = prefs.getBoolean(this.getString(R.string.pref_enable
d), false); |
199 boolean proxyenabled = prefs.getBoolean(getString(R.string.pref_proxyenabled
), true); | 205 final boolean proxyenabled = prefs.getBoolean(this.getString(R.string.pref_p
roxyenabled), true); |
200 boolean autoconfigured = prefs.getBoolean(getString(R.string.pref_proxyautoc
onfigured), false); | 206 final boolean autoconfigured = prefs.getBoolean(this.getString(R.string.pref
_proxyautoconfigured), false); |
201 | 207 |
202 // This is weird but UI does not update on back button (when returning from
advanced preferences) | 208 // This is weird but UI does not update on back button (when returning from |
203 ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChe
cked(enabled); | 209 // advanced preferences) |
| 210 ((SwitchPreference)this.findPreference(this.getString(R.string.pref_enabled)
)).setChecked(enabled); |
204 | 211 |
205 if (enabled || firstRun) | 212 if (enabled || firstRun) |
206 setFilteringEnabled(true); | 213 { |
| 214 this.setFilteringEnabled(true); |
| 215 } |
207 if (enabled || firstRun || (proxyenabled && !autoconfigured)) | 216 if (enabled || firstRun || (proxyenabled && !autoconfigured)) |
208 setProxyEnabled(true); | 217 { |
| 218 this.setProxyEnabled(true); |
| 219 } |
209 | 220 |
210 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0)
; | 221 this.bindService(new Intent(this, ProxyService.class), this.proxyServiceConn
ection, 0); |
211 } | 222 } |
212 | 223 |
213 private void showNotificationDialog(String title, String message, String url) | 224 private void showNotificationDialog(final String title, String message, String
url) |
214 { | 225 { |
215 url = TextUtils.htmlEncode(url); | 226 url = TextUtils.htmlEncode(url); |
216 message = TextUtils.htmlEncode(message) | 227 message = TextUtils.htmlEncode(message) |
217 .replaceAll("<a>(.*?)</a>", "<a href=\"" + url + "\">$1</a>"
); | 228 .replaceAll("<a>(.*?)</a>", "<a href=\"" + url + "\">$1</a>"
); |
218 final TextView messageView = new TextView(this); | 229 final TextView messageView = new TextView(this); |
219 messageView.setText(Html.fromHtml(message)); | 230 messageView.setText(Html.fromHtml(message)); |
220 messageView.setMovementMethod(LinkMovementMethod.getInstance()); | 231 messageView.setMovementMethod(LinkMovementMethod.getInstance()); |
221 final int padding = 10; | 232 final int padding = 10; |
222 messageView.setPadding(padding, padding, padding, padding); | 233 messageView.setPadding(padding, padding, padding, padding); |
223 new AlertDialog.Builder(this).setTitle(title) | 234 new AlertDialog.Builder(this).setTitle(title) |
224 .setView(messageView) | 235 .setView(messageView) |
225 .setIcon(android.R.drawable.ic_dialog_info) | 236 .setIcon(android.R.drawable.ic_dialog_info) |
226 .setPositiveButton(R.string.ok, null).create().show(); | 237 .setPositiveButton(R.string.ok, null).create().show(); |
227 } | 238 } |
228 | 239 |
229 @Override | 240 @Override |
230 public void onPause() | 241 public void onPause() |
231 { | 242 { |
232 super.onPause(); | 243 super.onPause(); |
233 try | 244 try |
234 { | 245 { |
235 unregisterReceiver(receiver); | 246 this.unregisterReceiver(this.receiver); |
236 } | 247 } |
237 catch (IllegalArgumentException e) | 248 catch (final IllegalArgumentException e) |
238 { | 249 { |
239 // ignore - it is thrown if receiver is not registered but it can not be | 250 // ignore - it is thrown if receiver is not registered but it can not be |
240 // true in normal conditions | 251 // true in normal conditions |
241 } | 252 } |
242 unbindService(proxyServiceConnection); | 253 this.unbindService(this.proxyServiceConnection); |
243 proxyService = null; | 254 proxyService = null; |
244 | 255 |
245 hideConfigurationMsg(); | 256 this.hideConfigurationMsg(); |
246 } | 257 } |
247 | 258 |
248 @Override | 259 @Override |
249 protected void onStop() | 260 protected void onStop() |
250 { | 261 { |
251 super.onStop(); | 262 super.onStop(); |
252 AdblockPlus application = AdblockPlus.getApplication(); | 263 final AdblockPlus application = AdblockPlus.getApplication(); |
253 if (!application.isFilteringEnabled()) | 264 if (!application.isFilteringEnabled()) |
| 265 { |
254 application.stopEngine(); | 266 application.stopEngine(); |
| 267 } |
255 } | 268 } |
256 | 269 |
257 @Override | 270 @Override |
258 public boolean onCreateOptionsMenu(Menu menu) | 271 public boolean onCreateOptionsMenu(final Menu menu) |
259 { | 272 { |
260 MenuInflater inflater = getSupportMenuInflater(); | 273 final MenuInflater inflater = this.getSupportMenuInflater(); |
261 inflater.inflate(R.menu.menu_preferences, menu); | 274 inflater.inflate(R.menu.menu_preferences, menu); |
262 return true; | 275 return true; |
263 } | 276 } |
264 | 277 |
| 278 @SuppressWarnings("deprecation") |
265 @Override | 279 @Override |
266 public boolean onOptionsItemSelected(MenuItem item) | 280 public boolean onOptionsItemSelected(final MenuItem item) |
267 { | 281 { |
268 switch (item.getItemId()) | 282 switch (item.getItemId()) |
269 { | 283 { |
270 case R.id.menu_help: | 284 case R.id.menu_help: |
271 Uri uri = Uri.parse(getString(R.string.configuring_url)); | 285 final Uri uri = Uri.parse(this.getString(R.string.configuring_url)); |
272 Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 286 final Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
273 startActivity(intent); | 287 this.startActivity(intent); |
274 return true; | 288 return true; |
275 case R.id.menu_about: | 289 case R.id.menu_about: |
276 showDialog(ABOUT_DIALOG); | 290 this.showDialog(ABOUT_DIALOG); |
277 return true; | 291 return true; |
278 case R.id.menu_advanced: | 292 case R.id.menu_advanced: |
279 startActivity(new Intent(this, AdvancedPreferences.class)); | 293 this.startActivity(new Intent(this, AdvancedPreferences.class)); |
280 return true; | 294 return true; |
281 default: | 295 default: |
282 return super.onOptionsItemSelected(item); | 296 return super.onOptionsItemSelected(item); |
283 } | 297 } |
284 } | 298 } |
285 | 299 |
286 private void setAcceptableAdsEnabled(boolean enabled) | 300 @SuppressWarnings("deprecation") |
| 301 private void setAcceptableAdsEnabled(final boolean enabled) |
287 { | 302 { |
288 CheckBoxPreference acceptableAdsPreference = | 303 final CheckBoxPreference acceptableAdsPreference = |
289 (CheckBoxPreference) findPreference(getString(R.string.pref_acceptablead
s)); | 304 (CheckBoxPreference)this.findPreference(this.getString(R.string.pref_acc
eptableads)); |
290 acceptableAdsPreference.setChecked(enabled); | 305 acceptableAdsPreference.setChecked(enabled); |
291 AdblockPlus application = AdblockPlus.getApplication(); | 306 final AdblockPlus application = AdblockPlus.getApplication(); |
292 application.setAcceptableAdsEnabled(enabled); | 307 application.setAcceptableAdsEnabled(enabled); |
293 } | 308 } |
294 | 309 |
295 private void setFilteringEnabled(boolean enabled) | 310 @SuppressWarnings("deprecation") |
| 311 private void setFilteringEnabled(final boolean enabled) |
296 { | 312 { |
297 SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferen
ces(this).edit(); | 313 final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPr
eferences(this).edit(); |
298 editor.putBoolean(getString(R.string.pref_enabled), enabled); | 314 editor.putBoolean(this.getString(R.string.pref_enabled), enabled); |
299 editor.commit(); | 315 editor.commit(); |
300 ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChe
cked(enabled); | 316 ((SwitchPreference)this.findPreference(this.getString(R.string.pref_enabled)
)).setChecked(enabled); |
301 AdblockPlus application = AdblockPlus.getApplication(); | 317 final AdblockPlus application = AdblockPlus.getApplication(); |
302 application.setFilteringEnabled(enabled); | 318 application.setFilteringEnabled(enabled); |
303 } | 319 } |
304 | 320 |
305 private void setProxyEnabled(boolean enabled) | 321 private void setProxyEnabled(final boolean enabled) |
306 { | 322 { |
307 SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferen
ces(this).edit(); | 323 final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPr
eferences(this).edit(); |
308 editor.putBoolean(getString(R.string.pref_proxyenabled), enabled); | 324 editor.putBoolean(this.getString(R.string.pref_proxyenabled), enabled); |
309 editor.commit(); | 325 editor.commit(); |
310 AdblockPlus application = AdblockPlus.getApplication(); | 326 final AdblockPlus application = AdblockPlus.getApplication(); |
311 if (enabled && !application.isServiceRunning()) | 327 if (enabled && !application.isServiceRunning()) |
312 startService(new Intent(this, ProxyService.class)); | 328 { |
| 329 this.startService(new Intent(this, ProxyService.class)); |
| 330 } |
313 } | 331 } |
314 | 332 |
315 /** | 333 /** |
316 * Copies file assets from installation package to filesystem. | 334 * Copies file assets from installation package to filesystem. |
317 */ | 335 */ |
318 private void copyAssets() | 336 private void copyAssets() |
319 { | 337 { |
320 AssetManager assetManager = getAssets(); | 338 final AssetManager assetManager = this.getAssets(); |
321 String[] files = null; | 339 String[] files = null; |
322 try | 340 try |
323 { | 341 { |
324 files = assetManager.list("install"); | 342 files = assetManager.list("install"); |
325 } | 343 } |
326 catch (IOException e) | 344 catch (final IOException e) |
327 { | 345 { |
328 Log.e(TAG, "Failed to get assets list", e); | 346 Log.e(TAG, "Failed to get assets list", e); |
329 } | 347 } |
330 for (int i = 0; i < files.length; i++) | 348 for (int i = 0; i < files.length; i++) |
331 { | 349 { |
332 try | 350 try |
333 { | 351 { |
334 Log.d(TAG, "Copy: install/" + files[i]); | 352 Log.d(TAG, "Copy: install/" + files[i]); |
335 InputStream in = assetManager.open("install/" + files[i]); | 353 final InputStream in = assetManager.open("install/" + files[i]); |
336 OutputStream out = openFileOutput(files[i], MODE_PRIVATE); | 354 final OutputStream out = this.openFileOutput(files[i], MODE_PRIVATE); |
337 byte[] buffer = new byte[1024]; | 355 final byte[] buffer = new byte[1024]; |
338 int read; | 356 int read; |
339 while ((read = in.read(buffer)) != -1) | 357 while ((read = in.read(buffer)) != -1) |
340 { | 358 { |
341 out.write(buffer, 0, read); | 359 out.write(buffer, 0, read); |
342 } | 360 } |
343 in.close(); | 361 in.close(); |
344 out.flush(); | 362 out.flush(); |
345 out.close(); | 363 out.close(); |
346 } | 364 } |
347 catch (Exception e) | 365 catch (final Exception e) |
348 { | 366 { |
349 Log.e(TAG, "Asset copy error", e); | 367 Log.e(TAG, "Asset copy error", e); |
350 } | 368 } |
351 } | 369 } |
352 } | 370 } |
353 | 371 |
354 public void showProxySettings(View v) | 372 public void showProxySettings(final View v) |
355 { | 373 { |
356 startActivity(new Intent(this, ProxyConfigurationActivity.class).putExtra("p
ort", proxyService.port)); | 374 this.startActivity(new Intent(this, ProxyConfigurationActivity.class).putExt
ra("port", proxyService.port)); |
357 } | 375 } |
358 | 376 |
359 @Override | 377 @Override |
360 protected Dialog onCreateDialog(int id) | 378 protected Dialog onCreateDialog(final int id) |
361 { | 379 { |
362 Dialog dialog = null; | 380 Dialog dialog = null; |
363 switch (id) | 381 switch (id) |
364 { | 382 { |
365 case ABOUT_DIALOG: | 383 case ABOUT_DIALOG: |
366 dialog = new AboutDialog(this); | 384 dialog = new AboutDialog(this); |
367 break; | 385 break; |
368 case HIDEICONWARNING_DIALOG: | 386 case HIDEICONWARNING_DIALOG: |
369 AlertDialog.Builder builder = new AlertDialog.Builder(this); | 387 final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
370 builder.setTitle(R.string.warning); | 388 builder.setTitle(R.string.warning); |
371 builder.setIcon(android.R.drawable.ic_dialog_alert); | 389 builder.setIcon(android.R.drawable.ic_dialog_alert); |
372 builder.setCancelable(false); | 390 builder.setCancelable(false); |
373 StringBuffer message = new StringBuffer(); | 391 final StringBuffer message = new StringBuffer(); |
374 message.append(getString(R.string.msg_hideicon_warning)); | 392 message.append(this.getString(R.string.msg_hideicon_warning)); |
375 builder.setPositiveButton(R.string.gotit, new DialogInterface.OnClickLis
tener() | 393 builder.setPositiveButton(R.string.gotit, new DialogInterface.OnClickLis
tener() |
376 { | 394 { |
377 public void onClick(DialogInterface dialog, int id) | 395 @Override |
378 { | 396 public void onClick(final DialogInterface dialog, final int id) |
379 dialog.cancel(); | 397 { |
380 } | 398 dialog.cancel(); |
381 }); | 399 } |
| 400 }); |
382 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) | 401 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) |
383 { | 402 { |
384 message.append("<br/><br/>"); | 403 message.append("<br/><br/>"); |
385 message.append(getString(R.string.msg_hideicon_native)); | 404 message.append(this.getString(R.string.msg_hideicon_native)); |
386 builder.setNeutralButton(R.string.showme, new DialogInterface.OnClick
Listener() | 405 builder.setNeutralButton(R.string.showme, new DialogInterface.OnClickL
istener() |
| 406 { |
| 407 @Override |
| 408 public void onClick(final DialogInterface dialog, final int id) |
387 { | 409 { |
388 public void onClick(DialogInterface dialog, int id) | 410 AdblockPlus.showAppDetails(Preferences.this.getApplicationContext(
)); |
389 { | 411 dialog.cancel(); |
390 AdblockPlus.showAppDetails(getApplicationContext()); | 412 } |
391 dialog.cancel(); | 413 }); |
392 } | |
393 }); | |
394 } | 414 } |
395 builder.setMessage(Html.fromHtml(message.toString())); | 415 builder.setMessage(Html.fromHtml(message.toString())); |
396 dialog = builder.create(); | 416 dialog = builder.create(); |
397 break; | 417 break; |
398 } | 418 } |
399 return dialog; | 419 return dialog; |
400 } | 420 } |
401 | 421 |
| 422 @SuppressWarnings("deprecation") |
402 @Override | 423 @Override |
403 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str
ing key) | 424 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
s, final String key) |
404 { | 425 { |
405 AdblockPlus application = AdblockPlus.getApplication(); | 426 final AdblockPlus application = AdblockPlus.getApplication(); |
406 if (getString(R.string.pref_enabled).equals(key)) | 427 if (this.getString(R.string.pref_enabled).equals(key)) |
407 { | 428 { |
408 boolean enabled = sharedPreferences.getBoolean(key, false); | 429 final boolean enabled = sharedPreferences.getBoolean(key, false); |
409 boolean autoconfigured = sharedPreferences.getBoolean(getString(R.string.p
ref_proxyautoconfigured), false); | 430 final boolean autoconfigured = sharedPreferences.getBoolean(this.getString
(R.string.pref_proxyautoconfigured), false); |
410 boolean serviceRunning = application.isServiceRunning(); | 431 final boolean serviceRunning = application.isServiceRunning(); |
411 application.setFilteringEnabled(enabled); | 432 application.setFilteringEnabled(enabled); |
412 if (enabled) | 433 if (enabled) |
413 { | 434 { |
414 // If user has enabled filtering, enable proxy as well | 435 // If user has enabled filtering, enable proxy as well |
415 setProxyEnabled(true); | 436 this.setProxyEnabled(true); |
416 } | 437 } |
417 else if (serviceRunning && autoconfigured) | 438 else if (serviceRunning && autoconfigured) |
418 { | 439 { |
419 // If user disabled filtering disable proxy only if it was autoconfigure
d | 440 // If user disabled filtering disable proxy only if it was |
420 stopService(new Intent(this, ProxyService.class)); | 441 // autoconfigured |
| 442 this.stopService(new Intent(this, ProxyService.class)); |
421 } | 443 } |
422 } | 444 } |
423 else if (getString(R.string.pref_acceptableads).equals(key)) | 445 else if (this.getString(R.string.pref_acceptableads).equals(key)) |
424 { | 446 { |
425 boolean enabled = sharedPreferences.getBoolean(key, false); | 447 final boolean enabled = sharedPreferences.getBoolean(key, false); |
426 application.setAcceptableAdsEnabled(enabled); | 448 application.setAcceptableAdsEnabled(enabled); |
427 } | 449 } |
428 else if (getString(R.string.pref_subscription).equals(key)) | 450 else if (this.getString(R.string.pref_subscription).equals(key)) |
429 { | 451 { |
430 String url = sharedPreferences.getString(key, null); | 452 final String url = sharedPreferences.getString(key, null); |
431 if (url != null) | 453 if (url != null) |
| 454 { |
432 application.setSubscription(url); | 455 application.setSubscription(url); |
| 456 } |
433 } | 457 } |
434 else if (getString(R.string.pref_hideicon).equals(key)) | 458 else if (this.getString(R.string.pref_hideicon).equals(key)) |
435 { | 459 { |
436 boolean hideIcon = sharedPreferences.getBoolean(key, false); | 460 final boolean hideIcon = sharedPreferences.getBoolean(key, false); |
437 if (hideIcon) | 461 if (hideIcon) |
438 showDialog(HIDEICONWARNING_DIALOG); | 462 { |
| 463 this.showDialog(HIDEICONWARNING_DIALOG); |
| 464 } |
439 if (proxyService != null) | 465 if (proxyService != null) |
| 466 { |
440 proxyService.setEmptyIcon(hideIcon); | 467 proxyService.setEmptyIcon(hideIcon); |
| 468 } |
441 } | 469 } |
442 super.onSharedPreferenceChanged(sharedPreferences, key); | 470 super.onSharedPreferenceChanged(sharedPreferences, key); |
443 } | 471 } |
444 | 472 |
445 private void showConfigurationMsg(String message) | 473 private void showConfigurationMsg(final String message) |
446 { | 474 { |
447 ViewGroup grp = (ViewGroup) findViewById(R.id.grp_configuration); | 475 final ViewGroup grp = (ViewGroup)this.findViewById(R.id.grp_configuration); |
448 TextView msg = (TextView) findViewById(R.id.txt_configuration); | 476 final TextView msg = (TextView)this.findViewById(R.id.txt_configuration); |
449 msg.setText(Html.fromHtml(message)); | 477 msg.setText(Html.fromHtml(message)); |
450 grp.setVisibility(View.VISIBLE); | 478 grp.setVisibility(View.VISIBLE); |
451 } | 479 } |
452 | 480 |
453 private void hideConfigurationMsg() | 481 private void hideConfigurationMsg() |
454 { | 482 { |
455 ViewGroup grp = (ViewGroup) findViewById(R.id.grp_configuration); | 483 final ViewGroup grp = (ViewGroup)this.findViewById(R.id.grp_configuration); |
456 grp.setVisibility(View.GONE); | 484 grp.setVisibility(View.GONE); |
457 } | 485 } |
458 | 486 |
459 private BroadcastReceiver receiver = new BroadcastReceiver() | 487 private final BroadcastReceiver receiver = new BroadcastReceiver() |
460 { | 488 { |
461 @Override | 489 @Override |
462 public void onReceive(Context context, Intent intent) | 490 public void onReceive(final Context context, final Intent intent) |
463 { | 491 { |
464 String action = intent.getAction(); | 492 final String action = intent.getAction(); |
465 Bundle extra = intent.getExtras(); | 493 final Bundle extra = intent.getExtras(); |
466 if (action.equals(ProxyService.BROADCAST_STATE_CHANGED)) | 494 if (action.equals(ProxyService.BROADCAST_STATE_CHANGED)) |
467 { | 495 { |
468 if (extra.getBoolean("enabled")) | 496 if (extra.getBoolean("enabled")) |
469 { | 497 { |
470 // Service is enabled in manual mode | 498 // Service is enabled in manual mode |
471 if (extra.getBoolean("manual")) | 499 if (extra.getBoolean("manual")) |
472 { | 500 { |
473 // Proxy is properly configured | 501 // Proxy is properly configured |
474 if (extra.getBoolean("configured")) | 502 if (extra.getBoolean("configured")) |
475 hideConfigurationMsg(); | 503 { |
| 504 Preferences.this.hideConfigurationMsg(); |
| 505 } |
476 else | 506 else |
477 showConfigurationMsg(getString(R.string.msg_configuration)); | 507 { |
| 508 Preferences.this.showConfigurationMsg(Preferences.this.getString(R
.string.msg_configuration)); |
| 509 } |
478 } | 510 } |
479 } | 511 } |
480 else | 512 else |
481 { | 513 { |
482 setFilteringEnabled(false); | 514 Preferences.this.setFilteringEnabled(false); |
483 hideConfigurationMsg(); | 515 Preferences.this.hideConfigurationMsg(); |
484 } | 516 } |
485 } | 517 } |
486 if (action.equals(ProxyService.BROADCAST_PROXY_FAILED)) | 518 if (action.equals(ProxyService.BROADCAST_PROXY_FAILED)) |
487 { | 519 { |
488 String msg = extra.getString("msg"); | 520 final String msg = extra.getString("msg"); |
489 new AlertDialog.Builder(Preferences.this).setTitle(R.string.error).setMe
ssage(msg).setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(R.strin
g.ok, null).create().show(); | 521 new AlertDialog.Builder(Preferences.this).setTitle(R.string.error).setMe
ssage(msg).setIcon(android.R.drawable.ic_dialog_alert) |
490 setFilteringEnabled(false); | 522 .setPositiveButton(R.string.ok, null).create().show(); |
| 523 Preferences.this.setFilteringEnabled(false); |
491 } | 524 } |
492 if (action.equals(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)) | 525 if (action.equals(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)) |
493 { | 526 { |
494 //TODO Should check if url matches active subscription | 527 // TODO Should check if url matches active subscription |
495 final String text = extra.getString("status"); | 528 final String text = extra.getString("status"); |
496 final long time = extra.getLong("time"); | 529 final long time = extra.getLong("time"); |
497 runOnUiThread(new Runnable() | 530 Preferences.this.runOnUiThread(new Runnable() |
498 { | 531 { |
| 532 @Override |
499 public void run() | 533 public void run() |
500 { | 534 { |
501 setSubscriptionStatus(text, time); | 535 Preferences.this.setSubscriptionStatus(text, time); |
502 } | 536 } |
503 }); | 537 }); |
504 } | 538 } |
505 } | 539 } |
506 }; | 540 }; |
507 | 541 |
508 /** | 542 /** |
509 * Constructs and updates subscription status text. | 543 * Constructs and updates subscription status text. |
510 * | 544 * |
511 * @param text | 545 * @param text |
512 * status message | 546 * status message |
513 * @param time | 547 * @param time |
514 * time of last change | 548 * time of last change |
515 */ | 549 */ |
516 private void setSubscriptionStatus(String text, long time) | 550 @SuppressWarnings("deprecation") |
| 551 private void setSubscriptionStatus(final String text, final long time) |
517 { | 552 { |
518 ListPreference subscriptionList = (ListPreference) findPreference(getString(
R.string.pref_subscription)); | 553 final ListPreference subscriptionList = (ListPreference)this.findPreference(
this.getString(R.string.pref_subscription)); |
519 CharSequence summary = subscriptionList.getEntry(); | 554 final CharSequence summary = subscriptionList.getEntry(); |
520 StringBuilder builder = new StringBuilder(); | 555 final StringBuilder builder = new StringBuilder(); |
521 if (summary != null) | 556 if (summary != null) |
522 { | 557 { |
523 builder.append(summary); | 558 builder.append(summary); |
524 if (text != "") | 559 if (text != "") |
525 { | 560 { |
526 builder.append(" ("); | 561 builder.append(" ("); |
527 int id = getResources().getIdentifier(text, "string", getPackageName()); | 562 final int id = this.getResources().getIdentifier(text, "string", this.ge
tPackageName()); |
528 if (id > 0) | 563 if (id > 0) |
529 builder.append(getString(id, text)); | 564 { |
| 565 builder.append(this.getString(id, text)); |
| 566 } |
530 else | 567 else |
| 568 { |
531 builder.append(text); | 569 builder.append(text); |
| 570 } |
532 if (time > 0) | 571 if (time > 0) |
533 { | 572 { |
534 builder.append(": "); | 573 builder.append(": "); |
535 Calendar calendar = Calendar.getInstance(); | 574 final Calendar calendar = Calendar.getInstance(); |
536 calendar.setTimeInMillis(time); | 575 calendar.setTimeInMillis(time); |
537 Date date = calendar.getTime(); | 576 final Date date = calendar.getTime(); |
538 builder.append(DateFormat.getDateFormat(this).format(date)); | 577 builder.append(DateFormat.getDateFormat(this).format(date)); |
539 builder.append(" "); | 578 builder.append(" "); |
540 builder.append(DateFormat.getTimeFormat(this).format(date)); | 579 builder.append(DateFormat.getTimeFormat(this).format(date)); |
541 } | 580 } |
542 builder.append(")"); | 581 builder.append(")"); |
543 } | 582 } |
544 subscriptionSummary = builder.toString(); | 583 this.subscriptionSummary = builder.toString(); |
545 subscriptionList.setSummary(subscriptionSummary); | 584 subscriptionList.setSummary(this.subscriptionSummary); |
546 } | 585 } |
547 } | 586 } |
548 | 587 |
549 @Override | 588 @Override |
550 protected void onRestoreInstanceState(Bundle state) | 589 protected void onRestoreInstanceState(final Bundle state) |
551 { | 590 { |
552 super.onRestoreInstanceState(state); | 591 super.onRestoreInstanceState(state); |
553 subscriptionSummary = state.getString("subscriptionSummary"); | 592 this.subscriptionSummary = state.getString("subscriptionSummary"); |
554 } | 593 } |
555 | 594 |
556 @Override | 595 @Override |
557 protected void onSaveInstanceState(Bundle outState) | 596 protected void onSaveInstanceState(final Bundle outState) |
558 { | 597 { |
559 outState.putString("subscriptionSummary", subscriptionSummary); | 598 outState.putString("subscriptionSummary", this.subscriptionSummary); |
560 super.onSaveInstanceState(outState); | 599 super.onSaveInstanceState(outState); |
561 } | 600 } |
562 | 601 |
563 private ServiceConnection proxyServiceConnection = new ServiceConnection() | 602 private final ServiceConnection proxyServiceConnection = new ServiceConnection
() |
564 { | 603 { |
565 public void onServiceConnected(ComponentName className, IBinder service) | 604 @Override |
| 605 public void onServiceConnected(final ComponentName className, final IBinder
service) |
566 { | 606 { |
567 proxyService = ((ProxyService.LocalBinder) service).getService(); | 607 proxyService = ((ProxyService.LocalBinder)service).getService(); |
568 Log.d(TAG, "Proxy service connected"); | 608 Log.d(TAG, "Proxy service connected"); |
569 | 609 |
570 if (proxyService.isManual() && proxyService.noTraffic()) | 610 if (proxyService.isManual() && proxyService.noTraffic()) |
571 showConfigurationMsg(getString(R.string.msg_configuration)); | 611 { |
| 612 Preferences.this.showConfigurationMsg(Preferences.this.getString(R.strin
g.msg_configuration)); |
| 613 } |
572 } | 614 } |
573 | 615 |
574 public void onServiceDisconnected(ComponentName className) | 616 @Override |
| 617 public void onServiceDisconnected(final ComponentName className) |
575 { | 618 { |
576 proxyService = null; | 619 proxyService = null; |
577 Log.d(TAG, "Proxy service disconnected"); | 620 Log.d(TAG, "Proxy service disconnected"); |
578 } | 621 } |
579 }; | 622 }; |
580 } | 623 } |
OLD | NEW |