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 com.android.contacts.ContactSaveService;
19import com.android.contacts.R;
20import com.android.contacts.model.AccountWithDataSet;
21
22import android.app.Activity;
23import android.app.FragmentManager;
24import android.content.Intent;
25import android.os.Bundle;
26import android.widget.EditText;
27
28/**
29 * A dialog for creating a new group.
30 */
31public class GroupCreationDialogFragment extends GroupNameDialogFragment {
32    private static final String ARG_ACCOUNT_TYPE = "accountType";
33    private static final String ARG_ACCOUNT_NAME = "accountName";
34    private static final String ARG_DATA_SET = "dataSet";
35
36    public static void show(
37            FragmentManager fragmentManager, String accountType, String accountName,
38            String dataSet) {
39        GroupCreationDialogFragment dialog = new GroupCreationDialogFragment();
40        Bundle args = new Bundle();
41        args.putString(ARG_ACCOUNT_TYPE, accountType);
42        args.putString(ARG_ACCOUNT_NAME, accountName);
43        args.putString(ARG_DATA_SET, dataSet);
44        dialog.setArguments(args);
45        dialog.show(fragmentManager, "createGroup");
46    }
47
48    @Override
49    protected void initializeGroupLabelEditText(EditText editText) {
50    }
51
52    @Override
53    protected int getTitleResourceId() {
54        return R.string.create_group_dialog_title;
55    }
56
57    @Override
58    protected void onCompleted(String groupLabel) {
59        Bundle arguments = getArguments();
60        String accountType = arguments.getString(ARG_ACCOUNT_TYPE);
61        String accountName = arguments.getString(ARG_ACCOUNT_NAME);
62        String dataSet = arguments.getString(ARG_DATA_SET);
63
64        Activity activity = getActivity();
65        activity.startService(ContactSaveService.createNewGroupIntent(activity,
66                new AccountWithDataSet(accountName, accountType, dataSet), groupLabel,
67                null /* no new members to add */,
68                activity.getClass(), Intent.ACTION_EDIT));
69    }
70}
71