android: Spinner added to select the VPN type
authorTobias Brunner <tobias@strongswan.org>
Mon, 27 Aug 2012 14:51:41 +0000 (16:51 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 31 Aug 2012 16:24:19 +0000 (18:24 +0200)
src/frontends/android/res/layout/profile_detail_view.xml
src/frontends/android/res/values-de/arrays.xml [new file with mode: 0644]
src/frontends/android/res/values-de/strings.xml
src/frontends/android/res/values-pl/arrays.xml [new file with mode: 0644]
src/frontends/android/res/values-pl/strings.xml
src/frontends/android/res/values/arrays.xml [new file with mode: 0644]
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/data/VpnType.java
src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java

index d9ccca5..1ca562a 100644 (file)
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="10dp"
-            android:text="@string/profile_username_label" />
+            android:text="@string/profile_vpn_type_label" />
 
-        <EditText
-            android:id="@+id/username"
+        <Spinner
+            android:id="@+id/vpn_type"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:inputType="textNoSuggestions" />
+            android:spinnerMode="dialog"
+            android:entries="@array/vpn_types" />
 
-        <TextView
+        <LinearLayout
+            android:id="@+id/username_password_group"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="10dp"
-            android:text="@string/profile_password_label" />
+            android:orientation="vertical" >
 
-        <EditText
-            android:id="@+id/password"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:inputType="textPassword|textNoSuggestions"
-            android:hint="@string/profile_password_hint" />
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="10dp"
+                android:text="@string/profile_username_label" />
+
+            <EditText
+                android:id="@+id/username"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:singleLine="true"
+                android:inputType="textNoSuggestions" />
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="10dp"
+                android:text="@string/profile_password_label" />
+
+            <EditText
+                android:id="@+id/password"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:singleLine="true"
+                android:inputType="textPassword|textNoSuggestions"
+                android:hint="@string/profile_password_hint" />
+
+        </LinearLayout>
 
         <TextView
             android:layout_width="match_parent"
diff --git a/src/frontends/android/res/values-de/arrays.xml b/src/frontends/android/res/values-de/arrays.xml
new file mode 100644 (file)
index 0000000..8661a37
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2012 Tobias Brunner
+    Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<resources>
+    <!-- the order here must match the enum entries in VpnType.java -->
+    <string-array name="vpn_types">
+        <item>IKEv2 EAP (Benutzername/Passwort)</item>
+    </string-array>
+</resources>
\ No newline at end of file
index 9f3f637..9e415ab 100644 (file)
@@ -49,6 +49,7 @@
     <string name="profile_name_label">Profilname:</string>
     <string name="profile_name_hint">(Gateway-Adresse verwenden)</string>
     <string name="profile_gateway_label">Gateway:</string>
+    <string name="profile_vpn_type_label">Typ:</string>
     <string name="profile_username_label">Benutzername:</string>
     <string name="profile_password_label">Passwort:</string>
     <string name="profile_password_hint">(anfordern wenn benötigt)</string>
diff --git a/src/frontends/android/res/values-pl/arrays.xml b/src/frontends/android/res/values-pl/arrays.xml
new file mode 100644 (file)
index 0000000..ed14934
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2012 Tobias Brunner
+    Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<resources>
+    <!-- the order here must match the enum entries in VpnType.java -->
+    <string-array name="vpn_types">
+        <item>IKEv2 EAP (użytkownik/hasło)</item>
+    </string-array>
+</resources>
\ No newline at end of file
index e7d4670..4a474e8 100644 (file)
@@ -51,6 +51,7 @@
     <string name="profile_name_label">Nazwa profilu:</string>
     <string name="profile_name_hint">(użyj adresu bramki)</string>
     <string name="profile_gateway_label">Bramka:</string>
+    <string name="profile_vpn_type_label">Typ:</string>
     <string name="profile_username_label">Użytkownik:</string>
     <string name="profile_password_label">Hasło:</string>
     <string name="profile_password_hint">(w razie potrzebz zapromptuj)</string>
diff --git a/src/frontends/android/res/values/arrays.xml b/src/frontends/android/res/values/arrays.xml
new file mode 100644 (file)
index 0000000..62164f7
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2012 Tobias Brunner
+    Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<resources>
+    <!-- the order here must match the enum entries in VpnType.java -->
+    <string-array name="vpn_types">
+        <item>IKEv2 EAP (Username/Password)</item>
+    </string-array>
+</resources>
\ No newline at end of file
index bc7fa4a..29cd643 100644 (file)
@@ -49,6 +49,7 @@
     <string name="profile_name_label">Profile Name:</string>
     <string name="profile_name_hint">(use gateway address)</string>
     <string name="profile_gateway_label">Gateway:</string>
+    <string name="profile_vpn_type_label">Type:</string>
     <string name="profile_username_label">Username:</string>
     <string name="profile_password_label">Password:</string>
     <string name="profile_password_hint">(prompt when needed)</string>
index 35b32da..44a4fa6 100644 (file)
@@ -17,6 +17,7 @@ package org.strongswan.android.data;
 
 public enum VpnType
 {
+       /* the order here must match the items in R.array.vpn_types */
        IKEV2_EAP("ikev2-eap", true, false),
        IKEV2_CERT("ikev2-cert", false, true);
 
index 73365b4..73fa301 100644 (file)
@@ -23,6 +23,7 @@ import org.strongswan.android.R;
 import org.strongswan.android.data.TrustedCertificateEntry;
 import org.strongswan.android.data.VpnProfile;
 import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.data.VpnType;
 import org.strongswan.android.logic.TrustedCertificateManager;
 
 import android.app.Activity;
@@ -36,11 +37,15 @@ import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.CheckBox;
 import android.widget.CompoundButton;
 import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.EditText;
 import android.widget.RelativeLayout;
+import android.widget.Spinner;
 import android.widget.TextView;
 
 public class VpnProfileDetailActivity extends Activity
@@ -50,9 +55,12 @@ public class VpnProfileDetailActivity extends Activity
        private VpnProfileDataSource mDataSource;
        private Long mId;
        private TrustedCertificateEntry mCertEntry;
+       private VpnType mVpnType = VpnType.IKEV2_EAP;
        private VpnProfile mProfile;
        private EditText mName;
        private EditText mGateway;
+       private Spinner mSelectVpnType;
+       private ViewGroup mUsernamePassword;
        private EditText mUsername;
        private EditText mPassword;
        private CheckBox mCheckAuto;
@@ -60,7 +68,6 @@ public class VpnProfileDetailActivity extends Activity
        private TextView mCertTitle;
        private TextView mCertSubtitle;
 
-
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
@@ -75,15 +82,35 @@ public class VpnProfileDetailActivity extends Activity
                setContentView(R.layout.profile_detail_view);
 
                mName = (EditText)findViewById(R.id.name);
-               mPassword = (EditText)findViewById(R.id.password);
                mGateway = (EditText)findViewById(R.id.gateway);
+               mSelectVpnType = (Spinner)findViewById(R.id.vpn_type);
+
+               mUsernamePassword = (ViewGroup)findViewById(R.id.username_password_group);
                mUsername = (EditText)findViewById(R.id.username);
+               mPassword = (EditText)findViewById(R.id.password);
 
                mCheckAuto = (CheckBox)findViewById(R.id.ca_auto);
                mSelectCert = (RelativeLayout)findViewById(R.id.select_certificate);
                mCertTitle = (TextView)findViewById(R.id.select_certificate_title);
                mCertSubtitle = (TextView)findViewById(R.id.select_certificate_subtitle);
 
+
+               mSelectVpnType.setOnItemSelectedListener(new OnItemSelectedListener() {
+                       @Override
+                       public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
+                       {
+                               mVpnType = VpnType.values()[position];
+                               updateClientCredentialView();
+                       }
+
+                       @Override
+                       public void onNothingSelected(AdapterView<?> parent)
+                       {       /* should not happen */
+                               mVpnType = VpnType.IKEV2_EAP;
+                               updateClientCredentialView();
+                       }
+               });
+
                mCheckAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
@@ -110,6 +137,7 @@ public class VpnProfileDetailActivity extends Activity
 
                loadProfileData(savedInstanceState);
 
+               updateClientCredentialView();
                updateCertificateSelector();
        }
 
@@ -179,6 +207,14 @@ public class VpnProfileDetailActivity extends Activity
        }
 
        /**
+        * Update the UI to enter client credentials depending on the type of VPN currently selected
+        */
+       private void updateClientCredentialView()
+       {
+               mUsernamePassword.setVisibility(mVpnType.getRequiresUsernamePassword() ? View.VISIBLE : View.GONE);
+       }
+
+       /**
         * Show an alert in case the previously selected certificate is not found anymore
         * or the user did not select a certificate in the spinner.
         */
@@ -262,10 +298,13 @@ public class VpnProfileDetailActivity extends Activity
                        mGateway.setError(getString(R.string.alert_text_no_input_gateway));
                        valid = false;
                }
-               if (mUsername.getText().toString().trim().isEmpty())
+               if (mVpnType.getRequiresUsernamePassword())
                {
-                       mUsername.setError(getString(R.string.alert_text_no_input_username));
-                       valid = false;
+                       if (mUsername.getText().toString().trim().isEmpty())
+                       {
+                               mUsername.setError(getString(R.string.alert_text_no_input_username));
+                               valid = false;
+                       }
                }
                if (!mCheckAuto.isChecked() && mCertEntry == null)
                {
@@ -285,10 +324,14 @@ public class VpnProfileDetailActivity extends Activity
                String gateway = mGateway.getText().toString().trim();
                mProfile.setName(name.isEmpty() ? gateway : name);
                mProfile.setGateway(gateway);
-               mProfile.setUsername(mUsername.getText().toString().trim());
-               String password = mPassword.getText().toString().trim();
-               password = password.isEmpty() ? null : password;
-               mProfile.setPassword(password);
+               mProfile.setVpnType(mVpnType);
+               if (mVpnType.getRequiresUsernamePassword())
+               {
+                       mProfile.setUsername(mUsername.getText().toString().trim());
+                       String password = mPassword.getText().toString().trim();
+                       password = password.isEmpty() ? null : password;
+                       mProfile.setPassword(password);
+               }
                String certAlias = mCheckAuto.isChecked() ? null : mCertEntry.getAlias();
                mProfile.setCertificateAlias(certAlias);
        }
@@ -310,6 +353,7 @@ public class VpnProfileDetailActivity extends Activity
                        {
                                mName.setText(mProfile.getName());
                                mGateway.setText(mProfile.getGateway());
+                               mVpnType = mProfile.getVpnType();
                                mUsername.setText(mProfile.getUsername());
                                mPassword.setText(mProfile.getPassword());
                                alias = mProfile.getCertificateAlias();
@@ -323,6 +367,8 @@ public class VpnProfileDetailActivity extends Activity
                        }
                }
 
+               mSelectVpnType.setSelection(mVpnType.ordinal());
+
                /* check if the user selected a certificate previously */
                alias = savedInstanceState == null ? alias : savedInstanceState.getString(VpnProfileDataSource.KEY_CERTIFICATE);
                mCheckAuto.setChecked(alias == null);