~ubuntu-branches/ubuntu/utopic/strongswan/utopic

« back to all changes in this revision

Viewing changes to src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java

  • Committer: Package Import Robot
  • Author(s): Jonathan Davies
  • Date: 2014-01-20 19:00:59 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20140120190059-z8e4dl3g8cd09yi5
Tags: 5.1.2~dr3+git20130120-0ubuntu1
* Upstream Git snapshot for build fixes with regards to entropy.
* debian/rules:
  - Enforcing DEB_BUILD_OPTIONS=nostrip for library integrity checking.
  - Set TESTS_REDUCED_KEYLENGTHS to one generate smallest key-lengths in
    tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.TrustedCertificateEntry;
 
20
import org.strongswan.android.data.VpnProfileDataSource;
 
21
 
 
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;
 
30
 
 
31
public class TrustedCertificatesActivity extends Activity implements TrustedCertificateListFragment.OnTrustedCertificateSelectedListener
 
32
{
 
33
        @Override
 
34
        public void onCreate(Bundle savedInstanceState)
 
35
        {
 
36
                super.onCreate(savedInstanceState);
 
37
                setContentView(R.layout.trusted_certificates_activity);
 
38
 
 
39
                ActionBar actionBar = getActionBar();
 
40
                actionBar.setDisplayHomeAsUpEnabled(true);
 
41
                actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
 
42
 
 
43
                actionBar.addTab(actionBar
 
44
                        .newTab()
 
45
                        .setText(R.string.system_tab)
 
46
                        .setTabListener(new TrustedCertificatesTabListener(this, "system", false)));
 
47
                actionBar.addTab(actionBar
 
48
                        .newTab()
 
49
                        .setText(R.string.user_tab)
 
50
                        .setTabListener(new TrustedCertificatesTabListener(this, "user", true)));
 
51
 
 
52
                if (savedInstanceState != null)
 
53
                {
 
54
                        actionBar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
 
55
                }
 
56
        }
 
57
 
 
58
        @Override
 
59
        protected void onSaveInstanceState(Bundle outState)
 
60
        {
 
61
                super.onSaveInstanceState(outState);
 
62
                outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
 
63
        }
 
64
 
 
65
        @Override
 
66
        public boolean onOptionsItemSelected(MenuItem item)
 
67
        {
 
68
                switch (item.getItemId())
 
69
                {
 
70
                        case android.R.id.home:
 
71
                                finish();
 
72
                                return true;
 
73
                }
 
74
                return super.onOptionsItemSelected(item);
 
75
        }
 
76
 
 
77
        @Override
 
78
        public void onTrustedCertificateSelected(TrustedCertificateEntry selected)
 
79
        {
 
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);
 
84
                finish();
 
85
        }
 
86
 
 
87
        public static class TrustedCertificatesTabListener implements ActionBar.TabListener
 
88
        {
 
89
                private final String mTag;
 
90
                private final boolean mUser;
 
91
                private Fragment mFragment;
 
92
 
 
93
                public TrustedCertificatesTabListener(Activity activity, String tag, boolean user)
 
94
                {
 
95
                        mTag = tag;
 
96
                        mUser = 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())
 
102
                        {
 
103
                                FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
 
104
                                ft.detach(mFragment);
 
105
                                ft.commit();
 
106
                        }
 
107
                }
 
108
 
 
109
                @Override
 
110
                public void onTabSelected(Tab tab, FragmentTransaction ft)
 
111
                {
 
112
                        if (mFragment == null)
 
113
                        {
 
114
                                mFragment = new TrustedCertificateListFragment();
 
115
                                if (mUser)
 
116
                                {       /* use non empty arguments to indicate this */
 
117
                                        mFragment.setArguments(new Bundle());
 
118
                                }
 
119
                                ft.add(android.R.id.content, mFragment, mTag);
 
120
                        }
 
121
                        else
 
122
                        {
 
123
                                ft.attach(mFragment);
 
124
                        }
 
125
                }
 
126
 
 
127
                @Override
 
128
                public void onTabUnselected(Tab tab, FragmentTransaction ft)
 
129
                {
 
130
                        if (mFragment != null)
 
131
                        {
 
132
                                ft.detach(mFragment);
 
133
                        }
 
134
                }
 
135
 
 
136
                @Override
 
137
                public void onTabReselected(Tab tab, FragmentTransaction ft)
 
138
                {
 
139
                        /* nothing to be done */
 
140
                }
 
141
        }
 
142
}