Show a button to disconnect the VPN once it is established

This commit is contained in:
Tobias Brunner
2012-08-13 11:18:51 +02:00
parent a43bdf9a37
commit 8062f973e1
3 changed files with 36 additions and 0 deletions
@@ -72,6 +72,17 @@
</TextView>
</GridLayout>
<Button
android:id="@+id/action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="@string/disconnect"
style="?android:attr/borderlessButtonStyle" >
</Button>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
@@ -53,6 +53,7 @@
<!-- VPN state fragment -->
<string name="state_label">Status:</string>
<string name="profile_label">Profile:</string>
<string name="disconnect">Disconnect</string>
<string name="state_connecting">Connecting&#8230;</string>
<string name="state_connected">Connected</string>
<string name="state_disconnecting">Disconnecting&#8230;</string>
@@ -36,7 +36,9 @@ import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class VpnStateFragment extends Fragment implements VpnStateListener
@@ -45,6 +47,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
private TextView mProfileView;
private TextView mStateView;
private int stateBaseColor;
private Button mActionButton;
private ProgressDialog mProgressDialog;
private State mState;
private VpnStateService mService;
@@ -81,6 +84,19 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
{
View view = inflater.inflate(R.layout.vpn_state_fragment, null);
mActionButton = (Button)view.findViewById(R.id.action);
mActionButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
if (mService != null)
{
mService.disconnect();
}
}
});
enableActionButton(false);
mStateView = (TextView)view.findViewById(R.id.vpn_state);
stateBaseColor = mStateView.getCurrentTextColor();
mProfileView = (TextView)view.findViewById(R.id.vpn_profile_label);
@@ -144,6 +160,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
}
hideProgressDialog();
enableActionButton(false);
mProfileNameView.setText(name);
mState = state;
@@ -162,6 +179,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
break;
case CONNECTED:
showProfile(true);
enableActionButton(true);
mStateView.setText(R.string.state_connected);
mStateView.setTextColor(Color.GREEN);
break;
@@ -180,6 +198,12 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
mProfileNameView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void enableActionButton(boolean enable)
{
mActionButton.setEnabled(enable);
mActionButton.setVisibility(enable ? View.VISIBLE : View.GONE);
}
private void hideProgressDialog()
{
if (mProgressDialog != null)