improved activate button responsive to be more instant

svn:r21778
This commit is contained in:
Nathan Freitas 2010-03-01 06:15:35 +00:00
parent 0a602b7868
commit a678969624
2 changed files with 53 additions and 17 deletions

View File

@ -631,16 +631,52 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On
{ {
try try
{ {
if (mService == null) if (mService == null)
{ {
} }
else if (mService.getStatus() == STATUS_READY) else if (mService.getStatus() == STATUS_READY)
{ {
mService.setProfile(PROFILE_ON); //this means turn on mService.setProfile(PROFILE_ON); //this means turn on
imgStatus.setImageResource(R.drawable.torstarting);
lblStatus.setText(getString(R.string.status_starting_up));
Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG);
mHandler.sendMessage(msg);
updateStatus(""); updateStatus("");
}
else
{
mService.setProfile(PROFILE_ONDEMAND); //these means turn off
Message msg = mHandler.obtainMessage(DISABLE_TOR_MSG);
mHandler.sendMessage(msg);
updateStatus("");
}
}
catch (Exception e)
{
Log.i(TAG,"error onclick",e);
}
}
}
private void doTorSetup (boolean enabled)
{
if (enabled)
{
processSettings(); processSettings();
@ -653,10 +689,6 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On
} }
else else
{ {
mService.setProfile(PROFILE_ONDEMAND); //these means turn off
updateStatus("");
if (hasRoot && enableTransparentProxy) if (hasRoot && enableTransparentProxy)
{ {
TorTransProxy.purgeNatIptables(); TorTransProxy.purgeNatIptables();
@ -665,15 +697,6 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On
} }
} }
} }
catch (Exception e)
{
Log.i(TAG,"error onclick",e);
}
}
}
/** /**
* This implementation is used to receive callbacks from the remote * This implementation is used to receive callbacks from the remote
@ -697,6 +720,8 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On
private static final int BUMP_MSG = 1; private static final int BUMP_MSG = 1;
private static final int ENABLE_TOR_MSG = 2;
private static final int DISABLE_TOR_MSG = 3;
private Handler mHandler = new Handler() { private Handler mHandler = new Handler() {
@Override public void handleMessage(Message msg) { @Override public void handleMessage(Message msg) {
@ -711,6 +736,15 @@ public class Orbot extends Activity implements OnClickListener, TorConstants, On
updateStatus(torServiceMsg); updateStatus(torServiceMsg);
break; break;
case ENABLE_TOR_MSG:
doTorSetup(true);
break;
case DISABLE_TOR_MSG:
doTorSetup(false);
break;
default: default:
super.handleMessage(msg); super.handleMessage(msg);
} }

View File

@ -699,6 +699,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void setProfile (int profile) public void setProfile (int profile)
{ {
setTorProfile(profile); setTorProfile(profile);
sendCallbackMessage("");
} }
}; };