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

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

Issue 8493083: ABP/Android UI (Closed)
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:
View unified diff | Download patch
OLDNEW
(Empty)
1 package org.adblockplus.android;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.adblockplus.android.updater.AlarmReceiver;
7
8 import android.app.AlertDialog;
9 import android.app.Dialog;
10 import android.content.ComponentName;
11 import android.content.DialogInterface;
12 import android.content.Intent;
13 import android.content.ServiceConnection;
14 import android.content.SharedPreferences;
15 import android.content.pm.PackageInfo;
16 import android.content.pm.PackageManager.NameNotFoundException;
17 import android.os.Build;
18 import android.os.Bundle;
19 import android.os.IBinder;
20 import android.preference.Preference;
21 import android.preference.Preference.OnPreferenceClickListener;
22 import android.preference.PreferenceManager;
23 import android.preference.PreferenceScreen;
24 import android.text.ClipboardManager;
25 import android.text.TextUtils;
26 import android.util.Log;
27 import android.view.View;
28 import android.widget.ScrollView;
29 import android.widget.TextView;
30 import android.widget.Toast;
31
32 /**
33 * Advanced settings UI.
34 */
35 public class AdvancedPreferences extends SummarizedPreferences
36 {
37 private static final String TAG = "AdvancedPreferences";
38
39 private static final int CONFIGURATION_DIALOG = 1;
40
41 private static ProxyService proxyService = null;
42
43 private boolean hasNativeProxy;
44
45 @Override
46 public void onCreate(Bundle savedInstanceState)
47 {
48 super.onCreate(savedInstanceState);
49
50 hasNativeProxy = Build.VERSION.SDK_INT >= 12; // Honeycomb 3.1
51
52 addPreferencesFromResource(R.xml.preferences_advanced);
53
54 PreferenceScreen screen = getPreferenceScreen();
55 if (hasNativeProxy)
56 {
57 screen.removePreference(findPreference(getString(R.string.pref_proxy)));
58 }
59 if (getResources().getBoolean(R.bool.def_release))
60 {
61 screen.removePreference(findPreference(getString(R.string.pref_support)));
62 }
63 else
64 {
65 Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate ));
66 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener()
67 {
68 public boolean onPreferenceClick(Preference preference)
69 {
70 Intent updater = new Intent(getApplicationContext(), AlarmReceiver.cla ss).putExtra("notifynoupdate", true);
71 sendBroadcast(updater);
72 return true;
73 }
74 });
75
76 Preference prefConfiguration = findPreference(getString(R.string.pref_conf iguration));
77 prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen er()
78 {
79 public boolean onPreferenceClick(Preference preference)
80 {
81 showDialog(CONFIGURATION_DIALOG);
82 return true;
83 }
84 });
85 }
86 }
87
88 @Override
89 public void onResume()
90 {
91 super.onResume();
92 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this );
93 int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_refres h), "0"));
94 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ;
95 connect();
96 }
97
98 @Override
99 public void onPause()
100 {
101 super.onPause();
102 disconnect();
103 }
104
105 @Override
106 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key)
107 {
108 if (getString(R.string.pref_refresh).equals(key))
109 {
110 int refresh = Integer.valueOf(sharedPreferences.getString(getString(R.stri ng.pref_refresh), "0"));
111 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0);
112 }
113 if (getString(R.string.pref_crashreport).equals(key))
114 {
115 AdblockPlus application = AdblockPlus.getApplication();
116 application.updateCrashReportStatus();
117 }
118 super.onSharedPreferenceChanged(sharedPreferences, key);
119 }
120
121 @Override
122 protected Dialog onCreateDialog(int id)
123 {
124 Dialog dialog = null;
125 switch (id)
126 {
127 case CONFIGURATION_DIALOG:
128 List<String> items = new ArrayList<String>();
129 int buildNumber = -1;
130 try
131 {
132 PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
133 buildNumber = pi.versionCode;
134 }
135 catch (NameNotFoundException e)
136 {
137 // ignore - this shouldn't happen
138 e.printStackTrace();
139 }
140 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, buil dNumber));
141 if (proxyService != null)
142 {
143 items.add(String.format("Local port: %d", proxyService.port));
144 if (proxyService.isTransparent())
145 {
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 }
157 }
158 if (proxyService.isNativeProxy())
159 {
160 items.add("Uses native proxy");
161 }
162 if (hasNativeProxy)
163 {
164 String[] px = proxyService.getUserProxy();
165 if (px != null)
166 {
167 items.add("System settings:");
168 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2]));
169 }
170 }
171 items.add("Proxy settings:");
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"),
173 proxyService.proxy.props.getProperty("adblock.proxyExcl")));
174 if (proxyService.proxy.props.getProperty("adblock.auth") != null)
175 items.add("Auth: yes");
176 }
177 else
178 {
179 items.add("Service not running");
180 }
181
182 ScrollView scrollPane = new ScrollView(this);
183 TextView messageText = new TextView(this);
184 messageText.setPadding(12, 6, 12, 6);
185 messageText.setText(TextUtils.join("\n", items));
186 messageText.setOnClickListener(new View.OnClickListener()
187 {
188
189 @Override
190 public void onClick(View v)
191 {
192 ClipboardManager manager = (ClipboardManager) getSystemService(CLIPB OARD_SERVICE);
193 TextView showTextParam = (TextView) v;
194 manager.setText(showTextParam.getText());
195 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show();
196 }
197 });
198 scrollPane.addView(messageText);
199
200 AlertDialog.Builder builder = new AlertDialog.Builder(this);
201 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false)
202 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( )
203 {
204 public void onClick(DialogInterface dialog, int id)
205 {
206 dialog.cancel();
207 }
208 });
209 dialog = builder.create();
210 break;
211 }
212 return dialog;
213 }
214
215 private void connect()
216 {
217 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ;
218 }
219
220 private void disconnect()
221 {
222 unbindService(proxyServiceConnection);
223 proxyService = null;
224 }
225
226 private ServiceConnection proxyServiceConnection = new ServiceConnection()
227 {
228 public void onServiceConnected(ComponentName className, IBinder service)
229 {
230 proxyService = ((ProxyService.LocalBinder) service).getService();
231 Log.d(TAG, "Proxy service connected");
232 }
233
234 public void onServiceDisconnected(ComponentName className)
235 {
236 proxyService = null;
237 Log.d(TAG, "Proxy service disconnected");
238 }
239 };
240 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/AboutDialog.java ('k') | src/org/adblockplus/android/BootBroadcastReceiver.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld