2
* Copyright (C) 2012 Tobias Brunner
3
* Hochschule fuer Technik Rapperswil
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>.
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
16
package org.strongswan.android.ui;
18
import org.strongswan.android.R;
19
import org.strongswan.android.data.TrustedCertificateEntry;
20
import org.strongswan.android.data.VpnProfileDataSource;
22
import android.app.ActionBar;
23
import android.app.ActionBar.Tab;
24
import android.app.Activity;
25
import android.app.Fragment;
26
import android.app.FragmentTransaction;
27
import android.content.Intent;
28
import android.os.Bundle;
29
import android.view.MenuItem;
31
public class TrustedCertificatesActivity extends Activity implements TrustedCertificateListFragment.OnTrustedCertificateSelectedListener
34
public void onCreate(Bundle savedInstanceState)
36
super.onCreate(savedInstanceState);
37
setContentView(R.layout.trusted_certificates_activity);
39
ActionBar actionBar = getActionBar();
40
actionBar.setDisplayHomeAsUpEnabled(true);
41
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
43
actionBar.addTab(actionBar
45
.setText(R.string.system_tab)
46
.setTabListener(new TrustedCertificatesTabListener(this, "system", false)));
47
actionBar.addTab(actionBar
49
.setText(R.string.user_tab)
50
.setTabListener(new TrustedCertificatesTabListener(this, "user", true)));
52
if (savedInstanceState != null)
54
actionBar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
59
protected void onSaveInstanceState(Bundle outState)
61
super.onSaveInstanceState(outState);
62
outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
66
public boolean onOptionsItemSelected(MenuItem item)
68
switch (item.getItemId())
70
case android.R.id.home:
74
return super.onOptionsItemSelected(item);
78
public void onTrustedCertificateSelected(TrustedCertificateEntry selected)
80
/* the user selected a certificate, return to calling activity */
81
Intent intent = new Intent();
82
intent.putExtra(VpnProfileDataSource.KEY_CERTIFICATE, selected.getAlias());
83
setResult(Activity.RESULT_OK, intent);
87
public static class TrustedCertificatesTabListener implements ActionBar.TabListener
89
private final String mTag;
90
private final boolean mUser;
91
private Fragment mFragment;
93
public TrustedCertificatesTabListener(Activity activity, String tag, boolean user)
97
/* check to see if we already have a fragment for this tab, probably
98
* from a previously saved state. if so, deactivate it, because the
99
* initial state is that no tab is shown */
100
mFragment = activity.getFragmentManager().findFragmentByTag(mTag);
101
if (mFragment != null && !mFragment.isDetached())
103
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
104
ft.detach(mFragment);
110
public void onTabSelected(Tab tab, FragmentTransaction ft)
112
if (mFragment == null)
114
mFragment = new TrustedCertificateListFragment();
116
{ /* use non empty arguments to indicate this */
117
mFragment.setArguments(new Bundle());
119
ft.add(android.R.id.content, mFragment, mTag);
123
ft.attach(mFragment);
128
public void onTabUnselected(Tab tab, FragmentTransaction ft)
130
if (mFragment != null)
132
ft.detach(mFragment);
137
public void onTabReselected(Tab tab, FragmentTransaction ft)
139
/* nothing to be done */