From: Tobias Brunner Date: Tue, 17 Jul 2012 17:40:03 +0000 (+0200) Subject: The list fragment uses a menu to provide an option to add new VPN profiles X-Git-Tag: 5.0.1~210^2~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c2e427c287731b7ee70ed6ce060d1d1523062b1b;p=thirdparty%2Fstrongswan.git The list fragment uses a menu to provide an option to add new VPN profiles --- diff --git a/src/frontends/android/res/menu/profile_list.xml b/src/frontends/android/res/menu/profile_list.xml new file mode 100644 index 0000000000..57c9a86a42 --- /dev/null +++ b/src/frontends/android/res/menu/profile_list.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java index ae3a5e3efa..1db68274e1 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java +++ b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java @@ -1,5 +1,23 @@ +/* + * 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 . + * + * 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 android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.net.VpnService; @@ -13,6 +31,9 @@ public class MainActivity extends Activity super.onCreate(savedInstanceState); setContentView(R.layout.main); startVpnService(); + + ActionBar bar = getActionBar(); + bar.setDisplayShowTitleEnabled(false); } private void startVpnService() diff --git a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java index 6b1f4192fa..a7211c5de5 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java @@ -24,16 +24,23 @@ import org.strongswan.android.data.VpnProfile; import org.strongswan.android.data.VpnProfileDataSource; import org.strongswan.android.ui.adapter.VpnProfileAdapter; +import android.app.Activity; import android.app.Fragment; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; public class VpnProfileListFragment extends Fragment { + private static final int ADD_REQUEST = 1; + private List mVpnProfiles; private VpnProfileDataSource mDataSource; private VpnProfileAdapter mListAdapter; @@ -56,6 +63,7 @@ public class VpnProfileListFragment extends Fragment public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setHasOptionsMenu(true); Context context = getActivity().getApplicationContext(); @@ -74,4 +82,47 @@ public class VpnProfileListFragment extends Fragment super.onDestroy(); mDataSource.close(); } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) + { + inflater.inflate(R.menu.profile_list, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) + { + switch (item.getItemId()) + { + case R.id.add_profile: + Intent connectionIntent = new Intent(getActivity(), + VpnProfileDetailActivity.class); + startActivityForResult(connectionIntent, ADD_REQUEST); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) + { + switch (requestCode) + { + case ADD_REQUEST: + if (resultCode != Activity.RESULT_OK) + { + return; + } + long id = data.getLongExtra(VpnProfileDataSource.KEY_ID, 0); + VpnProfile profile = mDataSource.getVpnProfile(id); + if (profile != null) + { + mVpnProfiles.add(profile); + mListAdapter.notifyDataSetChanged(); + } + return; + } + super.onActivityResult(requestCode, resultCode, data); + } }