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

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

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Removed newly added neetutils code Created April 25, 2014, 9:31 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 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
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")
Felix Dahlke 2014/04/28 07:29:01 I don't think we should ignore this, in general pr
René Jeschke 2014/04/28 08:34:32 Those deprecation warnings can only be resolved by
Felix Dahlke 2014/04/28 10:09:41 It may make sense then, however, I think it belong
René Jeschke 2014/04/28 10:18:34 Done.
48 public class AdvancedPreferences extends SummarizedPreferences 49 public class AdvancedPreferences extends SummarizedPreferences
49 { 50 {
50 private static final String TAG = "AdvancedPreferences"; 51 private static final String TAG = Utils.getTag(AdvancedPreferences.class);
51
52 private static final int CONFIGURATION_DIALOG = 1; 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(Bundle savedInstanceState) 57 public void onCreate(final Bundle savedInstanceState)
58 { 58 {
59 super.onCreate(savedInstanceState); 59 super.onCreate(savedInstanceState);
60 60
61 addPreferencesFromResource(R.xml.preferences_advanced); 61 addPreferencesFromResource(R.xml.preferences_advanced);
62 62
63 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); 63 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this);
64 64
65 PreferenceScreen screen = getPreferenceScreen(); 65 final PreferenceScreen screen = getPreferenceScreen();
66 if (ProxyService.NATIVE_PROXY_SUPPORTED) 66 if (ProxyService.NATIVE_PROXY_SUPPORTED)
67 { 67 {
68 screen.removePreference(findPreference(getString(R.string.pref_proxy))); 68 screen.removePreference(findPreference(getString(R.string.pref_proxy)));
69 if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) 69 if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false))
70 { 70 {
71 screen.removePreference(findPreference(getString(R.string.pref_proxyenab led))); 71 screen.removePreference(findPreference(getString(R.string.pref_proxyenab led)));
72 } 72 }
73 } 73 }
74 if (getResources().getBoolean(R.bool.def_release)) 74 if (getResources().getBoolean(R.bool.def_release))
75 { 75 {
76 screen.removePreference(findPreference(getString(R.string.pref_support))); 76 screen.removePreference(findPreference(getString(R.string.pref_support)));
77 } 77 }
78 else 78 else
79 { 79 {
80 Preference prefUpdate = findPreference(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 public boolean onPreferenceClick(Preference preference) 83 @Override
84 public boolean onPreferenceClick(final Preference preference)
84 { 85 {
85 AdblockPlus application = AdblockPlus.getApplication(); 86 final AdblockPlus application = AdblockPlus.getApplication();
86 application.checkUpdates(); 87 application.checkUpdates();
87 return true; 88 return true;
88 } 89 }
89 }); 90 });
90 91
91 Preference prefConfiguration = findPreference(getString(R.string.pref_conf iguration)); 92 final Preference prefConfiguration = findPreference(getString(R.string.pre f_configuration));
92 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er() 93 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er()
93 { 94 {
94 public boolean onPreferenceClick(Preference preference) 95 @Override
96 public boolean onPreferenceClick(final Preference preference)
95 { 97 {
96 showDialog(CONFIGURATION_DIALOG); 98 showDialog(CONFIGURATION_DIALOG);
97 return true; 99 return true;
98 } 100 }
99 }); 101 });
100 } 102 }
101 } 103 }
102 104
103 @Override 105 @Override
104 public void onResume() 106 public void onResume()
105 { 107 {
106 super.onResume(); 108 super.onResume();
107 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); 109 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this);
108 int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_refres h), "0")); 110 final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_ refresh), "0"));
109 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ; 111 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ;
110 connect(); 112 connect();
111 } 113 }
112 114
113 @Override 115 @Override
114 public void onPause() 116 public void onPause()
115 { 117 {
116 super.onPause(); 118 super.onPause();
117 disconnect(); 119 disconnect();
118 } 120 }
119 121
120 @Override 122 @Override
121 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key) 123 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference s, final String key)
122 { 124 {
123 if (getString(R.string.pref_proxyenabled).equals(key)) 125 if (getString(R.string.pref_proxyenabled).equals(key))
124 { 126 {
125 AdblockPlus application = AdblockPlus.getApplication(); 127 final AdblockPlus application = AdblockPlus.getApplication();
126 boolean enabled = sharedPreferences.getBoolean(key, false); 128 final boolean enabled = sharedPreferences.getBoolean(key, false);
127 boolean serviceRunning = application.isServiceRunning(); 129 final boolean serviceRunning = application.isServiceRunning();
128 if (enabled) 130 if (enabled)
129 { 131 {
130 if (!serviceRunning) 132 if (!serviceRunning)
131 startService(new Intent(this, ProxyService.class)); 133 startService(new Intent(this, ProxyService.class));
132 } 134 }
133 else 135 else
134 { 136 {
135 if (serviceRunning) 137 if (serviceRunning)
136 stopService(new Intent(this, ProxyService.class)); 138 stopService(new Intent(this, ProxyService.class));
137 // If disabled, disable filtering as well 139 // If disabled, disable filtering as well
138 SharedPreferences.Editor editor = sharedPreferences.edit(); 140 final SharedPreferences.Editor editor = sharedPreferences.edit();
139 editor.putBoolean(getString(R.string.pref_enabled), false); 141 editor.putBoolean(getString(R.string.pref_enabled), false);
140 editor.commit(); 142 editor.commit();
141 application.setFilteringEnabled(false); 143 application.setFilteringEnabled(false);
142 } 144 }
143 } 145 }
144 if (getString(R.string.pref_refresh).equals(key)) 146 if (getString(R.string.pref_refresh).equals(key))
145 { 147 {
146 int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")); 148 final int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")) ;
147 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0); 149 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0);
148 } 150 }
149 if (getString(R.string.pref_crashreport).equals(key)) 151 if (getString(R.string.pref_crashreport).equals(key))
150 { 152 {
151 boolean report = sharedPreferences.getBoolean(key, getResources().getBoole an(R.bool.def_crashreport)); 153 final boolean report = sharedPreferences.getBoolean(key, getResources().ge tBoolean(R.bool.def_crashreport));
152 try 154 try
153 { 155 {
154 CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtException Handler(); 156 final CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtExc eptionHandler();
155 handler.generateReport(report); 157 handler.generateReport(report);
156 } 158 }
157 catch (ClassCastException e) 159 catch (final ClassCastException e)
158 { 160 {
159 // ignore - default handler in use 161 // ignore - default handler in use
160 } 162 }
161 } 163 }
162 super.onSharedPreferenceChanged(sharedPreferences, key); 164 super.onSharedPreferenceChanged(sharedPreferences, key);
163 } 165 }
164 166
165 @Override 167 @Override
166 protected Dialog onCreateDialog(int id) 168 protected Dialog onCreateDialog(final int id)
167 { 169 {
168 Dialog dialog = null; 170 Dialog dialog = null;
169 switch (id) 171 switch (id)
170 { 172 {
171 case CONFIGURATION_DIALOG: 173 case CONFIGURATION_DIALOG:
172 List<String> items = new ArrayList<String>(); 174 final List<String> items = new ArrayList<String>();
173 items.add(AdblockPlus.getDeviceName()); 175 items.add(AdblockPlus.getDeviceName());
174 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()));
175 if (proxyService != null) 177 if (proxyService != null)
176 { 178 {
177 items.add(String.format("Local port: %d", proxyService.port)); 179 items.add(String.format("Local port: %d", proxyService.port));
178 if (proxyService.isTransparent()) 180 if (proxyService.isTransparent())
179 { 181 {
180 items.add("Running in root mode"); 182 items.add("Running in root mode");
181 items.add("iptables output:"); 183 items.add("iptables output:");
182 List<String> output = proxyService.getIptablesOutput(); 184 final List<String> output = proxyService.getIptablesOutput();
183 if (output != null) 185 if (output != null)
184 { 186 {
185 for (String line : output) 187 for (final String line : output)
186 { 188 {
187 if (!"".equals(line)) 189 if (!"".equals(line))
188 items.add(line); 190 items.add(line);
189 } 191 }
190 } 192 }
191 } 193 }
192 if (proxyService.isNativeProxyAutoConfigured()) 194 if (proxyService.isNativeProxyAutoConfigured())
193 { 195 {
194 items.add("Has native proxy auto configured"); 196 items.add("Has native proxy auto configured");
195 } 197 }
196 if (ProxyService.NATIVE_PROXY_SUPPORTED) 198 if (ProxyService.NATIVE_PROXY_SUPPORTED)
197 { 199 {
198 String[] px = ProxySettings.getUserProxy(getApplicationContext()); 200 final String[] px = ProxySettings.getUserProxy(getApplicationContext ());
199 if (px != null) 201 if (px != null)
200 { 202 {
201 items.add("System settings:"); 203 items.add("System settings:");
202 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]));
203 } 205 }
204 } 206 }
205 items.add("Proxy settings:"); 207 items.add("Proxy settings:");
206 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"), 208 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"),
Felix Dahlke 2014/04/28 07:29:01 Seems like this adds a lot of trailing whitespace,
René Jeschke 2014/04/28 08:34:32 Nope, just the diff view gone mad.
209 proxyService.proxy.props.getProperty("adblock.proxyPort"),
207 proxyService.proxy.props.getProperty("adblock.proxyExcl"))); 210 proxyService.proxy.props.getProperty("adblock.proxyExcl")));
208 if (proxyService.proxy.props.getProperty("adblock.auth") != null) 211 if (proxyService.proxy.props.getProperty("adblock.auth") != null)
209 items.add("Auth: yes"); 212 items.add("Auth: yes");
210 } 213 }
211 else 214 else
212 { 215 {
213 items.add("Service not running"); 216 items.add("Service not running");
214 } 217 }
215 218
216 ScrollView scrollPane = new ScrollView(this); 219 final ScrollView scrollPane = new ScrollView(this);
217 TextView messageText = new TextView(this); 220 final TextView messageText = new TextView(this);
218 messageText.setPadding(12, 6, 12, 6); 221 messageText.setPadding(12, 6, 12, 6);
219 messageText.setText(TextUtils.join("\n", items)); 222 messageText.setText(TextUtils.join("\n", items));
220 messageText.setOnClickListener(new View.OnClickListener() 223 messageText.setOnClickListener(new View.OnClickListener()
221 { 224 {
222
223 @Override 225 @Override
224 public void onClick(View v) 226 public void onClick(final View v)
225 { 227 {
226 ClipboardManager manager = (ClipboardManager) getSystemService(CLIPB OARD_SERVICE); 228 final ClipboardManager manager = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE);
227 TextView showTextParam = (TextView) v; 229 final TextView showTextParam = (TextView) v;
228 manager.setText(showTextParam.getText()); 230 manager.setText(showTextParam.getText());
229 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();
230 } 232 }
231 }); 233 });
232 scrollPane.addView(messageText); 234 scrollPane.addView(messageText);
233 235
234 AlertDialog.Builder builder = new AlertDialog.Builder(this); 236 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
235 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)
236 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) 238 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( )
237 { 239 {
238 public void onClick(DialogInterface dialog, int id) 240 @Override
Felix Dahlke 2014/04/28 07:29:01 I remarked about this before, but IIRC, the situat
René Jeschke 2014/04/28 08:34:32 The whole Adblock Plus Android gets checked/compil
Felix Dahlke 2014/04/28 10:09:41 Alright, thought it was Java 5 for some reason.
René Jeschke 2014/04/28 10:18:34 Done.
241 public void onClick(final DialogInterface dialog, final int id)
239 { 242 {
240 dialog.cancel(); 243 dialog.cancel();
241 } 244 }
242 }); 245 });
243 dialog = builder.create(); 246 dialog = builder.create();
244 break; 247 break;
245 } 248 }
246 return dialog; 249 return dialog;
247 } 250 }
248 251
249 private void connect() 252 private void connect()
250 { 253 {
251 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ; 254 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ;
252 } 255 }
253 256
254 private void disconnect() 257 private void disconnect()
255 { 258 {
256 unbindService(proxyServiceConnection); 259 unbindService(proxyServiceConnection);
257 proxyService = null; 260 proxyService = null;
258 } 261 }
259 262
260 private ServiceConnection proxyServiceConnection = new ServiceConnection() 263 private final ServiceConnection proxyServiceConnection = new ServiceConnection ()
261 { 264 {
262 public void onServiceConnected(ComponentName className, IBinder service) 265 @Override
266 public void onServiceConnected(final ComponentName className, final IBinder service)
263 { 267 {
264 proxyService = ((ProxyService.LocalBinder) service).getService(); 268 proxyService = ((ProxyService.LocalBinder) service).getService();
265 Log.d(TAG, "Proxy service connected"); 269 Log.d(TAG, "Proxy service connected");
266 } 270 }
267 271
268 public void onServiceDisconnected(ComponentName className) 272 @Override
273 public void onServiceDisconnected(final ComponentName className)
269 { 274 {
270 proxyService = null; 275 proxyService = null;
271 Log.d(TAG, "Proxy service disconnected"); 276 Log.d(TAG, "Proxy service disconnected");
272 } 277 }
273 }; 278 };
274 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld