| Index: src/org/adblockplus/android/AdvancedPreferences.java |
| diff --git a/src/org/adblockplus/android/AdvancedPreferences.java b/src/org/adblockplus/android/AdvancedPreferences.java |
| index 039f51fc3fb5e593700097ca925566fad7f1b904..bf976e80b7d50b92913b83d4cc5245d3668d799c 100644 |
| --- a/src/org/adblockplus/android/AdvancedPreferences.java |
| +++ b/src/org/adblockplus/android/AdvancedPreferences.java |
| @@ -45,55 +45,57 @@ import android.widget.Toast; |
| /** |
| * Advanced settings UI. |
| */ |
| +@SuppressWarnings("deprecation") |
| public class AdvancedPreferences extends SummarizedPreferences |
| { |
| - private static final String TAG = "AdvancedPreferences"; |
| - |
| - private static final int CONFIGURATION_DIALOG = 1; |
| + private final static String TAG = Utils.getTag(AdvancedPreferences.class); |
| + private final static int CONFIGURATION_DIALOG = 1; |
| private ProxyService proxyService = null; |
| @Override |
| - public void onCreate(Bundle savedInstanceState) |
| + public void onCreate(final Bundle savedInstanceState) |
| { |
| super.onCreate(savedInstanceState); |
| - addPreferencesFromResource(R.xml.preferences_advanced); |
| + this.addPreferencesFromResource(R.xml.preferences_advanced); |
|
Felix Dahlke
2014/04/16 15:24:25
ALso a bunch of unrelated changes here, same as be
René Jeschke
2014/04/16 17:51:47
Done.
|
| - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| - PreferenceScreen screen = getPreferenceScreen(); |
| + final PreferenceScreen screen = this.getPreferenceScreen(); |
| if (ProxyService.NATIVE_PROXY_SUPPORTED) |
| { |
| - screen.removePreference(findPreference(getString(R.string.pref_proxy))); |
| - if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) |
| + screen.removePreference(this.findPreference(this.getString(R.string.pref_proxy))); |
| + if (prefs.getBoolean(this.getString(R.string.pref_proxyautoconfigured), false)) |
| { |
| - screen.removePreference(findPreference(getString(R.string.pref_proxyenabled))); |
| + screen.removePreference(this.findPreference(this.getString(R.string.pref_proxyenabled))); |
| } |
| } |
| - if (getResources().getBoolean(R.bool.def_release)) |
| + if (this.getResources().getBoolean(R.bool.def_release)) |
| { |
| - screen.removePreference(findPreference(getString(R.string.pref_support))); |
| + screen.removePreference(this.findPreference(this.getString(R.string.pref_support))); |
| } |
| else |
| { |
| - Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate)); |
| + final Preference prefUpdate = this.findPreference(this.getString(R.string.pref_checkupdate)); |
| prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() |
| { |
| - public boolean onPreferenceClick(Preference preference) |
| + @Override |
|
Felix Dahlke
2014/04/16 15:24:25
Does that mean we're on Java 6 now?
René Jeschke
2014/04/16 17:51:47
The whole code base (please have a look) is a mixt
|
| + public boolean onPreferenceClick(final Preference preference) |
| { |
| - AdblockPlus application = AdblockPlus.getApplication(); |
| + final AdblockPlus application = AdblockPlus.getApplication(); |
| application.checkUpdates(); |
| return true; |
| } |
| }); |
| - Preference prefConfiguration = findPreference(getString(R.string.pref_configuration)); |
| + final Preference prefConfiguration = this.findPreference(this.getString(R.string.pref_configuration)); |
| prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListener() |
| { |
| - public boolean onPreferenceClick(Preference preference) |
| + @Override |
| + public boolean onPreferenceClick(final Preference preference) |
| { |
| - showDialog(CONFIGURATION_DIALOG); |
| + AdvancedPreferences.this.showDialog(CONFIGURATION_DIALOG); |
| return true; |
| } |
| }); |
| @@ -104,57 +106,61 @@ public class AdvancedPreferences extends SummarizedPreferences |
| public void onResume() |
| { |
| super.onResume(); |
| - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| - int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_refresh), "0")); |
| - findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); |
| - connect(); |
| + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| + final int refresh = Integer.valueOf(prefs.getString(this.getString(R.string.pref_refresh), "0")); |
| + this.findPreference(this.getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); |
| + this.connect(); |
| } |
| @Override |
| public void onPause() |
| { |
| super.onPause(); |
| - disconnect(); |
| + this.disconnect(); |
| } |
| @Override |
| - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) |
| + public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) |
| { |
| - if (getString(R.string.pref_proxyenabled).equals(key)) |
| + if (this.getString(R.string.pref_proxyenabled).equals(key)) |
| { |
| - AdblockPlus application = AdblockPlus.getApplication(); |
| - boolean enabled = sharedPreferences.getBoolean(key, false); |
| - boolean serviceRunning = application.isServiceRunning(); |
| + final AdblockPlus application = AdblockPlus.getApplication(); |
| + final boolean enabled = sharedPreferences.getBoolean(key, false); |
| + final boolean serviceRunning = application.isServiceRunning(); |
| if (enabled) |
| { |
| if (!serviceRunning) |
| - startService(new Intent(this, ProxyService.class)); |
| + { |
| + this.startService(new Intent(this, ProxyService.class)); |
| + } |
| } |
| else |
| { |
| if (serviceRunning) |
| - stopService(new Intent(this, ProxyService.class)); |
| + { |
| + this.stopService(new Intent(this, ProxyService.class)); |
| + } |
| // If disabled, disable filtering as well |
| - SharedPreferences.Editor editor = sharedPreferences.edit(); |
| - editor.putBoolean(getString(R.string.pref_enabled), false); |
| + final SharedPreferences.Editor editor = sharedPreferences.edit(); |
| + editor.putBoolean(this.getString(R.string.pref_enabled), false); |
| editor.commit(); |
| application.setFilteringEnabled(false); |
| } |
| } |
| - if (getString(R.string.pref_refresh).equals(key)) |
| + if (this.getString(R.string.pref_refresh).equals(key)) |
| { |
| - int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")); |
| - findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); |
| + final int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")); |
| + this.findPreference(this.getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); |
| } |
| - if (getString(R.string.pref_crashreport).equals(key)) |
| + if (this.getString(R.string.pref_crashreport).equals(key)) |
| { |
| - boolean report = sharedPreferences.getBoolean(key, getResources().getBoolean(R.bool.def_crashreport)); |
| + final boolean report = sharedPreferences.getBoolean(key, this.getResources().getBoolean(R.bool.def_crashreport)); |
| try |
| { |
| - CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtExceptionHandler(); |
| + final CrashHandler handler = (CrashHandler)Thread.getDefaultUncaughtExceptionHandler(); |
| handler.generateReport(report); |
| } |
| - catch (ClassCastException e) |
| + catch (final ClassCastException e) |
| { |
| // ignore - default handler in use |
| } |
| @@ -163,39 +169,41 @@ public class AdvancedPreferences extends SummarizedPreferences |
| } |
| @Override |
| - protected Dialog onCreateDialog(int id) |
| + protected Dialog onCreateDialog(final int id) |
| { |
| Dialog dialog = null; |
| switch (id) |
| { |
| case CONFIGURATION_DIALOG: |
| - List<String> items = new ArrayList<String>(); |
| + final List<String> items = new ArrayList<String>(); |
| items.add(AdblockPlus.getDeviceName()); |
| items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, AdblockPlus.getApplication().getBuildNumber())); |
| - if (proxyService != null) |
| + if (this.proxyService != null) |
| { |
| - items.add(String.format("Local port: %d", proxyService.port)); |
| - if (proxyService.isTransparent()) |
| + items.add(String.format("Local port: %d", this.proxyService.port)); |
| + if (this.proxyService.isTransparent()) |
| { |
| items.add("Running in root mode"); |
| items.add("iptables output:"); |
| - List<String> output = proxyService.getIptablesOutput(); |
| + final List<String> output = this.proxyService.getIptablesOutput(); |
| if (output != null) |
| { |
| - for (String line : output) |
| + for (final String line : output) |
| { |
| if (!"".equals(line)) |
| + { |
| items.add(line); |
| + } |
| } |
| } |
| } |
| - if (proxyService.isNativeProxyAutoConfigured()) |
| + if (this.proxyService.isNativeProxyAutoConfigured()) |
| { |
| items.add("Has native proxy auto configured"); |
| } |
| if (ProxyService.NATIVE_PROXY_SUPPORTED) |
| { |
| - String[] px = ProxySettings.getUserProxy(getApplicationContext()); |
| + final String[] px = ProxySettings.getUserProxy(this.getApplicationContext()); |
| if (px != null) |
| { |
| items.add("System settings:"); |
| @@ -203,39 +211,42 @@ public class AdvancedPreferences extends SummarizedPreferences |
| } |
| } |
| items.add("Proxy settings:"); |
| - items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyService.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getProperty("adblock.proxyPort"), |
| - proxyService.proxy.props.getProperty("adblock.proxyExcl"))); |
| - if (proxyService.proxy.props.getProperty("adblock.auth") != null) |
| + items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", this.proxyService.proxy.props.getProperty("adblock.proxyHost"), |
| + this.proxyService.proxy.props.getProperty("adblock.proxyPort"), |
| + this.proxyService.proxy.props.getProperty("adblock.proxyExcl"))); |
| + if (this.proxyService.proxy.props.getProperty("adblock.auth") != null) |
| + { |
| items.add("Auth: yes"); |
| + } |
| } |
| else |
| { |
| items.add("Service not running"); |
| } |
| - ScrollView scrollPane = new ScrollView(this); |
| - TextView messageText = new TextView(this); |
| + final ScrollView scrollPane = new ScrollView(this); |
| + final TextView messageText = new TextView(this); |
| messageText.setPadding(12, 6, 12, 6); |
| messageText.setText(TextUtils.join("\n", items)); |
| messageText.setOnClickListener(new View.OnClickListener() |
| { |
| - |
| @Override |
| - public void onClick(View v) |
| + public void onClick(final View v) |
| { |
| - ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); |
| - TextView showTextParam = (TextView) v; |
| + final ClipboardManager manager = (ClipboardManager)AdvancedPreferences.this.getSystemService(CLIPBOARD_SERVICE); |
| + final TextView showTextParam = (TextView)v; |
| manager.setText(showTextParam.getText()); |
| Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_SHORT).show(); |
| } |
| }); |
| scrollPane.addView(messageText); |
| - AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| + final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| builder.setView(scrollPane).setTitle(R.string.configuration_name).setIcon(android.R.drawable.ic_dialog_info).setCancelable(false) |
| .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() |
| { |
| - public void onClick(DialogInterface dialog, int id) |
| + @Override |
| + public void onClick(final DialogInterface dialog, final int id) |
| { |
| dialog.cancel(); |
| } |
| @@ -248,26 +259,28 @@ public class AdvancedPreferences extends SummarizedPreferences |
| private void connect() |
| { |
| - bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0); |
| + this.bindService(new Intent(this, ProxyService.class), this.proxyServiceConnection, 0); |
| } |
| private void disconnect() |
| { |
| - unbindService(proxyServiceConnection); |
| - proxyService = null; |
| + this.unbindService(this.proxyServiceConnection); |
| + this.proxyService = null; |
| } |
| - private ServiceConnection proxyServiceConnection = new ServiceConnection() |
| + private final ServiceConnection proxyServiceConnection = new ServiceConnection() |
| { |
| - public void onServiceConnected(ComponentName className, IBinder service) |
| + @Override |
| + public void onServiceConnected(final ComponentName className, final IBinder service) |
| { |
| - proxyService = ((ProxyService.LocalBinder) service).getService(); |
| + AdvancedPreferences.this.proxyService = ((ProxyService.LocalBinder)service).getService(); |
| Log.d(TAG, "Proxy service connected"); |
| } |
| - public void onServiceDisconnected(ComponentName className) |
| + @Override |
| + public void onServiceDisconnected(final ComponentName className) |
| { |
| - proxyService = null; |
| + AdvancedPreferences.this.proxyService = null; |
| Log.d(TAG, "Proxy service disconnected"); |
| } |
| }; |