1 /*
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 
17 package com.android.contacts.editor;
18 
19 import com.android.contacts.R;
20 
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.app.DialogFragment;
24 import android.content.DialogInterface;
25 import android.net.Uri;
26 import android.os.Bundle;
27 
28 public class SuggestionEditConfirmationDialogFragment extends DialogFragment {
29 
30     private static final String ARG_CONTACT_URI = "contactUri";
31 
show(ContactEditorBaseFragment fragment, Uri contactUri)32     public static void show(ContactEditorBaseFragment fragment, Uri contactUri) {
33         final Bundle args = new Bundle();
34         args.putParcelable(ARG_CONTACT_URI, contactUri);
35 
36         final SuggestionEditConfirmationDialogFragment dialog = new
37                 SuggestionEditConfirmationDialogFragment();
38         dialog.setArguments(args);
39         dialog.setTargetFragment(fragment, 0);
40         dialog.show(fragment.getFragmentManager(), "edit");
41     }
42 
43     @Override
onCreateDialog(Bundle savedInstanceState)44     public Dialog onCreateDialog(Bundle savedInstanceState) {
45         return new AlertDialog.Builder(getActivity())
46                 .setIconAttribute(android.R.attr.alertDialogIcon)
47                 .setMessage(R.string.aggregation_suggestion_edit_dialog_message)
48                 .setPositiveButton(android.R.string.yes,
49                         new DialogInterface.OnClickListener() {
50                             @Override
51                             public void onClick(DialogInterface dialog, int whichButton) {
52                                 final ContactEditorBaseFragment targetFragment =
53                                         (ContactEditorBaseFragment) getTargetFragment();
54                                 final Uri contactUri =
55                                         getArguments().getParcelable(ARG_CONTACT_URI);
56                                 targetFragment.doEditSuggestedContact(contactUri);
57                             }
58                         }
59                 )
60                 .setNegativeButton(android.R.string.no, null)
61                 .create();
62     }
63 }
64