Left: | ||
Right: |
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 27 matching lines...) Expand all Loading... | |
38 import android.text.TextUtils; | 38 import android.text.TextUtils; |
39 import android.util.Log; | 39 import android.util.Log; |
40 import android.view.View; | 40 import android.view.View; |
41 import android.widget.ScrollView; | 41 import android.widget.ScrollView; |
42 import android.widget.TextView; | 42 import android.widget.TextView; |
43 import android.widget.Toast; | 43 import android.widget.Toast; |
44 | 44 |
45 /** | 45 /** |
46 * Advanced settings UI. | 46 * Advanced settings UI. |
47 */ | 47 */ |
48 @SuppressWarnings("deprecation") | |
49 public class AdvancedPreferences extends SummarizedPreferences | 48 public class AdvancedPreferences extends SummarizedPreferences |
50 { | 49 { |
51 private final static String TAG = Utils.getTag(AdvancedPreferences.class); | 50 private static final String TAG = Utils.getTag(AdvancedPreferences.class); |
52 private final static int CONFIGURATION_DIALOG = 1; | 51 |
52 private static final int CONFIGURATION_DIALOG = 1; | |
53 | 53 |
54 private ProxyService proxyService = null; | 54 private ProxyService proxyService = null; |
55 | 55 |
56 @Override | 56 @Override |
57 public void onCreate(final Bundle savedInstanceState) | 57 public void onCreate(final Bundle savedInstanceState) |
58 { | 58 { |
59 super.onCreate(savedInstanceState); | 59 super.onCreate(savedInstanceState); |
60 | 60 |
61 this.addPreferencesFromResource(R.xml.preferences_advanced); | 61 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.
| |
62 | 62 |
63 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); | 63 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); |
64 | 64 |
65 final PreferenceScreen screen = this.getPreferenceScreen(); | 65 final PreferenceScreen screen = getPreferenceScreen(); |
66 if (ProxyService.NATIVE_PROXY_SUPPORTED) | 66 if (ProxyService.NATIVE_PROXY_SUPPORTED) |
67 { | 67 { |
68 screen.removePreference(this.findPreference(this.getString(R.string.pref_p roxy))); | 68 screen.removePreference(findPreference(getString(R.string.pref_proxy))); |
69 if (prefs.getBoolean(this.getString(R.string.pref_proxyautoconfigured), fa lse)) | 69 if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) |
70 { | 70 { |
71 screen.removePreference(this.findPreference(this.getString(R.string.pref _proxyenabled))); | 71 screen.removePreference(findPreference(getString(R.string.pref_proxyenab led))); |
72 } | 72 } |
73 } | 73 } |
74 if (this.getResources().getBoolean(R.bool.def_release)) | 74 if (getResources().getBoolean(R.bool.def_release)) |
75 { | 75 { |
76 screen.removePreference(this.findPreference(this.getString(R.string.pref_s upport))); | 76 screen.removePreference(findPreference(getString(R.string.pref_support))); |
77 } | 77 } |
78 else | 78 else |
79 { | 79 { |
80 final Preference prefUpdate = this.findPreference(this.getString(R.string. pref_checkupdate)); | 80 final Preference prefUpdate = findPreference(getString(R.string.pref_check update)); |
81 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() | 81 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() |
82 { | 82 { |
83 @Override | 83 @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
| |
84 public boolean onPreferenceClick(final Preference preference) | 84 public boolean onPreferenceClick(final Preference preference) |
85 { | 85 { |
86 final AdblockPlus application = AdblockPlus.getApplication(); | 86 final AdblockPlus application = AdblockPlus.getApplication(); |
87 application.checkUpdates(); | 87 application.checkUpdates(); |
88 return true; | 88 return true; |
89 } | 89 } |
90 }); | 90 }); |
91 | 91 |
92 final Preference prefConfiguration = this.findPreference(this.getString(R. string.pref_configuration)); | 92 final Preference prefConfiguration = findPreference(getString(R.string.pre f_configuration)); |
93 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er() | 93 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er() |
94 { | 94 { |
95 @Override | 95 @Override |
96 public boolean onPreferenceClick(final Preference preference) | 96 public boolean onPreferenceClick(final Preference preference) |
97 { | 97 { |
98 AdvancedPreferences.this.showDialog(CONFIGURATION_DIALOG); | 98 showDialog(CONFIGURATION_DIALOG); |
99 return true; | 99 return true; |
100 } | 100 } |
101 }); | 101 }); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 @Override | 105 @Override |
106 public void onResume() | 106 public void onResume() |
107 { | 107 { |
108 super.onResume(); | 108 super.onResume(); |
109 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); | 109 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); |
110 final int refresh = Integer.valueOf(prefs.getString(this.getString(R.string. pref_refresh), "0")); | 110 final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_ refresh), "0")); |
111 this.findPreference(this.getString(R.string.pref_wifirefresh)).setEnabled(re fresh > 0); | 111 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ; |
112 this.connect(); | 112 connect(); |
113 } | 113 } |
114 | 114 |
115 @Override | 115 @Override |
116 public void onPause() | 116 public void onPause() |
117 { | 117 { |
118 super.onPause(); | 118 super.onPause(); |
119 this.disconnect(); | 119 disconnect(); |
120 } | 120 } |
121 | 121 |
122 @Override | 122 @Override |
123 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference s, final String key) | 123 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference s, final String key) |
124 { | 124 { |
125 if (this.getString(R.string.pref_proxyenabled).equals(key)) | 125 if (getString(R.string.pref_proxyenabled).equals(key)) |
126 { | 126 { |
127 final AdblockPlus application = AdblockPlus.getApplication(); | 127 final AdblockPlus application = AdblockPlus.getApplication(); |
128 final boolean enabled = sharedPreferences.getBoolean(key, false); | 128 final boolean enabled = sharedPreferences.getBoolean(key, false); |
129 final boolean serviceRunning = application.isServiceRunning(); | 129 final boolean serviceRunning = application.isServiceRunning(); |
130 if (enabled) | 130 if (enabled) |
131 { | 131 { |
132 if (!serviceRunning) | 132 if (!serviceRunning) |
133 { | 133 startService(new Intent(this, ProxyService.class)); |
134 this.startService(new Intent(this, ProxyService.class)); | |
135 } | |
136 } | 134 } |
137 else | 135 else |
138 { | 136 { |
139 if (serviceRunning) | 137 if (serviceRunning) |
140 { | 138 stopService(new Intent(this, ProxyService.class)); |
141 this.stopService(new Intent(this, ProxyService.class)); | |
142 } | |
143 // If disabled, disable filtering as well | 139 // If disabled, disable filtering as well |
144 final SharedPreferences.Editor editor = sharedPreferences.edit(); | 140 final SharedPreferences.Editor editor = sharedPreferences.edit(); |
145 editor.putBoolean(this.getString(R.string.pref_enabled), false); | 141 editor.putBoolean(getString(R.string.pref_enabled), false); |
146 editor.commit(); | 142 editor.commit(); |
147 application.setFilteringEnabled(false); | 143 application.setFilteringEnabled(false); |
148 } | 144 } |
149 } | 145 } |
150 if (this.getString(R.string.pref_refresh).equals(key)) | 146 if (getString(R.string.pref_refresh).equals(key)) |
151 { | 147 { |
152 final int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")) ; | 148 final int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")) ; |
153 this.findPreference(this.getString(R.string.pref_wifirefresh)).setEnabled( refresh > 0); | 149 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); |
154 } | 150 } |
155 if (this.getString(R.string.pref_crashreport).equals(key)) | 151 if (getString(R.string.pref_crashreport).equals(key)) |
156 { | 152 { |
157 final boolean report = sharedPreferences.getBoolean(key, this.getResources ().getBoolean(R.bool.def_crashreport)); | 153 final boolean report = sharedPreferences.getBoolean(key, getResources().ge tBoolean(R.bool.def_crashreport)); |
158 try | 154 try |
159 { | 155 { |
160 final CrashHandler handler = (CrashHandler)Thread.getDefaultUncaughtExce ptionHandler(); | 156 final CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtExc eptionHandler(); |
161 handler.generateReport(report); | 157 handler.generateReport(report); |
162 } | 158 } |
163 catch (final ClassCastException e) | 159 catch (final ClassCastException e) |
164 { | 160 { |
165 // ignore - default handler in use | 161 // ignore - default handler in use |
166 } | 162 } |
167 } | 163 } |
168 super.onSharedPreferenceChanged(sharedPreferences, key); | 164 super.onSharedPreferenceChanged(sharedPreferences, key); |
169 } | 165 } |
170 | 166 |
171 @Override | 167 @Override |
172 protected Dialog onCreateDialog(final int id) | 168 protected Dialog onCreateDialog(final int id) |
173 { | 169 { |
174 Dialog dialog = null; | 170 Dialog dialog = null; |
175 switch (id) | 171 switch (id) |
176 { | 172 { |
177 case CONFIGURATION_DIALOG: | 173 case CONFIGURATION_DIALOG: |
178 final List<String> items = new ArrayList<String>(); | 174 final List<String> items = new ArrayList<String>(); |
179 items.add(AdblockPlus.getDeviceName()); | 175 items.add(AdblockPlus.getDeviceName()); |
180 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl ockPlus.getApplication().getBuildNumber())); | 176 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl ockPlus.getApplication().getBuildNumber())); |
181 if (this.proxyService != null) | 177 if (proxyService != null) |
182 { | 178 { |
183 items.add(String.format("Local port: %d", this.proxyService.port)); | 179 items.add(String.format("Local port: %d", proxyService.port)); |
184 if (this.proxyService.isTransparent()) | 180 if (proxyService.isTransparent()) |
185 { | 181 { |
186 items.add("Running in root mode"); | 182 items.add("Running in root mode"); |
187 items.add("iptables output:"); | 183 items.add("iptables output:"); |
188 final List<String> output = this.proxyService.getIptablesOutput(); | 184 final List<String> output = proxyService.getIptablesOutput(); |
189 if (output != null) | 185 if (output != null) |
190 { | 186 { |
191 for (final String line : output) | 187 for (final String line : output) |
192 { | 188 { |
193 if (!"".equals(line)) | 189 if (!"".equals(line)) |
194 { | |
195 items.add(line); | 190 items.add(line); |
196 } | |
197 } | 191 } |
198 } | 192 } |
199 } | 193 } |
200 if (this.proxyService.isNativeProxyAutoConfigured()) | 194 if (proxyService.isNativeProxyAutoConfigured()) |
201 { | 195 { |
202 items.add("Has native proxy auto configured"); | 196 items.add("Has native proxy auto configured"); |
203 } | 197 } |
204 if (ProxyService.NATIVE_PROXY_SUPPORTED) | 198 if (ProxyService.NATIVE_PROXY_SUPPORTED) |
205 { | 199 { |
206 final String[] px = ProxySettings.getUserProxy(this.getApplicationCo ntext()); | 200 final String[] px = ProxySettings.getUserProxy(getApplicationContext ()); |
207 if (px != null) | 201 if (px != null) |
208 { | 202 { |
209 items.add("System settings:"); | 203 items.add("System settings:"); |
210 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2])); | 204 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2])); |
211 } | 205 } |
212 } | 206 } |
213 items.add("Proxy settings:"); | 207 items.add("Proxy settings:"); |
214 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", this.proxy Service.proxy.props.getProperty("adblock.proxyHost"), | 208 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"), |
215 this.proxyService.proxy.props.getProperty("adblock.proxyPort"), | 209 proxyService.proxy.props.getProperty("adblock.proxyExcl"))); |
216 this.proxyService.proxy.props.getProperty("adblock.proxyExcl"))); | 210 if (proxyService.proxy.props.getProperty("adblock.auth") != null) |
217 if (this.proxyService.proxy.props.getProperty("adblock.auth") != null) | |
218 { | |
219 items.add("Auth: yes"); | 211 items.add("Auth: yes"); |
220 } | |
221 } | 212 } |
222 else | 213 else |
223 { | 214 { |
224 items.add("Service not running"); | 215 items.add("Service not running"); |
225 } | 216 } |
226 | 217 |
227 final ScrollView scrollPane = new ScrollView(this); | 218 final ScrollView scrollPane = new ScrollView(this); |
228 final TextView messageText = new TextView(this); | 219 final TextView messageText = new TextView(this); |
229 messageText.setPadding(12, 6, 12, 6); | 220 messageText.setPadding(12, 6, 12, 6); |
230 messageText.setText(TextUtils.join("\n", items)); | 221 messageText.setText(TextUtils.join("\n", items)); |
231 messageText.setOnClickListener(new View.OnClickListener() | 222 messageText.setOnClickListener(new View.OnClickListener() |
232 { | 223 { |
224 | |
233 @Override | 225 @Override |
234 public void onClick(final View v) | 226 public void onClick(final View v) |
235 { | 227 { |
236 final ClipboardManager manager = (ClipboardManager)AdvancedPreferenc es.this.getSystemService(CLIPBOARD_SERVICE); | 228 final ClipboardManager manager = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE); |
237 final TextView showTextParam = (TextView)v; | 229 final TextView showTextParam = (TextView) v; |
238 manager.setText(showTextParam.getText()); | 230 manager.setText(showTextParam.getText()); |
239 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); | 231 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); |
240 } | 232 } |
241 }); | 233 }); |
242 scrollPane.addView(messageText); | 234 scrollPane.addView(messageText); |
243 | 235 |
244 final AlertDialog.Builder builder = new AlertDialog.Builder(this); | 236 final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
245 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false) | 237 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false) |
246 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) | 238 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) |
247 { | 239 { |
248 @Override | 240 @Override |
249 public void onClick(final DialogInterface dialog, final int id) | 241 public void onClick(final DialogInterface dialog, final int id) |
250 { | 242 { |
251 dialog.cancel(); | 243 dialog.cancel(); |
252 } | 244 } |
253 }); | 245 }); |
254 dialog = builder.create(); | 246 dialog = builder.create(); |
255 break; | 247 break; |
256 } | 248 } |
257 return dialog; | 249 return dialog; |
258 } | 250 } |
259 | 251 |
260 private void connect() | 252 private void connect() |
261 { | 253 { |
262 this.bindService(new Intent(this, ProxyService.class), this.proxyServiceConn ection, 0); | 254 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ; |
263 } | 255 } |
264 | 256 |
265 private void disconnect() | 257 private void disconnect() |
266 { | 258 { |
267 this.unbindService(this.proxyServiceConnection); | 259 unbindService(proxyServiceConnection); |
268 this.proxyService = null; | 260 proxyService = null; |
269 } | 261 } |
270 | 262 |
271 private final ServiceConnection proxyServiceConnection = new ServiceConnection () | 263 private final ServiceConnection proxyServiceConnection = new ServiceConnection () |
272 { | 264 { |
273 @Override | 265 @Override |
274 public void onServiceConnected(final ComponentName className, final IBinder service) | 266 public void onServiceConnected(final ComponentName className, final IBinder service) |
275 { | 267 { |
276 AdvancedPreferences.this.proxyService = ((ProxyService.LocalBinder)service ).getService(); | 268 proxyService = ((ProxyService.LocalBinder) service).getService(); |
277 Log.d(TAG, "Proxy service connected"); | 269 Log.d(TAG, "Proxy service connected"); |
278 } | 270 } |
279 | 271 |
280 @Override | 272 @Override |
281 public void onServiceDisconnected(final ComponentName className) | 273 public void onServiceDisconnected(final ComponentName className) |
282 { | 274 { |
283 AdvancedPreferences.this.proxyService = null; | 275 proxyService = null; |
284 Log.d(TAG, "Proxy service disconnected"); | 276 Log.d(TAG, "Proxy service disconnected"); |
285 } | 277 } |
286 }; | 278 }; |
287 } | 279 } |
LEFT | RIGHT |