Merge branch 'app-selection'

This commit is contained in:
Jordan 2014-08-13 21:39:46 -07:00
commit c0dd584651
3 changed files with 374 additions and 258 deletions

View File

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:duplicateParentState="false">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:duplicateParentState="true">
<!--
<TextView android:text="Select apps to use with Tor:"
<!--
<TextView android:text="Select apps to use with Tor:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
@ -11,9 +16,59 @@
/>
-->
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/btnsave"
android:text="@string/button_close" android:layout_alignParentBottom="true" />
<ListView
android:id="@+id/applistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layout_button_filters"
android:layout_alignParentTop="true" >
</ListView>
<Button
android:id="@+id/btnsave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="@string/button_close" />
<RelativeLayout
android:id="@+id/layout_button_filters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnsave"
android:orientation="horizontal" >
<Button
android:id="@+id/button_proxy_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/button_proxy_none"
android:layout_toStartOf="@+id/button_proxy_none"
android:text="@string/button_proxy_all" />
<Button
android:id="@+id/button_invert_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:text="@string/button_invert_selection" />
<Button
android:id="@+id/button_proxy_none"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/button_invert_selection"
android:layout_toStartOf="@+id/button_invert_selection"
android:text="@string/button_proxy_none" />
</RelativeLayout>
<ListView android:layout_above="@id/btnsave" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/applistview"></ListView>
</RelativeLayout>

View File

@ -134,6 +134,10 @@
<string name="pref_entrance_node_summary">Fingerprints, nicks, countries and addresses for the first hop</string>
<string name="pref_entrance_node_dialog">Enter Entrance Nodes</string>
<string name="button_proxy_all">Proxy All</string>
<string name="button_proxy_none">Proxy None</string>
<string name="button_invert_selection">Invert Selection</string>
<string name="pref_proxy_title">Outbound Network Proxy (Optional)</string>
<string name="pref_proxy_type_title">Outbound Proxy Type</string>

View File

@ -11,11 +11,14 @@ import java.util.Iterator;
import java.util.List;
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;
import android.content.SharedPreferences;
@ -26,7 +29,11 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@ -48,7 +55,30 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
this.setContentView(R.layout.layout_apps);
Button buttonSelectAll, buttonSelectNone, buttonInvert;
buttonSelectAll = (Button) findViewById(R.id.button_proxy_all);
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);
}
});
buttonSelectNone.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
autoCheckApplications(v);
}
});
buttonInvert.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
autoCheckApplications(v);
}
});
}
@ -294,6 +324,33 @@ 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) {