]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/frontends/android/app/src/main/java/org/strongswan/android/ui/CertificateDeleteConfirmationDialog.java
android: Migrate to the Gradle build system
[thirdparty/strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / ui / CertificateDeleteConfirmationDialog.java
CommitLineData
ac200bcd
TB
1/*
2 * Copyright (C) 2014 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
16package org.strongswan.android.ui;
17
18import org.strongswan.android.R;
19
20import android.app.Activity;
21import android.app.AlertDialog;
22import android.app.Dialog;
23import android.app.DialogFragment;
24import android.content.DialogInterface;
25import android.os.Bundle;
26
27/**
28 * Class that displays a confirmation dialog to delete a selected local
29 * certificate.
30 */
31public class CertificateDeleteConfirmationDialog extends DialogFragment
32{
33 public static final String ALIAS = "alias";
34 OnCertificateDeleteListener mListener;
35
36 /**
37 * Interface that can be implemented by parent activities to get the
38 * alias of the certificate to delete, if the user confirms the deletion.
39 */
40 public interface OnCertificateDeleteListener
41 {
42 public void onDelete(String alias);
43 }
44
45 @Override
46 public void onAttach(Activity activity)
47 {
48 super.onAttach(activity);
49 if (activity instanceof OnCertificateDeleteListener)
50 {
51 mListener = (OnCertificateDeleteListener)activity;
52 }
53 }
54
55 @Override
56 public Dialog onCreateDialog(Bundle savedInstanceState)
57 {
58 return new AlertDialog.Builder(getActivity())
59 .setIcon(android.R.drawable.ic_dialog_alert)
60 .setTitle(R.string.delete_certificate_question)
61 .setMessage(R.string.delete_certificate)
62 .setPositiveButton(R.string.delete_profile, new DialogInterface.OnClickListener() {
63 @Override
64 public void onClick(DialogInterface dialog, int whichButton)
65 {
66 if (mListener != null)
67 {
68 mListener.onDelete(getArguments().getString(ALIAS));
69 }
70 }
71 })
72 .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
73 @Override
74 public void onClick(DialogInterface dialog, int which)
75 {
76 dismiss();
77 }
78 }).create();
79 }
80}