add button handle logic

This commit is contained in:
Nathan Freitas 2015-02-01 23:36:19 -05:00
parent 753e21f367
commit c1fe536aeb
2 changed files with 39 additions and 22 deletions

View File

@ -65,10 +65,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
private MenuItem mItemOnOff = null; private MenuItem mItemOnOff = null;
private TextView downloadText = null; private TextView downloadText = null;
private TextView uploadText = null; private TextView uploadText = null;
// private TextView mTxtOrbotLog = null;
// private SlidingDrawer mDrawer = null;
private boolean mDrawerOpen = false; private boolean mDrawerOpen = false;
// private View mViewMain = null;
private Button mBtnBrowser = null;
private Button mBtnVPN = null;
/* Some tracking bits */ /* Some tracking bits */
private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
@ -174,7 +174,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
private void doLayout () private void doLayout ()
{ {
setContentView(R.layout.layout_main); setContentView(R.layout.layout_main);
// lblStatus = (TextView)findViewById(R.id.lblStatus); // lblStatus = (TextView)findViewById(R.id.lblStatus);
// lblStatus.setOnLongClickListener(this); // lblStatus.setOnLongClickListener(this);
imgStatus = (ImageProgressView)findViewById(R.id.imgStatus); imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
@ -230,8 +230,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
// Gesture detection // Gesture detection
mGestureDetector = new GestureDetector(this, new MyGestureDetector()); mGestureDetector = new GestureDetector(this, new MyGestureDetector());
Button btnBrowser = (Button)findViewById(R.id.btnBrowser); mBtnBrowser = (Button)findViewById(R.id.btnBrowser);
btnBrowser.setOnClickListener(new View.OnClickListener () mBtnBrowser.setOnClickListener(new View.OnClickListener ()
{ {
@Override @Override
@ -243,8 +243,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}); });
Button btnVPN = (Button)findViewById(R.id.btnVPN); mBtnVPN = (Button)findViewById(R.id.btnVPN);
btnVPN.setOnClickListener(new View.OnClickListener () mBtnVPN.setOnClickListener(new View.OnClickListener ()
{ {
@Override @Override
@ -401,10 +401,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
startActivity(new Intent(this, ChooseLocaleWizardActivity.class)); startActivity(new Intent(this, ChooseLocaleWizardActivity.class));
} }
else if (item.getItemId() == R.id.menu_verify)
{
doTorCheck();
}
else if (item.getItemId() == R.id.menu_exit) else if (item.getItemId() == R.id.menu_exit)
{ {
//exit app //exit app
@ -418,12 +414,18 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
} }
/**
else if (item.getItemId() == R.id.menu_verify)
{
doTorCheck();
}
else if (item.getItemId() == R.id.menu_vpn) else if (item.getItemId() == R.id.menu_vpn)
{ {
startVpnService(); startVpnService();
} }*/
return true; return true;
} }
/** /**
@ -901,6 +903,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
imgStatus.setImageResource(R.drawable.toron); imgStatus.setImageResource(R.drawable.toron);
mBtnBrowser.setEnabled(true);
mBtnVPN.setEnabled(true);
String lblMsg = getString(R.string.status_activated); String lblMsg = getString(R.string.status_activated);
//lblStatus.setText(lblMsg); //lblStatus.setText(lblMsg);
@ -961,6 +966,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
if (mItemOnOff != null) if (mItemOnOff != null)
mItemOnOff.setTitle(R.string.menu_start); mItemOnOff.setTitle(R.string.menu_start);
mBtnBrowser.setEnabled(false);
mBtnVPN.setEnabled(false);
} }
} }

View File

@ -114,16 +114,25 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
// (i.e., Farsi and Arabic).^M // (i.e., Farsi and Arabic).^M
Locale.setDefault(new Locale("en")); Locale.setDefault(new Locale("en"));
String vpnName = "OrbotVPN";
String virtualGateway = "10.0.0.1";
String virtualRoute = "10.0.0.0";
String virtualIP = "10.0.0.2";
String virtualNetMask = "255.255.2555.0";
String localSocks = "localhost:" + TorServiceConstants.PORT_SOCKS_DEFAULT;
String localDNS = "localhost:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT;
Builder builder = new Builder(); Builder builder = new Builder();
builder.setMtu(VPN_MTU); builder.setMtu(VPN_MTU);
builder.addAddress("10.0.0.1",8); builder.addAddress(virtualGateway,8);
builder.setSession("OrbotVPN"); builder.setSession(vpnName);
builder.addRoute("0.0.0.0",0); builder.addRoute("0.0.0.0",0);
builder.addRoute("10.0.0.0",8); builder.addRoute(virtualRoute,8);
//builder.addRoute("192.0.0.0",8);
//builder.addRoute("192.168.43.0",8); //builder.addDnsServer("8.8.8.8");
builder.addDnsServer("8.8.8.8");
// Create a new interface using the builder and save the parameters. // Create a new interface using the builder and save the parameters.
mInterface = builder.setSession(mSessionName) mInterface = builder.setSession(mSessionName)
@ -132,7 +141,7 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
try try
{ {
Tun2Socks.Start(mInterface, VPN_MTU, "10.0.0.2", "255.255.255.0", "localhost:" + TorServiceConstants.PORT_SOCKS_DEFAULT, "50.116.51.157:7300", true); Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true);
} }
catch (Exception e) catch (Exception e)
{ {
@ -170,7 +179,7 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
/* /*
private void debugPacket(ByteBuffer packet) private void debugPacket(ByteBuffer packet)
{ {b
int buffer = packet.get(); int buffer = packet.get();
int version; int version;