[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] User can "Proxy all" or "Proxy none" apps in AppManager. TODO: fix invert button. It currently just selects none.
commit 67555d1ed45a711fd8d094be2b10310f9dbda4d1
Author: Jordan <jordannh@xxxxxxxx>
Date: Thu Aug 14 13:15:17 2014 -0700
User can "Proxy all" or "Proxy none" apps in AppManager. TODO: fix invert button. It currently just selects none.
---
.../torproject/android/settings/AppManager.java | 111 ++++++++++++--------
1 file changed, 69 insertions(+), 42 deletions(-)
diff --git a/src/org/torproject/android/settings/AppManager.java b/src/org/torproject/android/settings/AppManager.java
index 88e2023..6d86b06 100644
--- a/src/org/torproject/android/settings/AppManager.java
+++ b/src/org/torproject/android/settings/AppManager.java
@@ -13,11 +13,13 @@ import java.util.StringTokenizer;
+
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceUtils;
+
//import android.R;
import android.app.Activity;
import android.content.Context;
@@ -28,6 +30,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
@@ -49,6 +52,7 @@ import android.widget.TextView;
public class AppManager extends Activity implements OnCheckedChangeListener, OnClickListener, TorConstants {
private ListView listApps;
+ private final static String TAG = "Orbot";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -61,27 +65,75 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
buttonSelectNone = (Button) findViewById(R.id.button_proxy_none);
buttonInvert = (Button) findViewById(R.id.button_invert_selection);
- buttonSelectAll.setOnClickListener(new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- autoCheckApplications(v);
+ buttonSelectAll.setOnClickListener(new OnAutoClickListener(0));
+ buttonSelectNone.setOnClickListener(new OnAutoClickListener(1));
+ buttonInvert.setOnClickListener(new OnAutoClickListener(2));
+ }
+
+ class OnAutoClickListener implements Button.OnClickListener {
+ private int status;
+ public OnAutoClickListener(int status){
+ this.status = status;
+ }
+ @SuppressWarnings("unchecked")
+ public void onClick(View button){
+ ListView listView;
+ ViewGroup viewGroup;
+ View parentView, currentView;
+ ArrayAdapter<TorifiedApp> adapter;
+ TorifiedApp app;
+ CheckBox box;
+ float buttonId;
+ boolean[] isSelected;
+ int posI, selectedI, lvSz;
+
+ buttonId = button.getId();
+ listView = (ListView) findViewById(R.id.applistview);
+ lvSz = listView.getCount();
+ isSelected = new boolean[lvSz];
+
+ selectedI = -1;
+
+ if (this.status == 0){
+ Log.d(TAG, "Proxifying ALL");
+ }else if (this.status == 1){
+ Log.d(TAG, "Proxifying NONE");
+ }else {
+ Log.d(TAG, "Proxifying invert");
}
- });
- buttonSelectNone.setOnClickListener(new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- autoCheckApplications(v);
+
+ Context context = getApplicationContext();
+ SharedPreferences prefs = TorServiceUtils.getSharedPrefs(context);
+ ArrayList<TorifiedApp> apps = getApps(context, prefs);
+ parentView = (View) findViewById(R.layout.layout_apps);
+ viewGroup = (ViewGroup) listView;
+
+ adapter = (ArrayAdapter<TorifiedApp>) listApps.getAdapter();
+ if (adapter == null){
+ Log.w(TAG, "List adapter is null. Getting apps.");
+ loadApps(prefs);
+ adapter = (ArrayAdapter<TorifiedApp>) listApps.getAdapter();
}
- });
- buttonInvert.setOnClickListener(new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- autoCheckApplications(v);
+
+ for (int i = 0 ; i < adapter.getCount(); ++i){
+ app = (TorifiedApp) adapter.getItem(i);
+ currentView = adapter.getView(i, parentView, viewGroup);
+ box = (CheckBox) currentView.findViewById(R.id.itemcheck);
+ if (this.status == 0){
+ if (!box.isChecked())
+ box.performClick();
+ }else if (buttonId == R.id.button_proxy_none){
+ if (box.isChecked())
+ box.performClick();
+ }else {
+ box.performClick();
+ }
}
- });
+ saveAppSettings(context);
+ loadApps(prefs);
+ }
}
-
@Override
protected void onResume() {
super.onResume();
@@ -324,32 +376,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
}
- public void autoCheckApplications(View button){
- ListView listView;
- ListAdapter adapter;
- TorifiedApp app;
- float buttonId;
- boolean[] isSelected;
- int posI, selectedI, lvSz;
-
- buttonId = button.getId();
- listView = (ListView) findViewById(R.id.applistview);
- lvSz = listView.getCount();
- isSelected = new boolean[lvSz];
-
- selectedI = -1;
-
- for (posI = 0; posI < lvSz; ++posI){
- app = (TorifiedApp) listView.getItemAtPosition(posI);
- if (buttonId == R.id.button_proxy_all){
- app.setTorified(true);
- }else if (buttonId == R.id.button_proxy_none){
- app.setTorified(false);
- }else {
- app.setTorified(!app.isTorified());
- }
- }
- }
+
public void onClick(View v) {
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits