aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frontends/android/res/menu/profile_edit.xml28
-rw-r--r--src/frontends/android/res/values/strings.xml5
-rw-r--r--src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java90
3 files changed, 123 insertions, 0 deletions
diff --git a/src/frontends/android/res/menu/profile_edit.xml b/src/frontends/android/res/menu/profile_edit.xml
new file mode 100644
index 000000000..e69020ed0
--- /dev/null
+++ b/src/frontends/android/res/menu/profile_edit.xml
@@ -0,0 +1,28 @@
+<?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.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item
+ android:id="@+id/menu_accept"
+ android:title="@string/profile_edit_save"
+ android:showAsAction="always|withText" />
+
+ <item
+ android:id="@+id/menu_cancel"
+ android:title="@string/profile_edit_cancel"
+ android:showAsAction="ifRoom" />
+
+</menu>
diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml
index b81af924a..9d52c1e3e 100644
--- a/src/frontends/android/res/values/strings.xml
+++ b/src/frontends/android/res/values/strings.xml
@@ -25,11 +25,16 @@
<string name="add_profile">Add VPN profile</string>
<!-- VPN profile details -->
+ <string name="profile_edit_save">Save</string>
+ <string name="profile_edit_cancel">Cancel</string>
<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>
+ <!-- Warnings/Notifications in the details view -->
+ <string name="alert_text_no_input_gateway">Please enter the gateway address here</string>
+ <string name="alert_text_no_input_username">Please enter your username here</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
index 0a8dc1687..56eef15ac 100644
--- a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java
+++ b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileDetailActivity.java
@@ -22,8 +22,13 @@ import org.strongswan.android.data.VpnProfile;
import org.strongswan.android.data.VpnProfileDataSource;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.Window;
import android.widget.EditText;
public class VpnProfileDetailActivity extends Activity
@@ -78,6 +83,91 @@ public class VpnProfileDetailActivity extends Activity
outState.putLong(VpnProfileDataSource.KEY_ID, mId);
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.profile_edit, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
+ switch (item.getItemId())
+ {
+ case android.R.id.home:
+ case R.id.menu_cancel:
+ finish();
+ return true;
+ case R.id.menu_accept:
+ saveProfile();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ /**
+ * Save or update the profile depending on whether we actually have a
+ * profile object or not (this was created in updateProfileData)
+ */
+ private void saveProfile()
+ {
+ if (verifyInput())
+ {
+ if (mProfile != null)
+ {
+ updateProfileData();
+ mDataSource.updateVpnProfile(mProfile);
+ }
+ else
+ {
+ mProfile = new VpnProfile();
+ updateProfileData();
+ mDataSource.insertProfile(mProfile);
+ }
+ setResult(RESULT_OK, new Intent().putExtra(VpnProfileDataSource.KEY_ID, mProfile.getId()));
+ finish();
+ }
+ }
+
+ /**
+ * Verify the user input and display error messages.
+ * @return true if the input is valid
+ */
+ private boolean verifyInput()
+ {
+ boolean valid = true;
+ if (mGateway.getText().toString().trim().isEmpty())
+ {
+ mGateway.setError(getString(R.string.alert_text_no_input_gateway));
+ valid = false;
+ }
+ if (mUsername.getText().toString().trim().isEmpty())
+ {
+ mUsername.setError(getString(R.string.alert_text_no_input_username));
+ valid = false;
+ }
+ return valid;
+ }
+
+ /**
+ * Update the profile object with the data entered by the user
+ */
+ private void updateProfileData()
+ {
+ /* the name is optional, we default to the gateway if none is given */
+ String name = mName.getText().toString().trim();
+ 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);
+ }
+
/**
* Load an existing profile if we got an ID
*/