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 SplitContactConfirmationDialogFragment() {
38    }
39
40    @Override
41    public Dialog onCreateDialog(Bundle savedInstanceState) {
42        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
43        builder.setTitle(R.string.splitConfirmation_title);
44        builder.setIconAttribute(android.R.attr.alertDialogIcon);
45        builder.setMessage(R.string.splitConfirmation);
46        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
47            @Override
48            public void onClick(DialogInterface dialog, int which) {
49                final Listener targetListener = (Listener) getTargetFragment();
50                targetListener.onSplitContactConfirmed();
51            }
52        });
53        builder.setNegativeButton(android.R.string.cancel, null);
54        builder.setCancelable(false);
55        return builder.create();
56    }
57
58    public interface Listener {
59        void onSplitContactConfirmed();
60    }
61}
62