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

Delta Between Two Patch Sets: src/org/adblockplus/android/AdvancedPreferences.java

Issue 8493083: ABP/Android UI (Closed)
Left Patch Set: Created Oct. 5, 2012, 9:42 a.m.
Right Patch Set: ABP/Android UI Created Oct. 12, 2012, 1:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/android/AboutDialog.java ('k') | src/org/adblockplus/android/BootBroadcastReceiver.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package org.adblockplus.android; 1 package org.adblockplus.android;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 5
6 import org.adblockplus.android.updater.AlarmReceiver; 6 import org.adblockplus.android.updater.AlarmReceiver;
7 7
8 import android.app.AlertDialog; 8 import android.app.AlertDialog;
9 import android.app.Dialog; 9 import android.app.Dialog;
10 import android.content.ComponentName; 10 import android.content.ComponentName;
11 import android.content.DialogInterface; 11 import android.content.DialogInterface;
12 import android.content.Intent; 12 import android.content.Intent;
13 import android.content.ServiceConnection; 13 import android.content.ServiceConnection;
14 import android.content.SharedPreferences; 14 import android.content.SharedPreferences;
15 import android.content.pm.PackageInfo; 15 import android.content.pm.PackageInfo;
16 import android.content.pm.PackageManager.NameNotFoundException; 16 import android.content.pm.PackageManager.NameNotFoundException;
17 import android.os.Build; 17 import android.os.Build;
18 import android.os.Bundle; 18 import android.os.Bundle;
19 import android.os.IBinder; 19 import android.os.IBinder;
20 import android.preference.Preference; 20 import android.preference.Preference;
21 import android.preference.Preference.OnPreferenceClickListener;
21 import android.preference.PreferenceManager; 22 import android.preference.PreferenceManager;
22 import android.preference.PreferenceScreen; 23 import android.preference.PreferenceScreen;
23 import android.preference.Preference.OnPreferenceClickListener;
24 import android.text.ClipboardManager; 24 import android.text.ClipboardManager;
25 import android.text.TextUtils; 25 import android.text.TextUtils;
26 import android.util.Log; 26 import android.util.Log;
27 import android.view.View; 27 import android.view.View;
28 import android.widget.ScrollView;
28 import android.widget.TextView; 29 import android.widget.TextView;
29 import android.widget.Toast; 30 import android.widget.Toast;
30 31
31 /** 32 /**
32 * Advanced settings UI. 33 * Advanced settings UI.
33 */ 34 */
34 public class AdvancedPreferences extends SummarizedPreferences 35 public class AdvancedPreferences extends SummarizedPreferences
35 { 36 {
36 private final static String TAG = "AdvancedPreferences"; 37 private static final String TAG = "AdvancedPreferences";
Felix Dahlke 2012/10/09 14:27:29 How about "static final" instead of "final static"
Andrey Novikov 2012/10/12 13:19:14 Done.
37 38
38 private static final int CONFIGURATION_DIALOG = 1; 39 private static final int CONFIGURATION_DIALOG = 1;
39 40
40 private static ProxyService proxyService = null; 41 private static ProxyService proxyService = null;
42
43 private boolean hasNativeProxy;
41 44
42 @Override 45 @Override
43 public void onCreate(Bundle savedInstanceState) 46 public void onCreate(Bundle savedInstanceState)
44 { 47 {
45 super.onCreate(savedInstanceState); 48 super.onCreate(savedInstanceState);
49
50 hasNativeProxy = Build.VERSION.SDK_INT >= 12; // Honeycomb 3.1
46 51
47 addPreferencesFromResource(R.xml.preferences_advanced); 52 addPreferencesFromResource(R.xml.preferences_advanced);
48 53
49 PreferenceScreen screen = getPreferenceScreen(); 54 PreferenceScreen screen = getPreferenceScreen();
50 if (Build.VERSION.SDK_INT >= 12) // Honeycomb 3.1 55 if (hasNativeProxy)
51 { 56 {
52 screen.removePreference(findPreference(getString(R.string.pref_proxy))); 57 screen.removePreference(findPreference(getString(R.string.pref_proxy)));
53 } 58 }
54 if (getResources().getBoolean(R.bool.def_release)) 59 if (getResources().getBoolean(R.bool.def_release))
55 { 60 {
56 screen.removePreference(findPreference(getString(R.string.pref_support))); 61 screen.removePreference(findPreference(getString(R.string.pref_support)));
57 } 62 }
58 else 63 else
59 { 64 {
60 Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate )); 65 Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate ));
61 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() { 66 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener()
Felix Dahlke 2012/10/09 14:27:29 How about putting this opening brace on its own li
Andrey Novikov 2012/10/12 13:19:14 Done.
67 {
62 public boolean onPreferenceClick(Preference preference) 68 public boolean onPreferenceClick(Preference preference)
63 { 69 {
64 Intent updater = new Intent(getApplicationContext(), AlarmReceiver.cla ss).putExtra("notifynoupdate", true); 70 Intent updater = new Intent(getApplicationContext(), AlarmReceiver.cla ss).putExtra("notifynoupdate", true);
65 sendBroadcast(updater); 71 sendBroadcast(updater);
66 return true; 72 return true;
67 } 73 }
68 }); 74 });
69 75
70 Preference prefConfiguration = findPreference(getString(R.string.pref_conf iguration)); 76 Preference prefConfiguration = findPreference(getString(R.string.pref_conf iguration));
71 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er() { 77 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er()
Felix Dahlke 2012/10/09 14:27:29 Same as above, brace should be on its own line.
Andrey Novikov 2012/10/12 13:19:14 Done.
78 {
72 public boolean onPreferenceClick(Preference preference) 79 public boolean onPreferenceClick(Preference preference)
73 { 80 {
74 showDialog(CONFIGURATION_DIALOG); 81 showDialog(CONFIGURATION_DIALOG);
75 return true; 82 return true;
76 } 83 }
77 }); 84 });
78 } 85 }
79 } 86 }
80 87
81 @Override 88 @Override
(...skipping 24 matching lines...) Expand all
106 if (getString(R.string.pref_crashreport).equals(key)) 113 if (getString(R.string.pref_crashreport).equals(key))
107 { 114 {
108 AdblockPlus application = AdblockPlus.getApplication(); 115 AdblockPlus application = AdblockPlus.getApplication();
109 application.updateCrashReportStatus(); 116 application.updateCrashReportStatus();
110 } 117 }
111 super.onSharedPreferenceChanged(sharedPreferences, key); 118 super.onSharedPreferenceChanged(sharedPreferences, key);
112 } 119 }
113 120
114 @Override 121 @Override
115 protected Dialog onCreateDialog(int id) 122 protected Dialog onCreateDialog(int id)
116 { 123 {
Felix Dahlke 2012/10/09 14:27:29 You know I don't like long methods, this is one :)
Andrey Novikov 2012/10/12 13:19:14 We worked out a compromise in adding more comments
117 Dialog dialog = null; 124 Dialog dialog = null;
118 switch (id) 125 switch (id)
Felix Dahlke 2012/10/09 14:27:29 Why use a switch case if there's only one case han
Andrey Novikov 2012/10/12 13:19:14 This is a well known Android code pattern, there c
119 { 126 {
120 case CONFIGURATION_DIALOG: 127 case CONFIGURATION_DIALOG:
121 List<String> items = new ArrayList<String>(); 128 List<String> items = new ArrayList<String>();
122 int versionCode = -1; 129 int buildNumber = -1;
123 try 130 try
Felix Dahlke 2012/10/09 14:27:29 The same code for getting the package info is in A
Andrey Novikov 2012/10/12 13:19:14 NameNotFoundException is thrown when a given packa
Felix Dahlke 2012/10/12 13:29:47 That's why I suggested to return a PackageInfo obj
124 { 131 {
125 PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0); 132 PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
126 versionCode = pi.versionCode; 133 buildNumber = pi.versionCode;
127 } 134 }
128 catch (NameNotFoundException e) 135 catch (NameNotFoundException e)
129 { 136 {
130 // ignore - this shouldn't happen 137 // ignore - this shouldn't happen
131 } 138 e.printStackTrace();
132 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, vers ionCode)); 139 }
140 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, buil dNumber));
133 if (proxyService != null) 141 if (proxyService != null)
134 { 142 {
135 items.add(String.format("Local port: %d", proxyService.port)); 143 items.add(String.format("Local port: %d", proxyService.port));
136 if (proxyService.isTransparent()) 144 if (proxyService.isTransparent())
137 { 145 {
138 items.add("Running in root mode"); 146 items.add("Running in root mode");
147 items.add("iptables output:");
148 List<String> output = proxyService.getIptablesOutput();
149 if (output != null)
150 {
151 for (String line : output)
152 {
153 if (!"".equals(line))
154 items.add(line);
155 }
156 }
139 } 157 }
140 if (proxyService.isNativeProxy()) 158 if (proxyService.isNativeProxy())
141 { 159 {
142 items.add("Uses native proxy"); 160 items.add("Uses native proxy");
143 } 161 }
144 if (Build.VERSION.SDK_INT >= 12) // Honeycomb 3.1 162 if (hasNativeProxy)
Felix Dahlke 2012/10/09 14:27:29 I think this should be a constant, since it's also
Andrey Novikov 2012/10/12 13:19:14 Done.
145 { 163 {
146 String[] px = proxyService.getUserProxy(); 164 String[] px = proxyService.getUserProxy();
147 if (px != null) 165 if (px != null)
148 { 166 {
149 items.add("System settings:"); 167 items.add("System settings:");
150 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2])); 168 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2]));
151 } 169 }
152 } 170 }
153 items.add("Proxy settings:"); 171 items.add("Proxy settings:");
154 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"), 172 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"),
155 proxyService.proxy.props.getProperty("adblock.proxyExcl"))); 173 proxyService.proxy.props.getProperty("adblock.proxyExcl")));
156 if (proxyService.proxy.props.getProperty("adblock.auth") != null) 174 if (proxyService.proxy.props.getProperty("adblock.auth") != null)
157 items.add("Auth: yes"); 175 items.add("Auth: yes");
158 } 176 }
159 else 177 else
160 { 178 {
161 items.add("Service not running"); 179 items.add("Service not running");
162 } 180 }
163 181
182 ScrollView scrollPane = new ScrollView(this);
164 TextView messageText = new TextView(this); 183 TextView messageText = new TextView(this);
165 messageText.setPadding(12, 6, 12, 6); 184 messageText.setPadding(12, 6, 12, 6);
166 messageText.setText(TextUtils.join("\n", items)); 185 messageText.setText(TextUtils.join("\n", items));
167 messageText.setOnClickListener(new View.OnClickListener() { 186 messageText.setOnClickListener(new View.OnClickListener()
Felix Dahlke 2012/10/09 14:27:29 Brace on a new line please.
Andrey Novikov 2012/10/12 13:19:14 Done.
187 {
168 188
169 @Override 189 @Override
170 public void onClick(View v) 190 public void onClick(View v)
171 { 191 {
172 ClipboardManager manager = (ClipboardManager) getSystemService(CLIPB OARD_SERVICE); 192 ClipboardManager manager = (ClipboardManager) getSystemService(CLIPB OARD_SERVICE);
173 TextView showTextParam = (TextView) v; 193 TextView showTextParam = (TextView) v;
174 manager.setText(showTextParam.getText()); 194 manager.setText(showTextParam.getText());
175 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); 195 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show();
176 } 196 }
177 }); 197 });
198 scrollPane.addView(messageText);
178 199
179 AlertDialog.Builder builder = new AlertDialog.Builder(this); 200 AlertDialog.Builder builder = new AlertDialog.Builder(this);
180 builder.setView(messageText).setTitle(R.string.configuration_name).setIc on(android.R.drawable.ic_dialog_info).setCancelable(false) 201 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false)
181 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) { 202 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( )
203 {
182 public void onClick(DialogInterface dialog, int id) 204 public void onClick(DialogInterface dialog, int id)
183 { 205 {
184 dialog.cancel(); 206 dialog.cancel();
185 } 207 }
186 }); 208 });
187 dialog = builder.create(); 209 dialog = builder.create();
188 break; 210 break;
189 } 211 }
190 return dialog; 212 return dialog;
191 } 213 }
192 214
193 private void connect() 215 private void connect()
194 { 216 {
195 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ; 217 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ;
196 } 218 }
197 219
198 private void disconnect() 220 private void disconnect()
199 { 221 {
200 unbindService(proxyServiceConnection); 222 unbindService(proxyServiceConnection);
201 proxyService = null; 223 proxyService = null;
202 } 224 }
203 225
204 private ServiceConnection proxyServiceConnection = new ServiceConnection() { 226 private ServiceConnection proxyServiceConnection = new ServiceConnection()
227 {
205 public void onServiceConnected(ComponentName className, IBinder service) 228 public void onServiceConnected(ComponentName className, IBinder service)
206 { 229 {
207 proxyService = ((ProxyService.LocalBinder) service).getService(); 230 proxyService = ((ProxyService.LocalBinder) service).getService();
208 Log.d(TAG, "Proxy service connected"); 231 Log.d(TAG, "Proxy service connected");
209 } 232 }
210 233
211 public void onServiceDisconnected(ComponentName className) 234 public void onServiceDisconnected(ComponentName className)
212 { 235 {
213 proxyService = null; 236 proxyService = null;
214 Log.d(TAG, "Proxy service disconnected"); 237 Log.d(TAG, "Proxy service disconnected");
215 } 238 }
216 }; 239 };
217 } 240 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld