| 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 10 matching lines...) Expand all  Loading... | 
| 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 | 25 | 
| 26 import org.jraf.android.backport.switchwidget.SwitchPreference; | 26 import org.jraf.android.backport.switchwidget.SwitchPreference; | 
| 27 | 27 | 
| 28 import android.app.AlertDialog; | 28 import android.app.AlertDialog; | 
| 29 import android.app.Dialog; | 29 import android.app.Dialog; | 
| 30 import android.content.BroadcastReceiver; | 30 import android.content.BroadcastReceiver; | 
| 31 import android.content.ComponentName; |  | 
| 32 import android.content.Context; | 31 import android.content.Context; | 
| 33 import android.content.DialogInterface; | 32 import android.content.DialogInterface; | 
| 34 import android.content.Intent; | 33 import android.content.Intent; | 
| 35 import android.content.IntentFilter; | 34 import android.content.IntentFilter; | 
| 36 import android.content.ServiceConnection; |  | 
| 37 import android.content.SharedPreferences; | 35 import android.content.SharedPreferences; | 
| 38 import android.content.pm.PackageManager.NameNotFoundException; | 36 import android.content.pm.PackageManager.NameNotFoundException; | 
| 39 import android.content.res.AssetManager; | 37 import android.content.res.AssetManager; | 
| 40 import android.net.Uri; | 38 import android.net.Uri; | 
| 41 import android.os.Build; | 39 import android.os.Build; | 
| 42 import android.os.Bundle; | 40 import android.os.Bundle; | 
| 43 import android.os.IBinder; |  | 
| 44 import android.preference.CheckBoxPreference; | 41 import android.preference.CheckBoxPreference; | 
| 45 import android.preference.ListPreference; | 42 import android.preference.ListPreference; | 
| 46 import android.preference.PreferenceManager; | 43 import android.preference.PreferenceManager; | 
| 47 import android.text.Html; | 44 import android.text.Html; | 
| 48 import android.text.TextUtils; | 45 import android.text.TextUtils; | 
| 49 import android.text.format.DateFormat; | 46 import android.text.format.DateFormat; | 
| 50 import android.text.method.LinkMovementMethod; | 47 import android.text.method.LinkMovementMethod; | 
| 51 import android.util.Log; | 48 import android.util.Log; | 
| 52 import android.view.View; | 49 import android.view.View; | 
| 53 import android.view.ViewGroup; | 50 import android.view.ViewGroup; | 
| 54 import android.widget.TextView; | 51 import android.widget.TextView; | 
| 55 | 52 | 
| 56 import com.actionbarsherlock.view.Menu; | 53 import com.actionbarsherlock.view.Menu; | 
| 57 import com.actionbarsherlock.view.MenuInflater; | 54 import com.actionbarsherlock.view.MenuInflater; | 
| 58 import com.actionbarsherlock.view.MenuItem; | 55 import com.actionbarsherlock.view.MenuItem; | 
| 59 | 56 | 
| 60 /** | 57 /** | 
| 61  * Main settings UI. | 58  * Main settings UI. | 
| 62  */ | 59  */ | 
| 63 public class Preferences extends SummarizedPreferences | 60 public class Preferences extends SummarizedPreferences | 
| 64 { | 61 { | 
| 65   private static final String TAG = Utils.getTag(Preferences.class); | 62   private static final String TAG = Utils.getTag(Preferences.class); | 
| 66   private static final int ABOUT_DIALOG = 1; | 63   private static final int ABOUT_DIALOG = 1; | 
| 67   private static final int HIDEICONWARNING_DIALOG = 2; | 64   private static final int HIDEICONWARNING_DIALOG = 2; | 
| 68 | 65 | 
| 69   private static ProxyService proxyService = null; |  | 
| 70   private static boolean firstRunActionsPending = true; | 66   private static boolean firstRunActionsPending = true; | 
| 71 | 67 | 
| 72   private RefreshableListPreference subscriptionList; | 68   private RefreshableListPreference subscriptionList; | 
| 73   private String subscriptionSummary; | 69   private String subscriptionSummary; | 
| 74 | 70 | 
|  | 71   private ServiceBinder serviceBinder = null; | 
|  | 72 | 
| 75   @Override | 73   @Override | 
| 76   public void onCreate(final Bundle savedInstanceState) | 74   public void onCreate(final Bundle savedInstanceState) | 
| 77   { | 75   { | 
| 78     super.onCreate(savedInstanceState); | 76     super.onCreate(savedInstanceState); | 
| 79 | 77 | 
|  | 78     this.serviceBinder = new ServiceBinder(this).setOnConnectHandler(new Service
     Binder.OnConnectHandler() | 
|  | 79     { | 
|  | 80       @Override | 
|  | 81       public void onConnect(final ProxyService proxyService) | 
|  | 82       { | 
|  | 83         if (proxyService.isManual() && !proxyService.isRegistered()) | 
|  | 84         { | 
|  | 85           Preferences.this.showConfigurationMsg(Preferences.this.getString(R.str
     ing.msg_configuration)); | 
|  | 86         } | 
|  | 87       } | 
|  | 88     }); | 
|  | 89 | 
| 80     PreferenceManager.setDefaultValues(this, R.xml.preferences, true); | 90     PreferenceManager.setDefaultValues(this, R.xml.preferences, true); | 
| 81     PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true); | 91     PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true); | 
| 82     setContentView(R.layout.preferences); | 92     setContentView(R.layout.preferences); | 
| 83     addPreferencesFromResource(R.xml.preferences); | 93     addPreferencesFromResource(R.xml.preferences); | 
| 84 | 94 | 
| 85     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
     s(this); | 95     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
     s(this); | 
| 86 | 96 | 
| 87     // Check if we need to update assets | 97     // Check if we need to update assets | 
| 88     final int lastVersion = prefs.getInt(getString(R.string.pref_version), 0); | 98     final int lastVersion = prefs.getInt(getString(R.string.pref_version), 0); | 
| 89     try | 99     try | 
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 197     final boolean autoconfigured = prefs.getBoolean(getString(R.string.pref_prox
     yautoconfigured), false); | 207     final boolean autoconfigured = prefs.getBoolean(getString(R.string.pref_prox
     yautoconfigured), false); | 
| 198 | 208 | 
| 199     // This is weird but UI does not update on back button (when returning from 
     advanced preferences) | 209     // This is weird but UI does not update on back button (when returning from 
     advanced preferences) | 
| 200     ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChe
     cked(enabled); | 210     ((SwitchPreference) findPreference(getString(R.string.pref_enabled))).setChe
     cked(enabled); | 
| 201 | 211 | 
| 202     if (enabled || firstRun) | 212     if (enabled || firstRun) | 
| 203       setFilteringEnabled(true); | 213       setFilteringEnabled(true); | 
| 204     if (enabled || firstRun || (proxyenabled && !autoconfigured)) | 214     if (enabled || firstRun || (proxyenabled && !autoconfigured)) | 
| 205       setProxyEnabled(true); | 215       setProxyEnabled(true); | 
| 206 | 216 | 
| 207     bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0)
     ; | 217     this.serviceBinder.bind(); | 
| 208   } | 218   } | 
| 209 | 219 | 
| 210   private void showNotificationDialog(final String title, String message, String
      url) | 220   private void showNotificationDialog(final String title, String message, String
      url) | 
| 211   { | 221   { | 
| 212     url = TextUtils.htmlEncode(url); | 222     url = TextUtils.htmlEncode(url); | 
| 213     message = TextUtils.htmlEncode(message) | 223     message = TextUtils.htmlEncode(message) | 
| 214         .replaceAll("<a>(.*?)</a>", "<a href=\"" + url + "\">$1</a>"
     ); | 224         .replaceAll("<a>(.*?)</a>", "<a href=\"" + url + "\">$1</a>"
     ); | 
| 215     final TextView messageView = new TextView(this); | 225     final TextView messageView = new TextView(this); | 
| 216     messageView.setText(Html.fromHtml(message)); | 226     messageView.setText(Html.fromHtml(message)); | 
| 217     messageView.setMovementMethod(LinkMovementMethod.getInstance()); | 227     messageView.setMovementMethod(LinkMovementMethod.getInstance()); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 229     super.onPause(); | 239     super.onPause(); | 
| 230     try | 240     try | 
| 231     { | 241     { | 
| 232       unregisterReceiver(receiver); | 242       unregisterReceiver(receiver); | 
| 233     } | 243     } | 
| 234     catch (final IllegalArgumentException e) | 244     catch (final IllegalArgumentException e) | 
| 235     { | 245     { | 
| 236       // ignore - it is thrown if receiver is not registered but it can not be | 246       // ignore - it is thrown if receiver is not registered but it can not be | 
| 237       // true in normal conditions | 247       // true in normal conditions | 
| 238     } | 248     } | 
| 239     unbindService(proxyServiceConnection); | 249     this.serviceBinder.unbind(); | 
| 240     proxyService = null; |  | 
| 241 | 250 | 
| 242     hideConfigurationMsg(); | 251     hideConfigurationMsg(); | 
| 243   } | 252   } | 
| 244 | 253 | 
| 245   @Override | 254   @Override | 
| 246   protected void onStop() | 255   protected void onStop() | 
| 247   { | 256   { | 
| 248     super.onStop(); | 257     super.onStop(); | 
| 249     final AdblockPlus application = AdblockPlus.getApplication(); | 258     final AdblockPlus application = AdblockPlus.getApplication(); | 
| 250     if (!application.isFilteringEnabled()) | 259     if (!application.isFilteringEnabled()) | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 343       } | 352       } | 
| 344       catch (final Exception e) | 353       catch (final Exception e) | 
| 345       { | 354       { | 
| 346         Log.e(TAG, "Asset copy error", e); | 355         Log.e(TAG, "Asset copy error", e); | 
| 347       } | 356       } | 
| 348     } | 357     } | 
| 349   } | 358   } | 
| 350 | 359 | 
| 351   public void showProxySettings(final View v) | 360   public void showProxySettings(final View v) | 
| 352   { | 361   { | 
| 353     startActivity(new Intent(this, ProxyConfigurationActivity.class).putExtra("p
     ort", proxyService.port)); | 362     final ProxyService proxyService = this.serviceBinder.get(); | 
|  | 363     if (proxyService != null) | 
|  | 364     { | 
|  | 365       startActivity(new Intent(this, ProxyConfigurationActivity.class).putExtra(
     "port", proxyService.port)); | 
|  | 366     } | 
| 354   } | 367   } | 
| 355 | 368 | 
| 356   @Override | 369   @Override | 
| 357   protected Dialog onCreateDialog(final int id) | 370   protected Dialog onCreateDialog(final int id) | 
| 358   { | 371   { | 
| 359     Dialog dialog = null; | 372     Dialog dialog = null; | 
| 360     switch (id) | 373     switch (id) | 
| 361     { | 374     { | 
| 362       case ABOUT_DIALOG: | 375       case ABOUT_DIALOG: | 
| 363         dialog = new AboutDialog(this); | 376         dialog = new AboutDialog(this); | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 428     { | 441     { | 
| 429       final String url = sharedPreferences.getString(key, null); | 442       final String url = sharedPreferences.getString(key, null); | 
| 430       if (url != null) | 443       if (url != null) | 
| 431         application.setSubscription(url); | 444         application.setSubscription(url); | 
| 432     } | 445     } | 
| 433     else if (getString(R.string.pref_hideicon).equals(key)) | 446     else if (getString(R.string.pref_hideicon).equals(key)) | 
| 434     { | 447     { | 
| 435       final boolean hideIcon = sharedPreferences.getBoolean(key, false); | 448       final boolean hideIcon = sharedPreferences.getBoolean(key, false); | 
| 436       if (hideIcon) | 449       if (hideIcon) | 
| 437         showDialog(HIDEICONWARNING_DIALOG); | 450         showDialog(HIDEICONWARNING_DIALOG); | 
|  | 451       final ProxyService proxyService = this.serviceBinder.get(); | 
| 438       if (proxyService != null) | 452       if (proxyService != null) | 
| 439         proxyService.setEmptyIcon(hideIcon); | 453         proxyService.setEmptyIcon(hideIcon); | 
| 440     } | 454     } | 
| 441     super.onSharedPreferenceChanged(sharedPreferences, key); | 455     super.onSharedPreferenceChanged(sharedPreferences, key); | 
| 442   } | 456   } | 
| 443 | 457 | 
| 444   private void showConfigurationMsg(final String message) | 458   private void showConfigurationMsg(final String message) | 
| 445   { | 459   { | 
| 446     final ViewGroup grp = (ViewGroup) findViewById(R.id.grp_configuration); | 460     final ViewGroup grp = (ViewGroup) findViewById(R.id.grp_configuration); | 
| 447     final TextView msg = (TextView) findViewById(R.id.txt_configuration); | 461     final TextView msg = (TextView) findViewById(R.id.txt_configuration); | 
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 552     super.onRestoreInstanceState(state); | 566     super.onRestoreInstanceState(state); | 
| 553     subscriptionSummary = state.getString("subscriptionSummary"); | 567     subscriptionSummary = state.getString("subscriptionSummary"); | 
| 554   } | 568   } | 
| 555 | 569 | 
| 556   @Override | 570   @Override | 
| 557   protected void onSaveInstanceState(final Bundle outState) | 571   protected void onSaveInstanceState(final Bundle outState) | 
| 558   { | 572   { | 
| 559     outState.putString("subscriptionSummary", subscriptionSummary); | 573     outState.putString("subscriptionSummary", subscriptionSummary); | 
| 560     super.onSaveInstanceState(outState); | 574     super.onSaveInstanceState(outState); | 
| 561   } | 575   } | 
| 562 |  | 
| 563   private final ServiceConnection proxyServiceConnection = new ServiceConnection
     () |  | 
| 564   { |  | 
| 565     @Override |  | 
| 566     public void onServiceConnected(final ComponentName className, final IBinder 
     service) |  | 
| 567     { |  | 
| 568       proxyService = ((ProxyService.LocalBinder) service).getService(); |  | 
| 569       Log.d(TAG, "Proxy service connected"); |  | 
| 570 |  | 
| 571       if (proxyService.isManual() && proxyService.noTraffic()) |  | 
| 572         showConfigurationMsg(getString(R.string.msg_configuration)); |  | 
| 573     } |  | 
| 574 |  | 
| 575     @Override |  | 
| 576     public void onServiceDisconnected(final ComponentName className) |  | 
| 577     { |  | 
| 578       proxyService = null; |  | 
| 579       Log.d(TAG, "Proxy service disconnected"); |  | 
| 580     } |  | 
| 581   }; |  | 
| 582 } | 576 } | 
| OLD | NEW | 
|---|