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

« back to all changes in this revision

Viewing changes to src/frontends/android/src/org/strongswan/android/ui/adapter/VpnProfileAdapter.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
 * Copyright (C) 2012 Giuliano Grassi
 
4
 * Copyright (C) 2012 Ralf Sager
 
5
 * Hochschule fuer Technik Rapperswil
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation; either version 2 of the License, or (at your
 
10
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
14
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
15
 * for more details.
 
16
 */
 
17
 
 
18
package org.strongswan.android.ui.adapter;
 
19
 
 
20
import java.util.Collections;
 
21
import java.util.Comparator;
 
22
import java.util.List;
 
23
 
 
24
import org.strongswan.android.R;
 
25
import org.strongswan.android.data.VpnProfile;
 
26
 
 
27
import android.content.Context;
 
28
import android.view.LayoutInflater;
 
29
import android.view.View;
 
30
import android.view.ViewGroup;
 
31
import android.widget.ArrayAdapter;
 
32
import android.widget.TextView;
 
33
 
 
34
public class VpnProfileAdapter extends ArrayAdapter<VpnProfile>
 
35
{
 
36
        private final int resource;
 
37
        private final List<VpnProfile> items;
 
38
 
 
39
        public VpnProfileAdapter(Context context, int resource,
 
40
                                                         List<VpnProfile> items)
 
41
        {
 
42
                super(context, resource, items);
 
43
                this.resource = resource;
 
44
                this.items = items;
 
45
                sortItems();
 
46
        }
 
47
 
 
48
        @Override
 
49
        public View getView(int position, View convertView, ViewGroup parent)
 
50
        {
 
51
                View vpnProfileView;
 
52
                if (convertView != null)
 
53
                {
 
54
                        vpnProfileView = convertView;
 
55
                }
 
56
                else
 
57
                {
 
58
                        LayoutInflater inflater = LayoutInflater.from(getContext());
 
59
                        vpnProfileView = inflater.inflate(resource, null);
 
60
                }
 
61
                VpnProfile profile = getItem(position);
 
62
                TextView tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_name);
 
63
                tv.setText(profile.getName());
 
64
                tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_gateway);
 
65
                tv.setText(getContext().getString(R.string.profile_gateway_label) + " " + profile.getGateway());
 
66
                tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_username);
 
67
                if (profile.getVpnType().getRequiresUsernamePassword())
 
68
                {       /* if the view is reused we make sure it is visible */
 
69
                        tv.setVisibility(View.VISIBLE);
 
70
                        tv.setText(getContext().getString(R.string.profile_username_label) + " " + profile.getUsername());
 
71
                }
 
72
                else
 
73
                {
 
74
                        tv.setVisibility(View.GONE);
 
75
                }
 
76
                tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_certificate);
 
77
                if (profile.getVpnType().getRequiresCertificate())
 
78
                {
 
79
                        tv.setText(getContext().getString(R.string.profile_user_certificate_label) + " " + profile.getUserCertificateAlias());
 
80
                        tv.setVisibility(View.VISIBLE);
 
81
                }
 
82
                else
 
83
                {
 
84
                        tv.setVisibility(View.GONE);
 
85
                }
 
86
                return vpnProfileView;
 
87
        }
 
88
 
 
89
        @Override
 
90
        public void notifyDataSetChanged()
 
91
        {
 
92
                sortItems();
 
93
                super.notifyDataSetChanged();
 
94
        }
 
95
 
 
96
        private void sortItems()
 
97
        {
 
98
                Collections.sort(this.items, new Comparator<VpnProfile>() {
 
99
                        @Override
 
100
                        public int compare(VpnProfile lhs, VpnProfile rhs)
 
101
                        {
 
102
                                return lhs.getName().compareToIgnoreCase(rhs.getName());
 
103
                        }
 
104
                });
 
105
        }
 
106
}