2
* Copyright (C) 2012 Tobias Brunner
3
* Copyright (C) 2012 Giuliano Grassi
4
* Copyright (C) 2012 Ralf Sager
5
* Hochschule fuer Technik Rapperswil
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>.
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
18
package org.strongswan.android.ui.adapter;
20
import java.util.Collections;
21
import java.util.Comparator;
22
import java.util.List;
24
import org.strongswan.android.R;
25
import org.strongswan.android.data.VpnProfile;
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;
34
public class VpnProfileAdapter extends ArrayAdapter<VpnProfile>
36
private final int resource;
37
private final List<VpnProfile> items;
39
public VpnProfileAdapter(Context context, int resource,
40
List<VpnProfile> items)
42
super(context, resource, items);
43
this.resource = resource;
49
public View getView(int position, View convertView, ViewGroup parent)
52
if (convertView != null)
54
vpnProfileView = convertView;
58
LayoutInflater inflater = LayoutInflater.from(getContext());
59
vpnProfileView = inflater.inflate(resource, null);
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());
74
tv.setVisibility(View.GONE);
76
tv = (TextView)vpnProfileView.findViewById(R.id.profile_item_certificate);
77
if (profile.getVpnType().getRequiresCertificate())
79
tv.setText(getContext().getString(R.string.profile_user_certificate_label) + " " + profile.getUserCertificateAlias());
80
tv.setVisibility(View.VISIBLE);
84
tv.setVisibility(View.GONE);
86
return vpnProfileView;
90
public void notifyDataSetChanged()
93
super.notifyDataSetChanged();
96
private void sortItems()
98
Collections.sort(this.items, new Comparator<VpnProfile>() {
100
public int compare(VpnProfile lhs, VpnProfile rhs)
102
return lhs.getName().compareToIgnoreCase(rhs.getName());