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 package com.android.contacts.interactions; 17 18 import android.app.Activity; 19 import android.app.FragmentManager; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.widget.EditText; 23 24 import com.android.contacts.ContactSaveService; 25 import com.android.contacts.R; 26 import com.android.contacts.activities.ContactEditorBaseActivity; 27 import com.android.contacts.common.model.account.AccountWithDataSet; 28 29 /** 30 * A dialog for creating a new group. 31 */ 32 public class GroupCreationDialogFragment extends GroupNameDialogFragment { 33 private static final String ARG_ACCOUNT_TYPE = "accountType"; 34 private static final String ARG_ACCOUNT_NAME = "accountName"; 35 private static final String ARG_DATA_SET = "dataSet"; 36 37 public static final String FRAGMENT_TAG = "createGroupDialog"; 38 39 private final OnGroupCreatedListener mListener; 40 41 public interface OnGroupCreatedListener { 42 public void onGroupCreated(); 43 } 44 45 public static void show( 46 FragmentManager fragmentManager, String accountType, String accountName, 47 String dataSet, OnGroupCreatedListener listener) { 48 GroupCreationDialogFragment dialog = new GroupCreationDialogFragment(listener); 49 Bundle args = new Bundle(); 50 args.putString(ARG_ACCOUNT_TYPE, accountType); 51 args.putString(ARG_ACCOUNT_NAME, accountName); 52 args.putString(ARG_DATA_SET, dataSet); 53 dialog.setArguments(args); 54 dialog.show(fragmentManager, FRAGMENT_TAG); 55 } 56 57 public GroupCreationDialogFragment() { 58 super(); 59 mListener = null; 60 } 61 62 private GroupCreationDialogFragment(OnGroupCreatedListener listener) { 63 super(); 64 mListener = listener; 65 } 66 67 public OnGroupCreatedListener getOnGroupCreatedListener() { 68 return mListener; 69 } 70 71 @Override 72 protected void initializeGroupLabelEditText(EditText editText) { 73 } 74 75 @Override 76 protected int getTitleResourceId() { 77 return R.string.create_group_dialog_title; 78 } 79 80 @Override 81 protected void onCompleted(String groupLabel) { 82 Bundle arguments = getArguments(); 83 String accountType = arguments.getString(ARG_ACCOUNT_TYPE); 84 String accountName = arguments.getString(ARG_ACCOUNT_NAME); 85 String dataSet = arguments.getString(ARG_DATA_SET); 86 87 // Indicate to the listener that a new group will be created. 88 // If the device is rotated, mListener will become null, so that the 89 // popup from GroupMembershipView will not be shown. 90 if (mListener != null) { 91 mListener.onGroupCreated(); 92 } 93 94 Activity activity = getActivity(); 95 activity.startService(ContactSaveService.createNewGroupIntent(activity, 96 new AccountWithDataSet(accountName, accountType, dataSet), groupLabel, 97 null /* no new members to add */, 98 activity.getClass(), ContactEditorBaseActivity.ACTION_EDIT)); 99 } 100 } 101