]> git.ipfire.org Git - thirdparty/strongswan.git/blob
c8e3df38b47a6b9c33e118a6d03d21c7f7f7709b
[thirdparty/strongswan.git] /
1 /*
2 * Copyright (C) 2016 Tobias Brunner
3 * HSR 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 android.content.Context;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.ArrayAdapter;
23 import android.widget.TextView;
24
25 import org.strongswan.android.R;
26 import org.strongswan.android.security.TrustedCertificateEntry;
27
28 import java.util.List;
29
30 public class CertificateIdentitiesAdapter extends ArrayAdapter<String>
31 {
32 TrustedCertificateEntry mCertificate;
33
34 public CertificateIdentitiesAdapter(Context context)
35 {
36 super(context, android.R.layout.simple_dropdown_item_1line);
37 extractIdentities();
38 }
39
40 /**
41 * Set a new certificate for this adapter.
42 *
43 * @param certificate the certificate to extract identities from (null to clear)
44 */
45 public void setCertificate(TrustedCertificateEntry certificate)
46 {
47 mCertificate = certificate;
48 clear();
49 extractIdentities();
50 }
51
52 private void extractIdentities()
53 {
54 if (mCertificate == null)
55 {
56 add(getContext().getString(R.string.profile_user_select_id_init));
57 }
58 else
59 {
60 add(String.format(getContext().getString(R.string.profile_user_select_id_default),
61 mCertificate.getCertificate().getSubjectDN().getName()));
62 addAll(mCertificate.getSubjectAltNames());
63 }
64 }
65 }