make the VPN/apps mode have a better UI flow

This commit is contained in:
Nathan Freitas 2016-10-24 14:30:46 -04:00
parent c1ffdbb4e7
commit 28f1dbf7dd
12 changed files with 93 additions and 63 deletions

View File

@ -30,4 +30,5 @@ dependencies {
compile project(':orbotservice')
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
}

View File

@ -86,7 +86,9 @@
<activity android:name=".settings.SettingsPreferences" android:label="@string/app_name"/>
<activity android:name=".ui.AppManager" android:label="@string/app_name"/>
<activity android:name=".ui.AppManager" android:label="@string/app_name"
android:theme="@style/Theme.AppCompat"
/>
<service
android:name=".service.TorService"

View File

@ -22,6 +22,7 @@ import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.settings.SettingsPreferences;
import org.torproject.android.ui.AppManager;
import org.torproject.android.ui.ImageProgressView;
import org.torproject.android.ui.PromoAppsActivity;
import org.torproject.android.ui.Rotate3dAnimation;
@ -111,6 +112,9 @@ public class OrbotMainActivity extends AppCompatActivity
private final static int REQUEST_VPN = 8888;
private final static int REQUEST_SETTINGS = 0x9874;
private final static int REQUEST_VPN_APPS_SELECT = 8889;
private final static boolean mIsLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
// message types for mStatusUpdateHandler
private final static int STATUS_UPDATE = 1;
@ -169,7 +173,8 @@ public class OrbotMainActivity extends AppCompatActivity
private void stopTor() {
imgStatus.setImageResource(R.drawable.torstarting);
requestTorStatus();
Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
stopService(torService);
@ -320,8 +325,12 @@ public class OrbotMainActivity extends AppCompatActivity
Prefs.putUseVpn(isChecked);
if (isChecked)
startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class));
if (isChecked) {
if (mIsLollipop) //let the user choose the apps
startActivityForResult(new Intent(OrbotMainActivity.this, AppManager.class),REQUEST_VPN_APPS_SELECT);
else
startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class));
}
else
stopVpnService();
}
@ -434,11 +443,12 @@ public class OrbotMainActivity extends AppCompatActivity
Intent intent = new Intent(OrbotMainActivity.this, SettingsPreferences.class);
startActivityForResult(intent, REQUEST_SETTINGS);
}
/**
else if (item.getItemId() == R.id.menu_promo_apps)
{
startActivity(new Intent(OrbotMainActivity.this, PromoAppsActivity.class));
}
}*/
else if (item.getItemId() == R.id.menu_exit)
{
//exit app
@ -859,6 +869,10 @@ public class OrbotMainActivity extends AppCompatActivity
}
}
else if (request == REQUEST_VPN_APPS_SELECT)
{
startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class));
}
IntentResult scanResult = IntentIntegrator.parseActivityResult(request, response, data);
if (scanResult != null) {
@ -1191,6 +1205,8 @@ public class OrbotMainActivity extends AppCompatActivity
else
lblStatus.setText(getString(R.string.status_starting_up));
mBtnStart.setText("...");
mBtnBrowser.setEnabled(false);
} else if (torStatus == TorServiceConstants.STATUS_STOPPING) {

View File

@ -23,6 +23,8 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -38,7 +40,7 @@ import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class AppManager extends Activity implements OnCheckedChangeListener, OnClickListener, OrbotConstants {
public class AppManager extends AppCompatActivity implements OnCheckedChangeListener, OnClickListener, OrbotConstants {
private ListView listApps;
private final static String TAG = "Orbot";
@ -47,6 +49,8 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
super.onCreate(savedInstanceState);
this.setContentView(R.layout.layout_apps);
setTitle(R.string.apps_mode);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Button buttonSelectAll, buttonSelectNone, buttonInvert;
@ -108,15 +112,16 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
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();
app.setTorified(true);
}else if (this.status == 1){
if (box.isChecked())
box.performClick();
app.setTorified(false);
}else {
box.performClick();
app.setTorified(!app.isTorified());
}
box.setChecked(app.isTorified());
}
saveAppSettings(context);
loadApps(prefs);
@ -128,15 +133,6 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
super.onResume();
listApps = (ListView)findViewById(R.id.applistview);
Button btnSave = (Button)findViewById(R.id.btnsave);
btnSave.setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
finish();
}
});
mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
loadApps(mPrefs);
}
@ -161,11 +157,18 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
final LayoutInflater inflater = getLayoutInflater();
ListAdapter adapter = new ArrayAdapter<TorifiedApp>(this, R.layout.layout_apps_item, R.id.itemtext,mApps) {
public View getView(int position, View convertView, ViewGroup parent) {
ListEntry entry;
if (convertView == null) {
// Inflate a new view
ListEntry entry = null;
if (convertView == null)
convertView = inflater.inflate(R.layout.layout_apps_item, parent, false);
else
entry = (ListEntry) convertView.getTag();;
if (entry == null) {
// Inflate a new view
entry = new ListEntry();
entry.icon = (ImageView) convertView.findViewById(R.id.itemicon);
entry.box = (CheckBox) convertView.findViewById(R.id.itemcheck);
@ -177,15 +180,11 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
convertView.setTag(entry);
entry.box.setOnCheckedChangeListener(AppManager.this);
} else {
// Convert an existing view
entry = (ListEntry) convertView.getTag();
}
final TorifiedApp app = mApps.get(position);
if (app.getIcon() != null)
if (app.getIcon() != null && entry.icon != null)
entry.icon.setImageDrawable(app.getIcon());
else
entry.icon.setVisibility(View.GONE);

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp"/> // if you want clear round shape then make radius size is half of your button`s height.
<solid android:color="#78af52"/> // Button Colour
<padding
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp"/>
</shape>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:duplicateParentState="true">
@ -25,20 +25,11 @@
</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:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button

View File

@ -5,6 +5,7 @@
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<ImageView android:id="@+id/itemicon" android:layout_width="50dip" android:layout_height="50dip" android:padding="3dip"></ImageView>
<TextView android:layout_height="wrap_content" android:id="@+id/itemtext" android:text="uid:packages" android:textSize="18sp" android:padding="3dip"></TextView>

View File

@ -5,6 +5,7 @@
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_purple"
>
<android.support.v7.widget.Toolbar
@ -67,9 +68,10 @@ android:layout_gravity="center_horizontal|center_vertical"/>
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="40dp"
android:text="@string/menu_start"
android:id="@+id/btnStart"
android:background="@drawable/rounded_button"
/>
@ -77,10 +79,12 @@ android:layout_gravity="center_horizontal|center_vertical"/>
<Button
android:id="@+id/btnBrowser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="40dp"
android:text="@string/menu_browse"
android:ellipsize="end"
android:singleLine="true"
android:background="@drawable/rounded_button"
android:layout_marginLeft="10dp"
/>
</LinearLayout>

View File

@ -24,46 +24,47 @@
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:icon="@drawable/ic_action_settings"
yourapp:showAsAction="always"
yourapp:showAsAction="never"
/>
<item
android:title="@string/menu_qr"
android:showAsAction="never"
yourapp:showAsAction="never"
>
<menu>
<item android:id="@+id/menu_scan"
android:title="@string/menu_scan"
android:showAsAction="never"
yourapp:showAsAction="never"
/>
<item android:id="@+id/menu_share_bridge"
android:title="@string/menu_share_bridge"
android:showAsAction="never"
yourapp:showAsAction="never"
/>
</menu>
</item>
<!--
<item android:id="@+id/menu_promo_apps"
android:title="@string/menu_promo_apps"
android:icon="@drawable/ic_menu_goto"
android:showAsAction="never"
yourapp:showAsAction="never"
/>
-->
<item android:id="@+id/menu_about"
android:title="@string/menu_about"
android:icon="@drawable/ic_menu_about"
android:showAsAction="never"
yourapp:showAsAction="never"
/>
<item android:id="@+id/menu_exit"
android:title="@string/menu_exit"
android:icon="@drawable/ic_menu_exit"
android:showAsAction="never"
yourapp:showAsAction="never"
/>

View File

@ -5,4 +5,5 @@
<color name="panel_background_main">#efefef</color>
<color name="bright_green">#ccff2a</color>
<color name="dark_green">#669901</color>
<color name="dark_purple">#3f2b4f</color>
</resources>

View File

@ -335,5 +335,5 @@
<string name="note_only_standard_tor_bridges_work_on_intel_x86_atom_devices">NOTE: Only standard Tor bridges work on Intel X86/ATOM devices</string>
<string name="vpn_default_world">World</string>
<string name="vpn_default_world">World (Location)</string>
</resources>

View File

@ -146,10 +146,11 @@ public class TorServiceUtils implements TorServiceConstants {
shell = Shell.startShell();
}*/
Runtime.getRuntime().exec("busybox killall " + signal + " " + fileProcBin.getName());
Runtime.getRuntime().exec("toolbox kill " + signal + " " + pidString);
Runtime.getRuntime().exec("busybox kill " + signal + " " + pidString);
Runtime.getRuntime().exec("kill " + signal + " " + pidString);
try { Runtime.getRuntime().exec("busybox killall " + signal + " " + fileProcBin.getName());}catch(IOException ioe){}
try { Runtime.getRuntime().exec("toolbox kill " + signal + " " + pidString);}catch(IOException ioe){}
try { Runtime.getRuntime().exec("busybox kill " + signal + " " + pidString);}catch(IOException ioe){}
try { Runtime.getRuntime().exec("kill " + signal + " " + pidString);}catch(IOException ioe){}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {