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

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

Issue 8943041: ABP/Android Notification not showing fix (Closed)
Patch Set: Created Nov. 23, 2012, 1:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/org/adblockplus/android/ProxyService.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 10 matching lines...) Expand all
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.content.BroadcastReceiver; 30 import android.content.BroadcastReceiver;
31 import android.content.ComponentName;
31 import android.content.Context; 32 import android.content.Context;
32 import android.content.DialogInterface; 33 import android.content.DialogInterface;
34 import android.content.ServiceConnection;
33 import android.content.DialogInterface.OnDismissListener; 35 import android.content.DialogInterface.OnDismissListener;
34 import android.content.Intent; 36 import android.content.Intent;
35 import android.content.IntentFilter; 37 import android.content.IntentFilter;
36 import android.content.SharedPreferences; 38 import android.content.SharedPreferences;
37 import android.content.pm.PackageManager.NameNotFoundException; 39 import android.content.pm.PackageManager.NameNotFoundException;
38 import android.content.res.AssetManager; 40 import android.content.res.AssetManager;
39 import android.net.Uri; 41 import android.net.Uri;
40 import android.os.Bundle; 42 import android.os.Bundle;
43 import android.os.IBinder;
41 import android.preference.CheckBoxPreference; 44 import android.preference.CheckBoxPreference;
42 import android.preference.ListPreference; 45 import android.preference.ListPreference;
43 import android.preference.PreferenceManager; 46 import android.preference.PreferenceManager;
44 import android.text.format.DateFormat; 47 import android.text.format.DateFormat;
45 import android.util.Log; 48 import android.util.Log;
46 import android.view.Menu; 49 import android.view.Menu;
47 import android.view.MenuInflater; 50 import android.view.MenuInflater;
48 import android.view.MenuItem; 51 import android.view.MenuItem;
49 import android.view.View; 52 import android.view.View;
50 import android.view.Window; 53 import android.view.Window;
51 import android.widget.TextView; 54 import android.widget.TextView;
52 55
53 /** 56 /**
54 * Main settings UI. 57 * Main settings UI.
55 */ 58 */
56 public class Preferences extends SummarizedPreferences 59 public class Preferences extends SummarizedPreferences
57 { 60 {
58 private static final String TAG = "Preferences"; 61 private static final String TAG = "Preferences";
59 62
63 private static ProxyService proxyService = null;
64
60 private AboutDialog aboutDialog; 65 private AboutDialog aboutDialog;
61 private boolean showAbout = false; 66 private boolean showAbout = false;
62 private String configurationMsg; 67 private boolean trafficDetected = false;
63 private String subscriptionSummary; 68 private String subscriptionSummary;
64 69
65 @Override 70 @Override
66 public void onCreate(Bundle savedInstanceState) 71 public void onCreate(Bundle savedInstanceState)
67 { 72 {
68 requestWindowFeature(Window.FEATURE_NO_TITLE); 73 requestWindowFeature(Window.FEATURE_NO_TITLE);
69 74
70 super.onCreate(savedInstanceState); 75 super.onCreate(savedInstanceState);
71 76
72 PreferenceManager.setDefaultValues(this, R.xml.preferences, false); 77 PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 { 194 {
190 setEnabled(false); 195 setEnabled(false);
191 } 196 }
192 // Run service if this is first application run 197 // Run service if this is first application run
193 else if (!enabled && firstRun) 198 else if (!enabled && firstRun)
194 { 199 {
195 startService(new Intent(this, ProxyService.class)); 200 startService(new Intent(this, ProxyService.class));
196 setEnabled(true); 201 setEnabled(true);
197 } 202 }
198 203
199 // Process screen rotation
200 if (configurationMsg != null)
201 showConfigurationMsg(configurationMsg);
202
203 if (showAbout) 204 if (showAbout)
204 onAbout(findViewById(R.id.btn_about)); 205 onAbout(findViewById(R.id.btn_about));
206
207 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ;
205 } 208 }
206 209
207 @Override 210 @Override
208 public void onPause() 211 public void onPause()
209 { 212 {
210 super.onPause(); 213 super.onPause();
211 unregisterReceiver(receiver); 214 unregisterReceiver(receiver);
215 unbindService(proxyServiceConnection);
216 proxyService = null;
212 } 217 }
213 218
214 @Override 219 @Override
215 protected void onStop() 220 protected void onStop()
216 { 221 {
217 super.onStop(); 222 super.onStop();
218 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); 223 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this );
219 boolean enabled = prefs.getBoolean(getString(R.string.pref_enabled), false); 224 boolean enabled = prefs.getBoolean(getString(R.string.pref_enabled), false);
220 AdblockPlus application = AdblockPlus.getApplication(); 225 AdblockPlus application = AdblockPlus.getApplication();
221 application.stopInteractive(); 226 application.stopInteractive();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 application.setSubscription(subscription); 366 application.setSubscription(subscription);
362 } 367 }
363 super.onSharedPreferenceChanged(sharedPreferences, key); 368 super.onSharedPreferenceChanged(sharedPreferences, key);
364 } 369 }
365 370
366 private void showConfigurationMsg(String message) 371 private void showConfigurationMsg(String message)
367 { 372 {
368 TextView msg = (TextView) findViewById(R.id.txt_configuration); 373 TextView msg = (TextView) findViewById(R.id.txt_configuration);
369 msg.setText(message); 374 msg.setText(message);
370 msg.setVisibility(View.VISIBLE); 375 msg.setVisibility(View.VISIBLE);
371 configurationMsg = message;
372 } 376 }
373 377
374 private void hideConfigurationMsg() 378 private void hideConfigurationMsg()
375 { 379 {
376 if (configurationMsg == null)
377 return;
378 TextView msg = (TextView) findViewById(R.id.txt_configuration); 380 TextView msg = (TextView) findViewById(R.id.txt_configuration);
379 msg.setVisibility(View.GONE); 381 msg.setVisibility(View.GONE);
380 configurationMsg = null;
381 } 382 }
382 383
383 private BroadcastReceiver receiver = new BroadcastReceiver() 384 private BroadcastReceiver receiver = new BroadcastReceiver()
384 { 385 {
385 @Override 386 @Override
386 public void onReceive(Context context, Intent intent) 387 public void onReceive(Context context, Intent intent)
387 { 388 {
388 String action = intent.getAction(); 389 String action = intent.getAction();
389 Bundle extra = intent.getExtras(); 390 Bundle extra = intent.getExtras();
390 if (action.equals(ProxyService.BROADCAST_STATE_CHANGED)) 391 if (action.equals(ProxyService.BROADCAST_STATE_CHANGED))
391 { 392 {
392 if (extra.getBoolean("enabled")) 393 if (extra.getBoolean("enabled"))
393 { 394 {
394 // If service is enabled in manual mode, show configuration message 395 // If service is enabled in manual mode, show configuration message
395 if (extra.getBoolean("manual")) 396 if (extra.getBoolean("manual"))
396 { 397 {
397 showConfigurationMsg(getString(R.string.msg_configuration, extra.get Int("port"))); 398 showConfigurationMsg(getString(R.string.msg_configuration, extra.get Int("port")));
398 } 399 }
399 } 400 }
400 else 401 else
401 { 402 {
402 setEnabled(false); 403 setEnabled(false);
403 hideConfigurationMsg(); 404 hideConfigurationMsg();
404 } 405 }
405 } 406 }
406 if (action.equals(AdblockPlus.BROADCAST_FILTER_MATCHES)) 407 if (action.equals(AdblockPlus.BROADCAST_FILTER_MATCHES))
407 { 408 {
408 // Hide configuration message if traffic is detected 409 // Hide configuration message if traffic is detected for the first time
409 hideConfigurationMsg(); 410 if (! trafficDetected)
Felix Dahlke 2012/11/23 13:19:43 Preferably no space after ! here.
Andrey Novikov 2012/11/30 09:43:39 Done.
411 hideConfigurationMsg();
412 trafficDetected = true;
410 } 413 }
411 if (action.equals(ProxyService.BROADCAST_PROXY_FAILED)) 414 if (action.equals(ProxyService.BROADCAST_PROXY_FAILED))
412 { 415 {
413 String msg = extra.getString("msg"); 416 String msg = extra.getString("msg");
414 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(); 417 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();
415 setEnabled(false); 418 setEnabled(false);
416 } 419 }
417 if (action.equals(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)) 420 if (action.equals(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS))
418 { 421 {
419 final String text = extra.getString("text"); 422 final String text = extra.getString("text");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 subscriptionSummary = builder.toString(); 471 subscriptionSummary = builder.toString();
469 subscriptionList.setSummary(subscriptionSummary); 472 subscriptionList.setSummary(subscriptionSummary);
470 } 473 }
471 } 474 }
472 475
473 @Override 476 @Override
474 protected void onRestoreInstanceState(Bundle state) 477 protected void onRestoreInstanceState(Bundle state)
475 { 478 {
476 super.onRestoreInstanceState(state); 479 super.onRestoreInstanceState(state);
477 showAbout = state.getBoolean("showAbout"); 480 showAbout = state.getBoolean("showAbout");
478 configurationMsg = state.getString("configurationMsg"); 481 trafficDetected = state.getBoolean("trafficDetected");
479 subscriptionSummary = state.getString("subscriptionSummary"); 482 subscriptionSummary = state.getString("subscriptionSummary");
480 } 483 }
481 484
482 @Override 485 @Override
483 protected void onSaveInstanceState(Bundle outState) 486 protected void onSaveInstanceState(Bundle outState)
484 { 487 {
485 outState.putString("subscriptionSummary", subscriptionSummary); 488 outState.putString("subscriptionSummary", subscriptionSummary);
486 outState.putString("configurationMsg", configurationMsg); 489 outState.putBoolean("trafficDetected", trafficDetected);
487 outState.putBoolean("showAbout", showAbout); 490 outState.putBoolean("showAbout", showAbout);
488 super.onSaveInstanceState(outState); 491 super.onSaveInstanceState(outState);
489 } 492 }
493
494 private ServiceConnection proxyServiceConnection = new ServiceConnection()
495 {
496 public void onServiceConnected(ComponentName className, IBinder service)
497 {
498 proxyService = ((ProxyService.LocalBinder) service).getService();
499 Log.d(TAG, "Proxy service connected");
500
501 if (! trafficDetected && proxyService.isManual())
Felix Dahlke 2012/11/23 13:19:43 Preferably no space after ! here.
Andrey Novikov 2012/11/30 09:43:39 Done.
502 showConfigurationMsg(getString(R.string.msg_configuration, proxyServic e.port));
503 }
504
505 public void onServiceDisconnected(ComponentName className)
506 {
507 proxyService = null;
508 Log.d(TAG, "Proxy service disconnected");
509 }
510 };
490 } 511 }
OLDNEW
« no previous file with comments | « no previous file | src/org/adblockplus/android/ProxyService.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld