Changed TrustedCertificateAdapter for use with ListViews and TrustedCertificateEntry
[strongswan.git] / src / frontends / android / src / org / strongswan / android / ui / adapter / TrustedCertificateAdapter.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.adapter;
17
18 import java.util.List;
19
20 import org.strongswan.android.R;
21 import org.strongswan.android.data.TrustedCertificateEntry;
22
23 import android.content.Context;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ArrayAdapter;
28 import android.widget.TextView;
29
30 public class TrustedCertificateAdapter extends ArrayAdapter<TrustedCertificateEntry>
31 {
32 public TrustedCertificateAdapter(Context context)
33 {
34 super(context, R.layout.trusted_certificates_item);
35 }
36
37 /**
38 * Set new data for this adapter.
39 *
40 * @param data the new data (null to clear)
41 */
42 public void setData(List<TrustedCertificateEntry> data)
43 {
44 clear();
45 if (data != null)
46 {
47 addAll(data);
48 }
49 }
50
51 @Override
52 public View getView(int position, View convertView, ViewGroup parent)
53 {
54 View view;
55 if (convertView != null)
56 {
57 view = convertView;
58 }
59 else
60 {
61 LayoutInflater inflater = LayoutInflater.from(getContext());
62 view = inflater.inflate(R.layout.trusted_certificates_item, parent, false);
63 }
64 TrustedCertificateEntry item = getItem(position);
65 TextView text = (TextView)view.findViewById(R.id.subject_primary);
66 text.setText(item.getSubjectPrimary());
67 text = (TextView)view.findViewById(R.id.subject_secondary);
68 text.setText(item.getSubjectSecondary());
69 return view;
70 }
71 }