Fragment added to list the VPN profiles
authorTobias Brunner <tobias@strongswan.org>
Tue, 17 Jul 2012 17:08:08 +0000 (19:08 +0200)
committerTobias Brunner <tobias@strongswan.org>
Sat, 11 Aug 2012 13:10:34 +0000 (15:10 +0200)
src/frontends/android/res/layout/profile_list_fragment.xml [new file with mode: 0644]
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java [new file with mode: 0644]

diff --git a/src/frontends/android/res/layout/profile_list_fragment.xml b/src/frontends/android/res/layout/profile_list_fragment.xml
new file mode 100644 (file)
index 0000000..50d628b
--- /dev/null
@@ -0,0 +1,38 @@
+<?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.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingBottom="10dp"
+    android:paddingTop="10dp"
+    android:paddingLeft="5dp"
+    android:paddingRight="5dp" >
+
+    <ListView
+        android:id="@+id/profile_list"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:dividerHeight="1dp"
+        android:divider="?android:attr/listDivider"
+        android:scrollbarAlwaysDrawVerticalTrack="true" />
+
+     <TextView android:id="@+id/profile_list_empty"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_marginLeft="15dp"
+        android:text="@string/no_profiles"/>
+
+</FrameLayout>
index 83c09a6..5b7acfc 100644 (file)
@@ -21,7 +21,9 @@
     <string name="app_name">strongSwan VPN Client</string>
     <string name="hello">Hello World, strongSwanActivity!</string>
 
+    <!-- VPN profile list -->
+    <string name="no_profiles">No VPN profiles.</string>
     <string name="profile_gateway_label">Gateway:</string>
     <string name="profile_username_label">Username:</string>
 
-</resources>
\ No newline at end of file
+</resources>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java
new file mode 100644 (file)
index 0000000..6b1f419
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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 java.util.List;
+
+import org.strongswan.android.R;
+import org.strongswan.android.data.VpnProfile;
+import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.ui.adapter.VpnProfileAdapter;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+
+public class VpnProfileListFragment extends Fragment
+{
+       private List<VpnProfile> mVpnProfiles;
+       private VpnProfileDataSource mDataSource;
+       private VpnProfileAdapter mListAdapter;
+       private ListView mListView;
+
+       @Override
+       public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                                                        Bundle savedInstanceState)
+       {
+               View view = inflater.inflate(R.layout.profile_list_fragment, null);
+
+               mListView = (ListView)view.findViewById(R.id.profile_list);
+               mListView.setEmptyView(view.findViewById(R.id.profile_list_empty));
+               mListView.setAdapter(mListAdapter);
+
+               return view;
+       }
+
+       @Override
+       public void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+
+               Context context = getActivity().getApplicationContext();
+
+               mDataSource = new VpnProfileDataSource(this.getActivity());
+               mDataSource.open();
+
+               /* cached list of profiles used as backend for the ListView */
+               mVpnProfiles = mDataSource.getAllVpnProfiles();
+
+               mListAdapter = new VpnProfileAdapter(context, R.layout.profile_list_item, mVpnProfiles);
+       }
+
+       @Override
+       public void onDestroy()
+       {
+               super.onDestroy();
+               mDataSource.close();
+       }
+}