android: Add the ability to create shortcuts to specific VPN profiles
authorTobias Brunner <tobias@strongswan.org>
Wed, 7 Nov 2012 15:09:59 +0000 (16:09 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 21 Nov 2012 17:57:41 +0000 (18:57 +0100)
src/frontends/android/AndroidManifest.xml
src/frontends/android/res/layout/vpn_profile_select.xml [new file with mode: 0644]
src/frontends/android/res/values-de/strings.xml
src/frontends/android/res/values-pl/strings.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/VpnProfileSelectActivity.java [new file with mode: 0644]

index c191a9e..24528cc 100644 (file)
             android:name=".ui.LogActivity"
             android:label="@string/log_title" >
         </activity>
+        <activity
+            android:name=".ui.VpnProfileSelectActivity"
+            android:label="@string/strongswan_shortcut" >
+            <intent-filter>
+                <action android:name="android.intent.action.CREATE_SHORTCUT" />
+                <action android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
 
         <service
             android:name=".logic.VpnStateService"
diff --git a/src/frontends/android/res/layout/vpn_profile_select.xml b/src/frontends/android/res/layout/vpn_profile_select.xml
new file mode 100644 (file)
index 0000000..7f49aa4
--- /dev/null
@@ -0,0 +1,30 @@
+<?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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:strongswan="http://schemas.android.com/apk/res/org.strongswan.android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <fragment
+            class="org.strongswan.android.ui.VpnProfileListFragment"
+            android:id="@+id/profile_list_frag"
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+            android:layout_weight="1"
+            strongswan:read_only="true" />
+
+</LinearLayout>
\ No newline at end of file
index 5c922ad..a89425c 100644 (file)
@@ -28,6 +28,7 @@
     <string name="vpn_not_supported_during_lockdown">VPN Verbindungen sind nicht möglich im abgeriegelten Modus.</string>
     <string name="loading">Laden&#8230;</string>
     <string name="profile_not_found">Profil nicht gefunden</string>
+    <string name="strongswan_shortcut">strongSwan-Verknüpfung</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index 80fab63..4df32c5 100644 (file)
@@ -30,6 +30,7 @@
     <string name="vpn_not_supported_during_lockdown">Polączenia nie sa możliwe w trybie zamkniętym</string>
     <string name="loading">Wczytywanie&#8230;</string>
     <string name="profile_not_found">Nie znaleziono profilu</string>
+    <string name="strongswan_shortcut">Skrót strongSwan</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
index 84fdf38..eba7a66 100644 (file)
@@ -28,6 +28,7 @@
     <string name="vpn_not_supported_during_lockdown">VPN connections are not supported in lockdown mode.</string>
     <string name="loading">Loading&#8230;</string>
     <string name="profile_not_found">Profile not found</string>
+    <string name="strongswan_shortcut">strongSwan shortcut</string>
 
     <!-- Log view -->
     <string name="log_title">Log</string>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileSelectActivity.java b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileSelectActivity.java
new file mode 100644 (file)
index 0000000..b4d34f5
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.strongswan.android.ui;
+
+import org.strongswan.android.R;
+import org.strongswan.android.data.VpnProfile;
+import org.strongswan.android.ui.VpnProfileListFragment.OnVpnProfileSelectedListener;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class VpnProfileSelectActivity extends Activity implements OnVpnProfileSelectedListener
+{
+       @Override
+       protected void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.vpn_profile_select);
+
+               /* we should probably return a result also if the user clicks the back
+                * button before selecting a profile */
+               setResult(RESULT_CANCELED);
+       }
+
+       @Override
+       public void onVpnProfileSelected(VpnProfile profile)
+       {
+               Intent shortcut = new Intent(MainActivity.START_PROFILE);
+               shortcut.putExtra(MainActivity.EXTRA_VPN_PROFILE_ID, profile.getId());
+
+               Intent intent = new Intent();
+               intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
+               intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profile.getName());
+               intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
+               setResult(RESULT_OK, intent);
+               finish();
+       }
+}