GroupDeletionDialogFragment.java revision 84a21cc711742f34f19978b2e02cba5f1743e9a5
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 */
16package com.android.contacts.interactions;
17
18import android.app.AlertDialog;
19import android.app.Dialog;
20import android.app.DialogFragment;
21import android.app.FragmentManager;
22import android.content.DialogInterface;
23import android.os.Bundle;
24
25import com.android.contacts.ContactSaveService;
26import com.android.contacts.R;
27import com.android.contacts.activities.PeopleActivity;
28
29/**
30 * A dialog for deleting a group.
31 */
32public class GroupDeletionDialogFragment extends DialogFragment {
33
34    private static final String ARG_GROUP_ID = "groupId";
35    private static final String ARG_LABEL = "label";
36
37    public static void show(FragmentManager fragmentManager, long groupId, String label) {
38        GroupDeletionDialogFragment dialog = new GroupDeletionDialogFragment();
39        Bundle args = new Bundle();
40        args.putLong(ARG_GROUP_ID, groupId);
41        args.putString(ARG_LABEL, label);
42        dialog.setArguments(args);
43        dialog.show(fragmentManager, "deleteGroup");
44    }
45
46    @Override
47    public Dialog onCreateDialog(Bundle savedInstanceState) {
48        String label = getArguments().getString(ARG_LABEL);
49        String message = getActivity().getString(R.string.delete_group_dialog_message, label);
50
51        return new AlertDialog.Builder(getActivity())
52                .setIconAttribute(android.R.attr.alertDialogIcon)
53                .setMessage(message)
54                .setPositiveButton(android.R.string.ok,
55                    new DialogInterface.OnClickListener() {
56                        @Override
57                        public void onClick(DialogInterface dialog, int whichButton) {
58                            deleteGroup();
59                        }
60                    }
61                )
62                .setNegativeButton(android.R.string.cancel, null)
63                .create();
64    }
65
66    protected void deleteGroup() {
67        final long groupId = getArguments().getLong(ARG_GROUP_ID);
68        final PeopleActivity activity = ((PeopleActivity) getActivity());
69        activity.startService(ContactSaveService.createGroupDeletionIntent(
70                getActivity(), groupId));
71        activity.switchToAllContacts();
72    }
73}
74