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

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

Issue 8960162: android: notification icon option (Closed)
Patch Set: Created Dec. 4, 2012, 6:37 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
1 /* 1 /*
2 * This file is part of the Adblock Plus, 2 * This file is part of the Adblock Plus,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android; 18 package org.adblockplus.android;
19 19
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.io.InputStream; 21 import java.io.InputStream;
22 import java.io.OutputStream; 22 import java.io.OutputStream;
23 import java.util.Calendar; 23 import java.util.Calendar;
24 import java.util.Date; 24 import java.util.Date;
25 import java.util.List; 25 import java.util.List;
26 26
27 import android.app.ActivityManager; 27 import android.app.ActivityManager;
28 import android.app.ActivityManager.RunningServiceInfo; 28 import android.app.ActivityManager.RunningServiceInfo;
29 import android.app.AlertDialog; 29 import android.app.AlertDialog;
30 import android.app.Dialog;
30 import android.content.BroadcastReceiver; 31 import android.content.BroadcastReceiver;
31 import android.content.ComponentName; 32 import android.content.ComponentName;
32 import android.content.Context; 33 import android.content.Context;
33 import android.content.DialogInterface; 34 import android.content.DialogInterface;
34 import android.content.ServiceConnection;
35 import android.content.DialogInterface.OnDismissListener;
36 import android.content.Intent; 35 import android.content.Intent;
37 import android.content.IntentFilter; 36 import android.content.IntentFilter;
37 import android.content.ServiceConnection;
38 import android.content.SharedPreferences; 38 import android.content.SharedPreferences;
39 import android.content.pm.PackageManager.NameNotFoundException; 39 import android.content.pm.PackageManager.NameNotFoundException;
40 import android.content.res.AssetManager; 40 import android.content.res.AssetManager;
41 import android.net.Uri; 41 import android.net.Uri;
42 import android.os.Bundle; 42 import android.os.Bundle;
43 import android.os.IBinder; 43 import android.os.IBinder;
44 import android.preference.CheckBoxPreference; 44 import android.preference.CheckBoxPreference;
45 import android.preference.ListPreference; 45 import android.preference.ListPreference;
46 import android.preference.PreferenceManager; 46 import android.preference.PreferenceManager;
47 import android.text.format.DateFormat; 47 import android.text.format.DateFormat;
48 import android.util.Log; 48 import android.util.Log;
49 import android.view.Menu; 49 import android.view.Menu;
50 import android.view.MenuInflater; 50 import android.view.MenuInflater;
51 import android.view.MenuItem; 51 import android.view.MenuItem;
52 import android.view.View; 52 import android.view.View;
53 import android.view.Window; 53 import android.view.Window;
54 import android.widget.TextView; 54 import android.widget.TextView;
55 55
56 /** 56 /**
57 * Main settings UI. 57 * Main settings UI.
58 */ 58 */
59 public class Preferences extends SummarizedPreferences 59 public class Preferences extends SummarizedPreferences
60 { 60 {
61 private static final String TAG = "Preferences"; 61 private static final String TAG = "Preferences";
62 62
63 private static final int ABOUT_DIALOG = 1;
64 private static final int HIDEICONWARNING_DIALOG = 2;
65
63 private static ProxyService proxyService = null; 66 private static ProxyService proxyService = null;
64 67
65 private RefreshableListPreference subscriptionList; 68 private RefreshableListPreference subscriptionList;
66 69
67 private AboutDialog aboutDialog;
68 private boolean showAbout = false;
69 private boolean trafficDetected = false; 70 private boolean trafficDetected = false;
70 private String subscriptionSummary; 71 private String subscriptionSummary;
71 72
72 @Override 73 @Override
73 public void onCreate(Bundle savedInstanceState) 74 public void onCreate(Bundle savedInstanceState)
74 { 75 {
75 requestWindowFeature(Window.FEATURE_NO_TITLE); 76 requestWindowFeature(Window.FEATURE_NO_TITLE);
76 77
77 super.onCreate(savedInstanceState); 78 super.onCreate(savedInstanceState);
78 79
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 { 201 {
201 setEnabled(false); 202 setEnabled(false);
202 } 203 }
203 // Run service if this is first application run 204 // Run service if this is first application run
204 else if (!enabled && firstRun) 205 else if (!enabled && firstRun)
205 { 206 {
206 startService(new Intent(this, ProxyService.class)); 207 startService(new Intent(this, ProxyService.class));
207 setEnabled(true); 208 setEnabled(true);
208 } 209 }
209 210
210 if (showAbout)
211 onAbout(findViewById(R.id.btn_about));
212
213 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ; 211 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ;
214 } 212 }
215 213
216 @Override 214 @Override
217 public void onPause() 215 public void onPause()
218 { 216 {
219 super.onPause(); 217 super.onPause();
220 try 218 try
221 { 219 {
222 unregisterReceiver(receiver); 220 unregisterReceiver(receiver);
223 } 221 }
224 catch (IllegalArgumentException e) 222 catch (IllegalArgumentException e)
225 { 223 {
226 // ignore - it is thrown if receiver is not registered but it can not be t rue in normal conditions 224 // ignore - it is thrown if receiver is not registered but it can not be t rue in normal conditions
227 } 225 }
228 unbindService(proxyServiceConnection); 226 unbindService(proxyServiceConnection);
229 proxyService = null; 227 proxyService = null;
230 } 228 }
231 229
232 @Override 230 @Override
233 protected void onStop() 231 protected void onStop()
234 { 232 {
235 super.onStop(); 233 super.onStop();
236 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); 234 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this );
237 boolean enabled = prefs.getBoolean(getString(R.string.pref_enabled), false); 235 boolean enabled = prefs.getBoolean(getString(R.string.pref_enabled), false);
238 AdblockPlus application = AdblockPlus.getApplication(); 236 AdblockPlus application = AdblockPlus.getApplication();
239 application.stopInteractive(); 237 application.stopInteractive();
240 if (!enabled) 238 if (!enabled)
241 application.stopEngine(true); 239 application.stopEngine(true);
242
243 if (aboutDialog != null)
244 aboutDialog.dismiss();
245 } 240 }
246 241
247 @Override 242 @Override
248 public boolean onCreateOptionsMenu(Menu menu) 243 public boolean onCreateOptionsMenu(Menu menu)
249 { 244 {
250 MenuInflater inflater = getMenuInflater(); 245 MenuInflater inflater = getMenuInflater();
251 inflater.inflate(R.menu.menu_preferences, menu); 246 inflater.inflate(R.menu.menu_preferences, menu);
252 return true; 247 return true;
253 } 248 }
254 249
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 Uri uri = Uri.parse(getString(R.string.configuring_url)); 332 Uri uri = Uri.parse(getString(R.string.configuring_url));
338 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 333 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
339 startActivity(intent); 334 startActivity(intent);
340 } 335 }
341 336
342 /** 337 /**
343 * Shows about dialog. 338 * Shows about dialog.
344 */ 339 */
345 public void onAbout(View view) 340 public void onAbout(View view)
346 { 341 {
347 aboutDialog = new AboutDialog(this); 342 showDialog(ABOUT_DIALOG);
348 aboutDialog.setOnDismissListener(new OnDismissListener()
349 {
350
351 @Override
352 public void onDismiss(DialogInterface dialog)
353 {
354 showAbout = false;
355 aboutDialog = null;
356 }
357 });
358 showAbout = true;
359 aboutDialog.show();
360 } 343 }
361 344
362 @Override 345 @Override
346 protected Dialog onCreateDialog(int id)
347 {
348 Dialog dialog = null;
349 switch (id)
350 {
351 case ABOUT_DIALOG:
352 dialog = new AboutDialog(this);
353 break;
354 case HIDEICONWARNING_DIALOG:
355 AlertDialog.Builder builder = new AlertDialog.Builder(this);
356 builder.setTitle(R.string.warning).setMessage(R.string.msg_hideicon_warn ing).setIcon(android.R.drawable.ic_dialog_alert).setCancelable(false)
357 .setPositiveButton(R.string.gotit, new DialogInterface.OnClickListen er()
358 {
359 public void onClick(DialogInterface dialog, int id)
360 {
361 dialog.cancel();
362 }
363 });
364 dialog = builder.create();
365 break;
366 }
367 return dialog;
368 }
369
370 @Override
363 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key) 371 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key)
364 { 372 {
365 if (getString(R.string.pref_enabled).equals(key)) 373 if (getString(R.string.pref_enabled).equals(key))
366 { 374 {
367 boolean enabled = sharedPreferences.getBoolean(key, false); 375 boolean enabled = sharedPreferences.getBoolean(key, false);
368 boolean serviceRunning = isServiceRunning(); 376 boolean serviceRunning = isServiceRunning();
369 if (enabled && !serviceRunning) 377 if (enabled && !serviceRunning)
370 startService(new Intent(this, ProxyService.class)); 378 startService(new Intent(this, ProxyService.class));
371 else if (!enabled && serviceRunning) 379 else if (!enabled && serviceRunning)
372 stopService(new Intent(this, ProxyService.class)); 380 stopService(new Intent(this, ProxyService.class));
373 } 381 }
374 if (getString(R.string.pref_subscription).equals(key)) 382 else if (getString(R.string.pref_subscription).equals(key))
375 { 383 {
376 String current = sharedPreferences.getString(key, null); 384 String current = sharedPreferences.getString(key, null);
377 AdblockPlus application = AdblockPlus.getApplication(); 385 AdblockPlus application = AdblockPlus.getApplication();
378 Subscription subscription = application.getSubscription(current); 386 Subscription subscription = application.getSubscription(current);
379 application.setSubscription(subscription); 387 application.setSubscription(subscription);
380 } 388 }
389 else if (getString(R.string.pref_hideicon).equals(key))
390 {
391 boolean hideIcon = sharedPreferences.getBoolean(key, false);
392 if (hideIcon)
393 showDialog(HIDEICONWARNING_DIALOG);
394 if (proxyService != null)
395 proxyService.setEmptyIcon(hideIcon);
396 }
381 super.onSharedPreferenceChanged(sharedPreferences, key); 397 super.onSharedPreferenceChanged(sharedPreferences, key);
382 } 398 }
383 399
384 private void showConfigurationMsg(String message) 400 private void showConfigurationMsg(String message)
385 { 401 {
386 TextView msg = (TextView) findViewById(R.id.txt_configuration); 402 TextView msg = (TextView) findViewById(R.id.txt_configuration);
387 msg.setText(message); 403 msg.setText(message);
388 msg.setVisibility(View.VISIBLE); 404 msg.setVisibility(View.VISIBLE);
389 } 405 }
390 406
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 499 }
484 subscriptionSummary = builder.toString(); 500 subscriptionSummary = builder.toString();
485 subscriptionList.setSummary(subscriptionSummary); 501 subscriptionList.setSummary(subscriptionSummary);
486 } 502 }
487 } 503 }
488 504
489 @Override 505 @Override
490 protected void onRestoreInstanceState(Bundle state) 506 protected void onRestoreInstanceState(Bundle state)
491 { 507 {
492 super.onRestoreInstanceState(state); 508 super.onRestoreInstanceState(state);
493 showAbout = state.getBoolean("showAbout");
494 trafficDetected = state.getBoolean("trafficDetected"); 509 trafficDetected = state.getBoolean("trafficDetected");
495 subscriptionSummary = state.getString("subscriptionSummary"); 510 subscriptionSummary = state.getString("subscriptionSummary");
496 } 511 }
497 512
498 @Override 513 @Override
499 protected void onSaveInstanceState(Bundle outState) 514 protected void onSaveInstanceState(Bundle outState)
500 { 515 {
501 outState.putString("subscriptionSummary", subscriptionSummary); 516 outState.putString("subscriptionSummary", subscriptionSummary);
502 outState.putBoolean("trafficDetected", trafficDetected); 517 outState.putBoolean("trafficDetected", trafficDetected);
503 outState.putBoolean("showAbout", showAbout);
504 super.onSaveInstanceState(outState); 518 super.onSaveInstanceState(outState);
505 } 519 }
506 520
507 private ServiceConnection proxyServiceConnection = new ServiceConnection() 521 private ServiceConnection proxyServiceConnection = new ServiceConnection()
508 { 522 {
509 public void onServiceConnected(ComponentName className, IBinder service) 523 public void onServiceConnected(ComponentName className, IBinder service)
510 { 524 {
511 proxyService = ((ProxyService.LocalBinder) service).getService(); 525 proxyService = ((ProxyService.LocalBinder) service).getService();
512 Log.d(TAG, "Proxy service connected"); 526 Log.d(TAG, "Proxy service connected");
513 527
514 if (!trafficDetected && proxyService.isManual()) 528 if (!trafficDetected && proxyService.isManual())
515 showConfigurationMsg(getString(R.string.msg_configuration, proxyServic e.port)); 529 showConfigurationMsg(getString(R.string.msg_configuration, proxyServic e.port));
516 } 530 }
517 531
518 public void onServiceDisconnected(ComponentName className) 532 public void onServiceDisconnected(ComponentName className)
519 { 533 {
520 proxyService = null; 534 proxyService = null;
521 Log.d(TAG, "Proxy service disconnected"); 535 Log.d(TAG, "Proxy service disconnected");
522 } 536 }
523 }; 537 };
524 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld