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