Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 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 com.android.contacts.R; |
| 19 | import com.android.contacts.views.ContactSaveService; |
| 20 | |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 21 | import android.app.FragmentManager; |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 22 | import android.os.Bundle; |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 23 | import android.widget.EditText; |
| 24 | |
| 25 | /** |
| 26 | * A dialog for renaming a group. |
| 27 | */ |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 28 | public class GroupRenamingDialogFragment extends GroupNameDialogFragment { |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 29 | |
| 30 | private static final String ARG_GROUP_ID = "groupId"; |
| 31 | private static final String ARG_LABEL = "label"; |
| 32 | |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 33 | public static void show(FragmentManager fragmentManager, long groupId, String label) { |
| 34 | GroupRenamingDialogFragment dialog = new GroupRenamingDialogFragment(); |
| 35 | Bundle args = new Bundle(); |
| 36 | args.putLong(ARG_GROUP_ID, groupId); |
| 37 | args.putString(ARG_LABEL, label); |
| 38 | dialog.setArguments(args); |
| 39 | dialog.show(fragmentManager, "renameGroup"); |
| 40 | } |
| 41 | |
| 42 | @Override |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 43 | protected void initializeGroupLabelEditText(EditText editText) { |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 44 | String label = getArguments().getString(ARG_LABEL); |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 45 | editText.setText(label); |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 46 | if (label != null) { |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 47 | editText.setSelection(label.length()); |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 48 | } |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 51 | @Override |
| 52 | protected int getTitleResourceId() { |
| 53 | return R.string.rename_group_dialog_title; |
| 54 | } |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 55 | |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 56 | @Override |
| 57 | protected void onCompleted(String groupLabel) { |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 58 | Bundle arguments = getArguments(); |
| 59 | long groupId = arguments.getLong(ARG_GROUP_ID); |
| 60 | |
| 61 | getActivity().startService(ContactSaveService.createGroupRenameIntent( |
Dmitri Plotnikov | 1ac58b6 | 2010-11-19 16:12:09 -0800 | [diff] [blame] | 62 | getActivity(), groupId, groupLabel)); |
Dmitri Plotnikov | e898a9f | 2010-11-18 16:58:25 -0800 | [diff] [blame] | 63 | } |
| 64 | } |