blob: ae8ebbc9e6d14626e7fd7213b20e9f4924693583 [file] [log] [blame]
Walter Jang6b87ef12016-11-04 14:03:39 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.contacts.common.vcard;
17
18import android.app.Activity;
19import android.app.AlertDialog;
20import android.app.Dialog;
21import android.app.DialogFragment;
22import android.content.DialogInterface;
23import android.os.Bundle;
24
25import com.android.contacts.common.R;
26
27/** Asks for confirmation before importing contacts from a vcard. */
28public class ImportVCardDialogFragment extends DialogFragment {
29
30 /** Callbacks for hosts of the {@link ImportVCardDialogFragment}. */
31 public interface Listener {
32
33 /** Invoked after the user has confirmed that contacts should be imported. */
34 void onImportVCardConfirmed();
35
36 /** Invoked after the user has rejected importing contacts. */
37 void onImportVCardDenied();
38 }
39
40 /** Displays the dialog asking for confirmation before importing contacts. */
41 public static void show(Activity activity) {
42 if (!(activity instanceof Listener)) {
43 throw new IllegalArgumentException(
44 "Activity must implement " + Listener.class.getName());
45 }
46
47 final ImportVCardDialogFragment dialog = new ImportVCardDialogFragment();
48 dialog.show(activity.getFragmentManager(), "importVCardDialogFragment");
49 }
50
51 @Override
52 public Dialog onCreateDialog(Bundle savedInstanceState) {
53 return new AlertDialog.Builder(getActivity())
54 .setIconAttribute(android.R.attr.alertDialogIcon)
55 .setMessage(R.string.import_from_vcf_file_confirmation_message)
56 .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
57 @Override
58 public void onClick(DialogInterface dialog, int whichButton) {
59 final Listener listener = (Listener) getActivity();
60 if (listener != null) {
61 listener.onImportVCardConfirmed();
62 }
63 }
64 })
65 .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
66 @Override
67 public void onClick(DialogInterface dialog, int whichButton) {
68 final Listener listener = (Listener) getActivity();
69 if (listener != null) {
70 listener.onImportVCardDenied();
71 }
72 }
73 })
74 .create();
75 }
76}