1/*
2 * Copyright (C) 2010 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 android.app.AlertDialog;
20import android.app.Dialog;
21import android.app.DialogFragment;
22import android.app.Fragment;
23import android.content.DialogInterface;
24import android.os.Bundle;
25
26import com.android.contacts.R;
27
28/**
29 * Shows a dialog asking the user whether to split the contact. The result is passed back
30 * to the Fragment that is configured by {@link Fragment#setTargetFragment(Fragment, int)}, which
31 * has to implement {@link SplitContactConfirmationDialogFragment.Listener}.
32 * Does not split the contact itself.
33 */
34public class SplitContactConfirmationDialogFragment extends DialogFragment {
35    public static final String TAG = "SplitContactConfirmationDialog";
36
37    public static void show(ContactEditorBaseFragment fragment) {
38        SplitContactConfirmationDialogFragment dialog = new
39                SplitContactConfirmationDialogFragment();
40        dialog.setTargetFragment(fragment, 0);
41        dialog.show(fragment.getFragmentManager(), "splitContact");
42    }
43
44    @Override
45    public Dialog onCreateDialog(Bundle savedInstanceState) {
46        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
47        builder.setTitle(R.string.splitConfirmation_title);
48        builder.setIconAttribute(android.R.attr.alertDialogIcon);
49        builder.setMessage(R.string.splitConfirmation);
50        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
51            @Override
52            public void onClick(DialogInterface dialog, int which) {
53                final Listener targetListener = (Listener) getTargetFragment();
54                targetListener.onSplitContactConfirmed();
55            }
56        });
57        builder.setNegativeButton(android.R.string.cancel, null);
58        builder.setCancelable(false);
59        return builder.create();
60    }
61
62    public interface Listener {
63        void onSplitContactConfirmed();
64    }
65}
66