android: Add the ability to create shortcuts to specific VPN profiles
[strongswan.git] / src / frontends / android / src / org / strongswan / android / ui / VpnProfileSelectActivity.java
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.ui;
17
18 import org.strongswan.android.R;
19 import org.strongswan.android.data.VpnProfile;
20 import org.strongswan.android.ui.VpnProfileListFragment.OnVpnProfileSelectedListener;
21
22 import android.app.Activity;
23 import android.content.Intent;
24 import android.os.Bundle;
25
26 public class VpnProfileSelectActivity extends Activity implements OnVpnProfileSelectedListener
27 {
28 @Override
29 protected void onCreate(Bundle savedInstanceState)
30 {
31 super.onCreate(savedInstanceState);
32 setContentView(R.layout.vpn_profile_select);
33
34 /* we should probably return a result also if the user clicks the back
35 * button before selecting a profile */
36 setResult(RESULT_CANCELED);
37 }
38
39 @Override
40 public void onVpnProfileSelected(VpnProfile profile)
41 {
42 Intent shortcut = new Intent(MainActivity.START_PROFILE);
43 shortcut.putExtra(MainActivity.EXTRA_VPN_PROFILE_ID, profile.getId());
44
45 Intent intent = new Intent();
46 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
47 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profile.getName());
48 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
49 setResult(RESULT_OK, intent);
50 finish();
51 }
52 }