Added an activity to edit basic VPN profile details
authorTobias Brunner <tobias@strongswan.org>
Tue, 17 Jul 2012 17:23:21 +0000 (19:23 +0200)
committerTobias Brunner <tobias@strongswan.org>
Sat, 11 Aug 2012 13:10:34 +0000 (15:10 +0200)
Already load existing data based on extra data delivered with the
Intent, no saving and CA certificate handling yet.

src/frontends/android/AndroidManifest.xml
src/frontends/android/res/layout/profile_detail_view.xml [new file with mode: 0644]
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java [new file with mode: 0644]

index 3a10082..a88bca5 100644 (file)
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        <activity
+            android:name=".ui.VpnProfileDetailActivity"
+            android:label="@string/app_name" >
+        </activity>
+
         <service
             android:name=".logic.CharonVpnService"
             android:exported="false"
diff --git a/src/frontends/android/res/layout/profile_detail_view.xml b/src/frontends/android/res/layout/profile_detail_view.xml
new file mode 100644 (file)
index 0000000..56a5065
--- /dev/null
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2012 Tobias Brunner
+    Copyright (C) 2012 Giuliano Grassi
+    Copyright (C) 2012 Ralf Sager
+    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.
+-->
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        android:padding="10dp" >
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:text="@string/profile_name_label" />
+
+        <EditText
+            android:id="@+id/name"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:inputType="textNoSuggestions"
+            android:hint="@string/profile_name_hint" />
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:text="@string/profile_gateway_label" />
+
+        <EditText
+            android:id="@+id/gateway"
+            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_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>
+
+</ScrollView>
\ No newline at end of file
index 99859d1..b81af92 100644 (file)
 
     <!-- VPN profile list -->
     <string name="no_profiles">No VPN profiles.</string>
+    <string name="add_profile">Add VPN profile</string>
+
+    <!-- VPN profile details -->
+    <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_username_label">Username:</string>
+    <string name="profile_password_label">Password:</string>
+    <string name="profile_password_hint">(prompt when needed)</string>
 
 </resources>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java
new file mode 100644 (file)
index 0000000..0a8dc16
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012 Giuliano Grassi
+ * Copyright (C) 2012 Ralf Sager
+ * 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.
+ */
+
+package org.strongswan.android.ui;
+
+import org.strongswan.android.R;
+import org.strongswan.android.data.VpnProfile;
+import org.strongswan.android.data.VpnProfileDataSource;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.EditText;
+
+public class VpnProfileDetailActivity extends Activity
+{
+       private VpnProfileDataSource mDataSource;
+       private Long mId;
+       private VpnProfile mProfile;
+       private EditText mName;
+       private EditText mGateway;
+       private EditText mUsername;
+       private EditText mPassword;
+
+       @Override
+       public void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+
+               /* the title is set when we load the profile, if any */
+               getActionBar().setDisplayHomeAsUpEnabled(true);
+
+               mDataSource = new VpnProfileDataSource(this);
+               mDataSource.open();
+
+               setContentView(R.layout.profile_detail_view);
+
+               mName = (EditText)findViewById(R.id.name);
+               mPassword = (EditText)findViewById(R.id.password);
+               mGateway = (EditText)findViewById(R.id.gateway);
+               mUsername = (EditText)findViewById(R.id.username);
+
+               mId = savedInstanceState == null ? null : savedInstanceState.getLong(VpnProfileDataSource.KEY_ID);
+               if (mId == null)
+               {
+                       Bundle extras = getIntent().getExtras();
+                       mId = extras == null ? null : extras.getLong(VpnProfileDataSource.KEY_ID);
+               }
+
+               loadProfileData();
+       }
+
+       @Override
+       protected void onDestroy()
+       {
+               super.onDestroy();
+               mDataSource.close();
+       }
+
+       @Override
+       protected void onSaveInstanceState(Bundle outState)
+       {
+               super.onSaveInstanceState(outState);
+               outState.putLong(VpnProfileDataSource.KEY_ID, mId);
+       }
+
+       /**
+        * Load an existing profile if we got an ID
+        */
+       private void loadProfileData()
+       {
+               getActionBar().setTitle(R.string.add_profile);
+               if (mId != null)
+               {
+                       mProfile = mDataSource.getVpnProfile(mId);
+                       if (mProfile != null)
+                       {
+                               mName.setText(mProfile.getName());
+                               mGateway.setText(mProfile.getGateway());
+                               mUsername.setText(mProfile.getUsername());
+                               mPassword.setText(mProfile.getPassword());
+                               getActionBar().setTitle(mProfile.getName());
+                       }
+                       else
+                       {
+                               Log.e(VpnProfileDetailActivity.class.getSimpleName(),
+                                         "VPN profile with id " + mId + " not found");
+                               finish();
+                       }
+               }
+       }
+}