LEFT | RIGHT |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 private static final String TAG = Utils.getTag(Preferences.class); | 65 private static final String TAG = Utils.getTag(Preferences.class); |
66 private static final int ABOUT_DIALOG = 1; | 66 private static final int ABOUT_DIALOG = 1; |
67 private static final int HIDEICONWARNING_DIALOG = 2; | 67 private static final int HIDEICONWARNING_DIALOG = 2; |
68 | 68 |
69 private static ProxyService proxyService = null; | 69 private static ProxyService proxyService = null; |
70 private static boolean firstRunActionsPending = true; | 70 private static boolean firstRunActionsPending = true; |
71 | 71 |
72 private RefreshableListPreference subscriptionList; | 72 private RefreshableListPreference subscriptionList; |
73 private String subscriptionSummary; | 73 private String subscriptionSummary; |
74 | 74 |
75 @SuppressWarnings("deprecation") | |
76 @Override | 75 @Override |
77 public void onCreate(final Bundle savedInstanceState) | 76 public void onCreate(final Bundle savedInstanceState) |
78 { | 77 { |
79 super.onCreate(savedInstanceState); | 78 super.onCreate(savedInstanceState); |
80 | 79 |
81 PreferenceManager.setDefaultValues(this, R.xml.preferences, true); | 80 PreferenceManager.setDefaultValues(this, R.xml.preferences, true); |
82 PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true); | 81 PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true); |
83 setContentView(R.layout.preferences); | 82 setContentView(R.layout.preferences); |
84 addPreferencesFromResource(R.xml.preferences); | 83 addPreferencesFromResource(R.xml.preferences); |
85 | 84 |
86 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(this); | 85 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(this); |
87 | 86 |
88 // Check if we need to update assets | 87 // Check if we need to update assets |
89 final int lastVersion = prefs.getInt(getString(R.string.pref_version), 0); | 88 final int lastVersion = prefs.getInt(getString(R.string.pref_version), 0); |
90 try | 89 try |
91 { | 90 { |
92 final int thisVersion = getPackageManager().getPackageInfo(getPackageName(
), 0).versionCode; | 91 final int thisVersion = getPackageManager().getPackageInfo(getPackageName(
), 0).versionCode; |
93 if (lastVersion != thisVersion) | 92 if (lastVersion != thisVersion) |
94 { | 93 { |
95 copyAssets(); | 94 copyAssets(); |
96 final SharedPreferences.Editor editor = prefs.edit(); | 95 final SharedPreferences.Editor editor = prefs.edit(); |
97 editor.putInt(getString(R.string.pref_version), thisVersion); | 96 editor.putInt(getString(R.string.pref_version), thisVersion); |
98 editor.commit(); | 97 editor.commit(); |
99 } | 98 } |
100 } | 99 } |
101 catch (final NameNotFoundException e) | 100 catch (final NameNotFoundException e) |
102 { | 101 { |
103 copyAssets(); | 102 copyAssets(); |
104 } | 103 } |
105 Log.d(TAG, "onCreateDone"); | 104 } |
106 } | 105 |
107 | |
108 @SuppressWarnings("deprecation") | |
109 @Override | 106 @Override |
110 protected void onStart() | 107 protected void onStart() |
111 { | 108 { |
112 super.onStart(); | 109 super.onStart(); |
113 final AdblockPlus application = AdblockPlus.getApplication(); | 110 final AdblockPlus application = AdblockPlus.getApplication(); |
114 application.startEngine(); | 111 application.startEngine(); |
115 | 112 |
116 // Initialize subscription list | 113 // Initialize subscription list |
117 subscriptionList = (RefreshableListPreference) findPreference(getString(R.st
ring.pref_subscription)); | 114 subscriptionList = (RefreshableListPreference) findPreference(getString(R.st
ring.pref_subscription)); |
118 final Subscription[] subscriptions = application.getRecommendedSubscriptions
(); | 115 final Subscription[] subscriptions = application.getRecommendedSubscriptions
(); |
119 | |
120 final String[] entries = new String[subscriptions.length]; | 116 final String[] entries = new String[subscriptions.length]; |
121 final String[] entryValues = new String[subscriptions.length]; | 117 final String[] entryValues = new String[subscriptions.length]; |
122 int i = 0; | 118 int i = 0; |
123 for (final Subscription subscription : subscriptions) | 119 for (final Subscription subscription : subscriptions) |
124 { | 120 { |
125 entries[i] = subscription.title; | 121 entries[i] = subscription.title; |
126 entryValues[i] = subscription.url; | 122 entryValues[i] = subscription.url; |
127 i++; | 123 i++; |
128 } | 124 } |
129 subscriptionList.setEntries(entries); | 125 subscriptionList.setEntries(entries); |
130 subscriptionList.setEntryValues(entryValues); | 126 subscriptionList.setEntryValues(entryValues); |
131 | 127 |
132 // Set Acceptable Ads FAQ link | 128 // Set Acceptable Ads FAQ link |
133 final HelpfulCheckBoxPreference acceptableAdsCheckBox = | 129 final HelpfulCheckBoxPreference acceptableAdsCheckBox = |
134 (HelpfulCheckBoxPreference) findPreference(getString(R.string.pref_accep
tableads)); | 130 (HelpfulCheckBoxPreference) findPreference(getString(R.string.pref_accep
tableads)); |
135 acceptableAdsCheckBox.setHelpUrl(AdblockPlus.getApplication().getAcceptableA
dsUrl()); | 131 acceptableAdsCheckBox.setHelpUrl(AdblockPlus.getApplication().getAcceptableA
dsUrl()); |
136 } | 132 } |
137 | 133 |
138 @SuppressWarnings("deprecation") | |
139 @Override | 134 @Override |
140 public void onResume() | 135 public void onResume() |
141 { | 136 { |
142 super.onResume(); | 137 super.onResume(); |
143 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(this); | 138 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(this); |
144 | 139 |
145 final AdblockPlus application = AdblockPlus.getApplication(); | 140 final AdblockPlus application = AdblockPlus.getApplication(); |
146 | 141 |
147 Subscription current = null; | 142 Subscription current = null; |
148 final Subscription[] subscriptions = application.getListedSubscriptions(); | 143 final Subscription[] subscriptions = application.getListedSubscriptions(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 252 } |
258 | 253 |
259 @Override | 254 @Override |
260 public boolean onCreateOptionsMenu(final Menu menu) | 255 public boolean onCreateOptionsMenu(final Menu menu) |
261 { | 256 { |
262 final MenuInflater inflater = getSupportMenuInflater(); | 257 final MenuInflater inflater = getSupportMenuInflater(); |
263 inflater.inflate(R.menu.menu_preferences, menu); | 258 inflater.inflate(R.menu.menu_preferences, menu); |
264 return true; | 259 return true; |
265 } | 260 } |
266 | 261 |
267 @SuppressWarnings("deprecation") | |
268 @Override | 262 @Override |
269 public boolean onOptionsItemSelected(final MenuItem item) | 263 public boolean onOptionsItemSelected(final MenuItem item) |
270 { | 264 { |
271 switch (item.getItemId()) | 265 switch (item.getItemId()) |
272 { | 266 { |
273 case R.id.menu_help: | 267 case R.id.menu_help: |
274 final Uri uri = Uri.parse(getString(R.string.configuring_url)); | 268 final Uri uri = Uri.parse(getString(R.string.configuring_url)); |
275 final Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 269 final Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
276 startActivity(intent); | 270 startActivity(intent); |
277 return true; | 271 return true; |
278 case R.id.menu_about: | 272 case R.id.menu_about: |
279 showDialog(ABOUT_DIALOG); | 273 showDialog(ABOUT_DIALOG); |
280 return true; | 274 return true; |
281 case R.id.menu_advanced: | 275 case R.id.menu_advanced: |
282 startActivity(new Intent(this, AdvancedPreferences.class)); | 276 startActivity(new Intent(this, AdvancedPreferences.class)); |
283 return true; | 277 return true; |
284 default: | 278 default: |
285 return super.onOptionsItemSelected(item); | 279 return super.onOptionsItemSelected(item); |
286 } | 280 } |
287 } | 281 } |
288 | 282 |
289 @SuppressWarnings("deprecation") | |
290 private void setAcceptableAdsEnabled(final boolean enabled) | 283 private void setAcceptableAdsEnabled(final boolean enabled) |
291 { | 284 { |
292 final CheckBoxPreference acceptableAdsPreference = | 285 final CheckBoxPreference acceptableAdsPreference = |
293 (CheckBoxPreference) findPreference(getString(R.string.pref_acceptablead
s)); | 286 (CheckBoxPreference) findPreference(getString(R.string.pref_acceptablead
s)); |
294 acceptableAdsPreference.setChecked(enabled); | 287 acceptableAdsPreference.setChecked(enabled); |
295 final AdblockPlus application = AdblockPlus.getApplication(); | 288 final AdblockPlus application = AdblockPlus.getApplication(); |
296 application.setAcceptableAdsEnabled(enabled); | 289 application.setAcceptableAdsEnabled(enabled); |
297 } | 290 } |
298 | 291 |
299 @SuppressWarnings("deprecation") | |
300 private void setFilteringEnabled(final boolean enabled) | 292 private void setFilteringEnabled(final boolean enabled) |
301 { | 293 { |
302 final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPr
eferences(this).edit(); | 294 final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPr
eferences(this).edit(); |
303 editor.putBoolean(getString(R.string.pref_enabled), enabled); | 295 editor.putBoolean(getString(R.string.pref_enabled), enabled); |
304 editor.commit(); | 296 editor.commit(); |
305 ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChe
cked(enabled); | 297 ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChe
cked(enabled); |
306 final AdblockPlus application = AdblockPlus.getApplication(); | 298 final AdblockPlus application = AdblockPlus.getApplication(); |
307 application.setFilteringEnabled(enabled); | 299 application.setFilteringEnabled(enabled); |
308 } | 300 } |
309 | 301 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 391 } |
400 }); | 392 }); |
401 } | 393 } |
402 builder.setMessage(Html.fromHtml(message.toString())); | 394 builder.setMessage(Html.fromHtml(message.toString())); |
403 dialog = builder.create(); | 395 dialog = builder.create(); |
404 break; | 396 break; |
405 } | 397 } |
406 return dialog; | 398 return dialog; |
407 } | 399 } |
408 | 400 |
409 @SuppressWarnings("deprecation") | |
410 @Override | 401 @Override |
411 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
s, final String key) | 402 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
s, final String key) |
412 { | 403 { |
413 final AdblockPlus application = AdblockPlus.getApplication(); | 404 final AdblockPlus application = AdblockPlus.getApplication(); |
414 if (getString(R.string.pref_enabled).equals(key)) | 405 if (getString(R.string.pref_enabled).equals(key)) |
415 { | 406 { |
416 final boolean enabled = sharedPreferences.getBoolean(key, false); | 407 final boolean enabled = sharedPreferences.getBoolean(key, false); |
417 final boolean autoconfigured = sharedPreferences.getBoolean(getString(R.st
ring.pref_proxyautoconfigured), false); | 408 final boolean autoconfigured = sharedPreferences.getBoolean(getString(R.st
ring.pref_proxyautoconfigured), false); |
418 final boolean serviceRunning = application.isServiceRunning(); | 409 final boolean serviceRunning = application.isServiceRunning(); |
419 application.setFilteringEnabled(enabled); | 410 application.setFilteringEnabled(enabled); |
420 if (enabled) | 411 if (enabled) |
421 { | 412 { |
422 // If user has enabled filtering, enable proxy as well | 413 // If user has enabled filtering, enable proxy as well |
423 setProxyEnabled(true); | 414 setProxyEnabled(true); |
424 } | 415 } |
425 else if (serviceRunning && autoconfigured) | 416 else if (serviceRunning && autoconfigured) |
426 { | 417 { |
427 // If user disabled filtering disable proxy only if it was | 418 // If user disabled filtering disable proxy only if it was autoconfigure
d |
428 // autoconfigured | |
429 stopService(new Intent(this, ProxyService.class)); | 419 stopService(new Intent(this, ProxyService.class)); |
430 } | 420 } |
431 } | 421 } |
432 else if (getString(R.string.pref_acceptableads).equals(key)) | 422 else if (getString(R.string.pref_acceptableads).equals(key)) |
433 { | 423 { |
434 final boolean enabled = sharedPreferences.getBoolean(key, false); | 424 final boolean enabled = sharedPreferences.getBoolean(key, false); |
435 application.setAcceptableAdsEnabled(enabled); | 425 application.setAcceptableAdsEnabled(enabled); |
436 } | 426 } |
437 else if (getString(R.string.pref_subscription).equals(key)) | 427 else if (getString(R.string.pref_subscription).equals(key)) |
438 { | 428 { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 }; | 506 }; |
517 | 507 |
518 /** | 508 /** |
519 * Constructs and updates subscription status text. | 509 * Constructs and updates subscription status text. |
520 * | 510 * |
521 * @param text | 511 * @param text |
522 * status message | 512 * status message |
523 * @param time | 513 * @param time |
524 * time of last change | 514 * time of last change |
525 */ | 515 */ |
526 @SuppressWarnings("deprecation") | |
527 private void setSubscriptionStatus(final String text, final long time) | 516 private void setSubscriptionStatus(final String text, final long time) |
528 { | 517 { |
529 final ListPreference subscriptionList = (ListPreference) findPreference(getS
tring(R.string.pref_subscription)); | 518 final ListPreference subscriptionList = (ListPreference) findPreference(getS
tring(R.string.pref_subscription)); |
530 final CharSequence summary = subscriptionList.getEntry(); | 519 final CharSequence summary = subscriptionList.getEntry(); |
531 final StringBuilder builder = new StringBuilder(); | 520 final StringBuilder builder = new StringBuilder(); |
532 if (summary != null) | 521 if (summary != null) |
533 { | 522 { |
534 builder.append(summary); | 523 builder.append(summary); |
535 if (text != "") | 524 if (text != "") |
536 { | 525 { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 } | 573 } |
585 | 574 |
586 @Override | 575 @Override |
587 public void onServiceDisconnected(final ComponentName className) | 576 public void onServiceDisconnected(final ComponentName className) |
588 { | 577 { |
589 proxyService = null; | 578 proxyService = null; |
590 Log.d(TAG, "Proxy service disconnected"); | 579 Log.d(TAG, "Proxy service disconnected"); |
591 } | 580 } |
592 }; | 581 }; |
593 } | 582 } |
LEFT | RIGHT |