blob: d467f3c0a421842a48581fa18c909f7489297dfa [file] [log] [blame]
Walter Janged8f6c92015-01-30 16:07:47 -08001/*
2 * Copyright (C) 2015 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 */
16
17package com.android.contacts.editor;
18
19import com.android.contacts.R;
20
21import android.app.AlertDialog;
22import android.app.Dialog;
23import android.app.DialogFragment;
24import android.content.DialogInterface;
25import android.os.Bundle;
26
27/**
28 * Asks the user whether to cancel editing the contact.
29 */
30public class CancelEditDialogFragment extends DialogFragment {
31
32 private static final String TAG = "cancelEditor";
33
34 /**
35 * Shows a {@link CancelEditDialogFragment} after setting the given Fragment as the
36 * target of the dialog.
37 */
Gary Mai363af602016-09-28 10:01:23 -070038 public static void show(ContactEditorFragment fragment) {
Walter Janged8f6c92015-01-30 16:07:47 -080039 final CancelEditDialogFragment dialog = new CancelEditDialogFragment();
40 dialog.setTargetFragment(fragment, 0);
41 dialog.show(fragment.getFragmentManager(), TAG);
42 }
43
44 @Override
45 public Dialog onCreateDialog(Bundle savedInstanceState) {
46 return new AlertDialog.Builder(getActivity())
47 .setIconAttribute(android.R.attr.alertDialogIcon)
48 .setMessage(R.string.cancel_confirmation_dialog_message)
Walter Jangd1cc5fe2016-01-25 15:44:01 -080049 .setPositiveButton(R.string.cancel_confirmation_dialog_cancel_editing_button,
Tingting Wang168331d2015-10-30 12:00:57 -070050 new DialogInterface.OnClickListener() {
Walter Janged8f6c92015-01-30 16:07:47 -080051 @Override
52 public void onClick(DialogInterface dialogInterface, int which) {
53 final Listener targetListener = (Listener) getTargetFragment();
54 targetListener.onCancelEditConfirmed();
55 }
56 }
57 )
Walter Jangd1cc5fe2016-01-25 15:44:01 -080058 .setNegativeButton(R.string.cancel_confirmation_dialog_keep_editing_button, null)
Walter Janged8f6c92015-01-30 16:07:47 -080059 .create();
60 }
61
62 /**
63 * Callbacks for {@link CancelEditDialogFragment} hosts.
64 */
65 public interface Listener {
66
67 /**
68 * Invoked when the user confirms that they want to cancel editing the contact.
69 */
70 void onCancelEditConfirmed();
71 }
Walter Jang7b0970f2016-09-01 10:40:19 -070072}