update VPN to toggle button

This commit is contained in:
Nathan Freitas 2015-02-04 14:55:42 -05:00
parent 17f2a0bdac
commit ec4350ee40
2 changed files with 16 additions and 7 deletions

View File

@ -170,12 +170,12 @@
android:text="Open Browser" android:text="Open Browser"
/> />
<Button <ToggleButton
android:id="@+id/btnVPN" android:id="@+id/btnVPN"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Start VPN" android:textOff="VPN Off"
android:textOn="VPN On"
/> />
</LinearLayout> </LinearLayout>

View File

@ -58,6 +58,7 @@ import android.view.animation.AccelerateInterpolator;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton;
public class OrbotMainActivity extends Activity implements TorConstants, OnLongClickListener, OnTouchListener, OnSharedPreferenceChangeListener public class OrbotMainActivity extends Activity implements TorConstants, OnLongClickListener, OnTouchListener, OnSharedPreferenceChangeListener
@ -73,7 +74,7 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
private TextView mTxtOrbotLog = null; private TextView mTxtOrbotLog = null;
private Button mBtnBrowser = null; private Button mBtnBrowser = null;
private Button mBtnVPN = null; private ToggleButton mBtnVPN = null;
private DrawerLayout mDrawer; private DrawerLayout mDrawer;
private ActionBarDrawerToggle mDrawerToggle; private ActionBarDrawerToggle mDrawerToggle;
@ -246,14 +247,17 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
}); });
mBtnVPN = (Button)findViewById(R.id.btnVPN); mBtnVPN = (ToggleButton)findViewById(R.id.btnVPN);
mBtnVPN.setOnClickListener(new View.OnClickListener () mBtnVPN.setOnClickListener(new View.OnClickListener ()
{ {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
startVpnService(); if (mBtnVPN.isChecked())
startVpnService();
else
stopVpnService();
} }
@ -808,6 +812,11 @@ public class OrbotMainActivity extends Activity implements TorConstants, OnLongC
} }
} }
public void stopVpnService ()
{
startService(TorServiceConstants.CMD_VPN_CLEAR);
}
private boolean flushTransProxy () private boolean flushTransProxy ()
{ {
startService(TorServiceConstants.CMD_FLUSH); startService(TorServiceConstants.CMD_FLUSH);