Show a button to disconnect the VPN once it is established
authorTobias Brunner <tobias@strongswan.org>
Thu, 9 Aug 2012 09:27:34 +0000 (11:27 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 13 Aug 2012 09:18:51 +0000 (11:18 +0200)
src/frontends/android/res/layout/vpn_state_fragment.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java

index 12d890a..6353f32 100644 (file)
         </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"
index e631a9e..4a719ef 100644 (file)
@@ -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>
index fc250f1..94475a3 100644 (file)
@@ -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)