The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1 | /* |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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 | |
Dmitri Plotnikov | 27834b2 | 2010-07-01 14:10:08 -0700 | [diff] [blame] | 17 | package com.android.contacts.activities; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 18 | |
Dmitri Plotnikov | 27834b2 | 2010-07-01 14:10:08 -0700 | [diff] [blame] | 19 | import com.android.contacts.R; |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 20 | import com.android.contacts.interactions.ContactDeletionInteraction; |
Dmitri Plotnikov | aa1dffe | 2010-07-01 13:46:17 -0700 | [diff] [blame] | 21 | import com.android.contacts.interactions.ImportExportInteraction; |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 22 | import com.android.contacts.interactions.PhoneNumberInteraction; |
Dmitri Plotnikov | 416b569 | 2010-04-27 18:14:58 -0700 | [diff] [blame] | 23 | import com.android.contacts.list.ContactBrowseListContextMenuAdapter; |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 24 | import com.android.contacts.list.ContactBrowseListFragment; |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 25 | import com.android.contacts.list.ContactEntryListFragment; |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 26 | import com.android.contacts.list.ContactListFilter; |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 27 | import com.android.contacts.list.ContactListFilterController; |
Dmitri Plotnikov | 0906ee3 | 2010-04-22 10:46:00 -0700 | [diff] [blame] | 28 | import com.android.contacts.list.ContactsIntentResolver; |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 29 | import com.android.contacts.list.ContactsRequest; |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 30 | import com.android.contacts.list.CustomContactListFilterActivity; |
Dmitri Plotnikov | 238d984 | 2010-05-04 14:14:57 -0700 | [diff] [blame] | 31 | import com.android.contacts.list.DefaultContactBrowseListFragment; |
Dmitri Plotnikov | 4d174aa | 2010-10-25 15:38:54 -0700 | [diff] [blame] | 32 | import com.android.contacts.list.DirectoryListLoader; |
Dmitri Plotnikov | 732f652 | 2010-04-27 10:30:59 -0700 | [diff] [blame] | 33 | import com.android.contacts.list.OnContactBrowserActionListener; |
Dmitri Plotnikov | 238d984 | 2010-05-04 14:14:57 -0700 | [diff] [blame] | 34 | import com.android.contacts.list.StrequentContactListFragment; |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 35 | import com.android.contacts.model.AccountTypes; |
Dmitri Plotnikov | c85ad18 | 2010-09-17 18:12:49 -0700 | [diff] [blame] | 36 | import com.android.contacts.preference.ContactsPreferenceActivity; |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 37 | import com.android.contacts.util.AccountsListAdapter; |
Daniel Lehmann | 3391dbe | 2010-07-12 09:50:22 -0700 | [diff] [blame] | 38 | import com.android.contacts.util.DialogManager; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 39 | import com.android.contacts.views.ContactSaveService; |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 40 | import com.android.contacts.views.detail.ContactDetailFragment; |
Dmitri Plotnikov | 1323d69 | 2010-04-27 14:54:27 -0700 | [diff] [blame] | 41 | import com.android.contacts.widget.ContextMenuAdapter; |
Tadashi G. Takaoka | 57cf30f | 2009-09-21 19:54:39 +0900 | [diff] [blame] | 42 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 43 | import android.accounts.Account; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 44 | import android.app.Activity; |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 45 | import android.app.Dialog; |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 46 | import android.app.Fragment; |
Daniel Lehmann | 60be1a1 | 2010-08-05 18:37:21 -0700 | [diff] [blame] | 47 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 48 | import android.content.ContentValues; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 49 | import android.content.Intent; |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 50 | import android.content.SharedPreferences; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 51 | import android.net.Uri; |
| 52 | import android.os.Bundle; |
Dmitri Plotnikov | a6c2198 | 2010-10-27 10:21:16 -0700 | [diff] [blame] | 53 | import android.os.Handler; |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 54 | import android.os.Message; |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 55 | import android.preference.PreferenceManager; |
Dmitri Plotnikov | d7c4af2 | 2009-06-19 18:31:00 -0700 | [diff] [blame] | 56 | import android.provider.ContactsContract; |
Jeff Hamilton | e052966 | 2009-08-21 02:43:47 -0500 | [diff] [blame] | 57 | import android.provider.ContactsContract.Contacts; |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 58 | import android.provider.ContactsContract.Intents; |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 59 | import android.provider.Settings; |
Daniel Lehmann | a35a7e2 | 2010-08-03 18:13:14 -0700 | [diff] [blame] | 60 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 61 | import android.view.KeyEvent; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 62 | import android.view.Menu; |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 63 | import android.view.MenuInflater; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 64 | import android.view.MenuItem; |
| 65 | import android.view.View; |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 66 | import android.view.View.OnClickListener; |
Dmitri Plotnikov | 4af3b07 | 2010-07-01 18:40:51 -0700 | [diff] [blame] | 67 | import android.view.Window; |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 68 | import android.widget.AdapterView; |
| 69 | import android.widget.AdapterView.OnItemClickListener; |
| 70 | import android.widget.ImageView; |
| 71 | import android.widget.ListPopupWindow; |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 72 | import android.widget.Toast; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 73 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
| 75 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 76 | /** |
Daniel Lehmann | bd772a5 | 2010-07-14 11:22:13 -0700 | [diff] [blame] | 77 | * Displays a list to browse contacts. For xlarge screens, this also displays a detail-pane on |
| 78 | * the right |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 79 | */ |
Dmitri Plotnikov | cfa3900 | 2010-07-09 18:05:17 -0700 | [diff] [blame] | 80 | public class ContactBrowserActivity extends Activity |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 81 | implements View.OnCreateContextMenuListener, ActionBarAdapter.Listener, |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 82 | DialogManager.DialogShowingViewActivity, |
| 83 | ContactListFilterController.ContactListFilterListener { |
Dmitri Plotnikov | 57d27da | 2009-09-28 18:06:11 -0700 | [diff] [blame] | 84 | |
Daniel Lehmann | bd772a5 | 2010-07-14 11:22:13 -0700 | [diff] [blame] | 85 | private static final String TAG = "ContactBrowserActivity"; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 86 | |
Daniel Lehmann | 22fb205 | 2010-07-27 19:59:21 -0700 | [diff] [blame] | 87 | private static final int SUBACTIVITY_NEW_CONTACT = 2; |
Dmitri Plotnikov | c85ad18 | 2010-09-17 18:12:49 -0700 | [diff] [blame] | 88 | private static final int SUBACTIVITY_SETTINGS = 3; |
Dmitri Plotnikov | 8c6955f | 2010-09-08 20:46:36 -0700 | [diff] [blame] | 89 | private static final int SUBACTIVITY_EDIT_CONTACT = 4; |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 90 | private static final int SUBACTIVITY_CUSTOMIZE_FILTER = 5; |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 91 | |
Dmitri Plotnikov | 6183540 | 2010-09-27 18:29:02 -0700 | [diff] [blame] | 92 | private static final int DEFAULT_DIRECTORY_RESULT_LIMIT = 20; |
| 93 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 94 | /** |
| 95 | * The id for a delayed message that triggers automatic selection of the first |
| 96 | * found contact in search mode. |
| 97 | */ |
| 98 | private static final int MESSAGE_AUTOSELECT_FIRST_FOUND_CONTACT = 1; |
| 99 | |
| 100 | /** |
| 101 | * The delay that is used for automatically selecting the first found contact. |
| 102 | */ |
| 103 | private static final int DELAY_AUTOSELECT_FIRST_FOUND_CONTACT_MILLIS = 500; |
| 104 | |
| 105 | /** |
| 106 | * The minimum number of characters in the search query that is required |
| 107 | * before we automatically select the first found contact. |
| 108 | */ |
| 109 | private static final int AUTOSELECT_FIRST_FOUND_CONTACT_MIN_QUERY_LENGTH = 2; |
| 110 | |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 111 | private static final String KEY_SEARCH_MODE = "searchMode"; |
| 112 | |
Daniel Lehmann | 3b7d594 | 2010-07-22 18:10:50 -0700 | [diff] [blame] | 113 | private DialogManager mDialogManager = new DialogManager(this); |
Daniel Lehmann | 3391dbe | 2010-07-12 09:50:22 -0700 | [diff] [blame] | 114 | |
Dmitri Plotnikov | ac0f783 | 2010-04-22 13:26:52 -0700 | [diff] [blame] | 115 | private ContactsIntentResolver mIntentResolver; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 116 | private ContactsRequest mRequest; |
| 117 | |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 118 | private SharedPreferences mPrefs; |
| 119 | |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 120 | private boolean mHasActionBar; |
| 121 | private ActionBarAdapter mActionBarAdapter; |
| 122 | |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 123 | private boolean mSearchMode; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 124 | |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 125 | private ContactBrowseListFragment mListFragment; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 126 | private boolean mContactContentDisplayed; |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 127 | private ContactDetailFragment mDetailFragment; |
| 128 | private DetailFragmentListener mDetailFragmentListener = new DetailFragmentListener(); |
| 129 | |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 130 | private PhoneNumberInteraction mPhoneNumberCallInteraction; |
| 131 | private PhoneNumberInteraction mSendTextMessageInteraction; |
| 132 | private ContactDeletionInteraction mContactDeletionInteraction; |
| 133 | private ImportExportInteraction mImportExportInteraction; |
| 134 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 135 | private boolean mSearchInitiated; |
| 136 | |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 137 | private ContactListFilterController mContactListFilterController; |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 138 | |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 139 | private ImageView mAddContactImageView; |
| 140 | |
Dmitri Plotnikov | a6c2198 | 2010-10-27 10:21:16 -0700 | [diff] [blame] | 141 | private Handler mHandler; |
| 142 | |
Dmitri Plotnikov | cfa3900 | 2010-07-09 18:05:17 -0700 | [diff] [blame] | 143 | public ContactBrowserActivity() { |
Dmitri Plotnikov | 1540674 | 2010-05-07 09:22:49 -0700 | [diff] [blame] | 144 | mIntentResolver = new ContactsIntentResolver(this); |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 145 | mContactListFilterController = new ContactListFilterController(this); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 146 | mContactListFilterController.addListener(this); |
Dmitri Plotnikov | 6178cb4 | 2010-04-20 11:26:05 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 149 | private Handler getHandler() { |
| 150 | if (mHandler == null) { |
| 151 | mHandler = new Handler() { |
| 152 | @Override |
| 153 | public void handleMessage(Message msg) { |
| 154 | if (msg.what == MESSAGE_AUTOSELECT_FIRST_FOUND_CONTACT) { |
| 155 | selectFirstFoundContact(); |
| 156 | } |
| 157 | } |
| 158 | }; |
| 159 | } |
| 160 | return mHandler; |
| 161 | } |
| 162 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 163 | @Override |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 164 | public void onAttachFragment(Fragment fragment) { |
| 165 | if (fragment instanceof ContactBrowseListFragment) { |
| 166 | mListFragment = (ContactBrowseListFragment)fragment; |
| 167 | mListFragment.setOnContactListActionListener(new ContactBrowserActionListener()); |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 168 | restoreListSelection(); |
Dmitri Plotnikov | d364314 | 2010-07-09 13:49:07 -0700 | [diff] [blame] | 169 | } else if (fragment instanceof ContactDetailFragment) { |
| 170 | mDetailFragment = (ContactDetailFragment)fragment; |
| 171 | mDetailFragment.setListener(mDetailFragmentListener); |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
| 175 | @Override |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 176 | protected void onCreate(Bundle savedState) { |
| 177 | super.onCreate(savedState); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 178 | |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 179 | if (savedState != null) { |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 180 | mSearchMode = savedState.getBoolean(KEY_SEARCH_MODE); |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 183 | // Extract relevant information from the intent |
| 184 | mRequest = mIntentResolver.resolveIntent(getIntent()); |
| 185 | if (!mRequest.isValid()) { |
| 186 | setResult(RESULT_CANCELED); |
| 187 | finish(); |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 191 | Intent redirect = mRequest.getRedirectIntent(); |
| 192 | if (redirect != null) { |
| 193 | // Need to start a different activity |
| 194 | startActivity(redirect); |
| 195 | finish(); |
| 196 | return; |
| 197 | } |
| 198 | |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 199 | mPrefs = PreferenceManager.getDefaultSharedPreferences(this); |
| 200 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 201 | setTitle(mRequest.getActivityTitle()); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 202 | setContentView(R.layout.contact_browser); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 203 | |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 204 | mHasActionBar = getWindow().hasFeature(Window.FEATURE_ACTION_BAR); |
Dmitri Plotnikov | 65ad5ee | 2010-07-15 18:09:21 -0700 | [diff] [blame] | 205 | mContactContentDisplayed = findViewById(R.id.detail_container) != null; |
| 206 | |
Dmitri Plotnikov | 27b97bc | 2010-10-07 18:06:09 -0700 | [diff] [blame] | 207 | if (mRequest.getActionCode() == ContactsRequest.ACTION_VIEW_CONTACT) { |
Dmitri Plotnikov | 27b97bc | 2010-10-07 18:06:09 -0700 | [diff] [blame] | 208 | if (!mContactContentDisplayed) { |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 209 | startActivity(new Intent(Intent.ACTION_VIEW, mRequest.getContactUri())); |
Dmitri Plotnikov | 27b97bc | 2010-10-07 18:06:09 -0700 | [diff] [blame] | 210 | finish(); |
| 211 | return; |
| 212 | } |
| 213 | } |
| 214 | |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 215 | if (mHasActionBar) { |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 216 | mActionBarAdapter = new ActionBarAdapter(this); |
Dmitri Plotnikov | 1a59cff | 2010-09-18 12:50:45 -0700 | [diff] [blame] | 217 | mActionBarAdapter.onCreate(savedState, mRequest, getActionBar()); |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 218 | mActionBarAdapter.setContactListFilterController(mContactListFilterController); |
| 219 | // TODO: request may ask for FREQUENT - set the filter accordingly |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 220 | mAddContactImageView = new ImageView(this); |
| 221 | mAddContactImageView.setImageResource(R.drawable.ic_menu_add_contact); |
| 222 | mAddContactImageView.setContentDescription(getString(R.string.menu_newContact)); |
| 223 | mAddContactImageView.setOnClickListener(new OnClickListener() { |
| 224 | @Override |
| 225 | public void onClick(View v) { |
| 226 | createNewContact(); |
| 227 | } |
| 228 | }); |
Dmitri Plotnikov | fe42e55 | 2010-05-14 14:50:32 -0700 | [diff] [blame] | 229 | } |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 230 | |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 231 | configureListFragment(true /* from request */); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 232 | |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 233 | if (mContactContentDisplayed) { |
| 234 | setupContactDetailFragment(mListFragment.getSelectedContactUri()); |
| 235 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 238 | @Override |
| 239 | protected void onNewIntent(Intent intent) { |
| 240 | super.onNewIntent(intent); |
| 241 | if (Intent.ACTION_VIEW.equals(intent.getAction())) { |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 242 | mRequest = mIntentResolver.resolveIntent(getIntent()); |
| 243 | |
| 244 | Uri uri = mRequest.getContactUri(); |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 245 | if (uri == null) { |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | if (mHasActionBar) { |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 250 | mActionBarAdapter.setSearchMode(false); |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 251 | } |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 252 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 253 | mListFragment.setSelectedContactUri(uri); |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 254 | mListFragment.requestSelectionOnScreen(true); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 255 | if (mContactContentDisplayed) { |
| 256 | setupContactDetailFragment(uri); |
| 257 | } |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 261 | @Override |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 262 | protected void onPause() { |
| 263 | if (mActionBarAdapter != null) { |
| 264 | mActionBarAdapter.setListener(null); |
| 265 | } |
| 266 | super.onPause(); |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | protected void onResume() { |
| 271 | super.onResume(); |
| 272 | if (mActionBarAdapter != null) { |
| 273 | mActionBarAdapter.setListener(this); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | @Override |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 278 | protected void onStart() { |
| 279 | if (mContactListFilterController != null) { |
| 280 | mContactListFilterController.startLoading(); |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 281 | } |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 282 | super.onStart(); |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 285 | private void configureListFragment(boolean fromRequest) { |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 286 | boolean searchMode = mSearchMode; |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 287 | if (fromRequest) { |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 288 | ContactListFilter filter = null; |
| 289 | int actionCode = mRequest.getActionCode(); |
| 290 | switch (actionCode) { |
| 291 | case ContactsRequest.ACTION_ALL_CONTACTS: |
| 292 | filter = new ContactListFilter(ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS); |
| 293 | break; |
| 294 | case ContactsRequest.ACTION_CONTACTS_WITH_PHONES: |
| 295 | filter = new ContactListFilter( |
| 296 | ContactListFilter.FILTER_TYPE_WITH_PHONE_NUMBERS_ONLY); |
| 297 | break; |
| 298 | |
| 299 | // TODO: handle FREQUENT and STREQUENT according to the spec |
| 300 | case ContactsRequest.ACTION_FREQUENT: |
| 301 | case ContactsRequest.ACTION_STREQUENT: |
| 302 | // For now they are treated the same as STARRED |
| 303 | case ContactsRequest.ACTION_STARRED: |
| 304 | filter = new ContactListFilter(ContactListFilter.FILTER_TYPE_STARRED); |
| 305 | break; |
| 306 | } |
| 307 | |
| 308 | if (filter != null) { |
| 309 | mContactListFilterController.setContactListFilter(filter, false); |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 310 | searchMode = false; |
Dmitri Plotnikov | 48cc250 | 2010-10-08 14:56:04 -0700 | [diff] [blame] | 311 | } else if (mRequest.getActionCode() == ContactsRequest.ACTION_ALL_CONTACTS) { |
| 312 | mContactListFilterController.setContactListFilter(new ContactListFilter( |
| 313 | ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS), false); |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 314 | } |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 315 | } else { |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 316 | if (mHasActionBar) { |
| 317 | searchMode = mActionBarAdapter.isSearchMode(); |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 318 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 321 | boolean replaceList = mListFragment == null || (mSearchMode != searchMode); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 322 | if (replaceList) { |
| 323 | closeListFragment(); |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 324 | mSearchMode = searchMode; |
| 325 | if (mSearchMode) { |
| 326 | mListFragment = createContactSearchFragment(); |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 327 | // When switching to the search mode, erase previous state of the search UI |
| 328 | mListFragment.saveSelectedUri(mPrefs); |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 329 | } else { |
| 330 | mListFragment = createListFragment(ContactsRequest.ACTION_DEFAULT); |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 331 | mListFragment.requestSelectionOnScreen(false); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 335 | if (mHasActionBar && mSearchMode) { |
| 336 | mListFragment.setQueryString(mActionBarAdapter.getQueryString()); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 337 | } |
Dmitri Plotnikov | cfc6489 | 2010-07-09 17:55:09 -0700 | [diff] [blame] | 338 | |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 339 | if (fromRequest) { |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 340 | Uri selectUri = mRequest.getContactUri(); |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 341 | if (selectUri != null) { |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 342 | mListFragment.setSelectedContactUri(selectUri); |
| 343 | mListFragment.requestSelectionOnScreen(false); |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 347 | if (replaceList) { |
Daniel Lehmann | 3514fd3 | 2010-08-19 14:45:26 -0700 | [diff] [blame] | 348 | getFragmentManager().openTransaction() |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 349 | .replace(R.id.list_container, mListFragment) |
| 350 | .commit(); |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 351 | |
| 352 | if (mContactContentDisplayed) { |
| 353 | setupContactDetailFragment(mListFragment.getSelectedContactUri()); |
| 354 | } |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 355 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 358 | private void closeListFragment() { |
| 359 | if (mListFragment != null) { |
| 360 | mListFragment.setOnContactListActionListener(null); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 361 | mListFragment = null; |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 365 | @Override |
| 366 | public void onContactListFiltersLoaded() { |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 367 | restoreListSelection(); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 368 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 369 | // Filters have been loaded - now we can start loading the list itself |
| 370 | mListFragment.startLoading(); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public void onContactListFilterChanged() { |
| 375 | // If there was a request to show a specific contact, that's no longer the case |
| 376 | // because the user has explicitly changed the filter. |
| 377 | mRequest.setContactUri(null); |
| 378 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 379 | restoreListSelection(); |
| 380 | mListFragment.reloadData(); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 383 | /** |
| 384 | * Restores filter-specific persistent selection. |
| 385 | */ |
| 386 | private void restoreListSelection() { |
| 387 | if (mListFragment instanceof DefaultContactBrowseListFragment |
| 388 | && mContactListFilterController != null |
| 389 | && mContactListFilterController.isLoaded()) { |
| 390 | DefaultContactBrowseListFragment fragment = |
| 391 | (DefaultContactBrowseListFragment) mListFragment; |
| 392 | fragment.setFilter(mContactListFilterController.getFilter()); |
| 393 | fragment.restoreSelectedUri(mPrefs); |
| 394 | fragment.requestSelectionOnScreen(false); |
| 395 | } |
| 396 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 397 | if (mContactContentDisplayed) { |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 398 | setupContactDetailFragment(mListFragment.getSelectedContactUri()); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Dmitri Plotnikov | 3ad2f35 | 2010-10-28 22:37:51 -0700 | [diff] [blame] | 402 | private void showDefaultSelection() { |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 403 | if (mSearchMode) { |
| 404 | selectFirstFoundContactAfterDelay(); |
| 405 | return; |
| 406 | } |
| 407 | |
Dmitri Plotnikov | 3ad2f35 | 2010-10-28 22:37:51 -0700 | [diff] [blame] | 408 | Uri requestedContactUri = mRequest.getContactUri(); |
| 409 | if (requestedContactUri != null |
| 410 | && mListFragment instanceof DefaultContactBrowseListFragment) { |
| 411 | // If a specific selection was requested, adjust the filter so |
| 412 | // that the requested selection is unconditionally visible. |
| 413 | DefaultContactBrowseListFragment fragment = |
| 414 | (DefaultContactBrowseListFragment) mListFragment; |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 415 | ContactListFilter filter = |
| 416 | new ContactListFilter(ContactListFilter.FILTER_TYPE_SINGLE_CONTACT); |
Dmitri Plotnikov | 3ad2f35 | 2010-10-28 22:37:51 -0700 | [diff] [blame] | 417 | fragment.setFilter(filter); |
| 418 | fragment.setSelectedContactUri(requestedContactUri); |
| 419 | fragment.saveSelectedUri(mPrefs); |
| 420 | fragment.reloadData(); |
| 421 | if (mContactListFilterController != null) { |
| 422 | mContactListFilterController.setContactListFilter(filter, true); |
| 423 | } |
| 424 | } else { |
| 425 | // Otherwise, choose the first contact on the list and select it |
| 426 | requestedContactUri = mListFragment.getFirstContactUri(); |
| 427 | if (requestedContactUri != null) { |
| 428 | mListFragment.setSelectedContactUri(requestedContactUri); |
| 429 | mListFragment.requestSelectionOnScreen(false); |
| 430 | } |
| 431 | } |
| 432 | if (mContactContentDisplayed) { |
| 433 | setupContactDetailFragment(requestedContactUri); |
| 434 | } |
| 435 | } |
| 436 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 437 | /** |
| 438 | * Automatically selects the first found contact in search mode. The selection |
| 439 | * is updated after a delay to allow the user to type without to much UI churn |
| 440 | * and to save bandwidth on directory queries. |
| 441 | */ |
| 442 | public void selectFirstFoundContactAfterDelay() { |
| 443 | Handler handler = getHandler(); |
| 444 | handler.removeMessages(MESSAGE_AUTOSELECT_FIRST_FOUND_CONTACT); |
| 445 | handler.sendEmptyMessageDelayed(MESSAGE_AUTOSELECT_FIRST_FOUND_CONTACT, |
| 446 | DELAY_AUTOSELECT_FIRST_FOUND_CONTACT_MILLIS); |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Selects the first contact in the list in search mode. |
| 451 | */ |
| 452 | protected void selectFirstFoundContact() { |
| 453 | if (!mSearchMode) { |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | Uri selectedUri = null; |
| 458 | String queryString = mListFragment.getQueryString(); |
| 459 | if (queryString != null |
| 460 | && queryString.length() >= AUTOSELECT_FIRST_FOUND_CONTACT_MIN_QUERY_LENGTH) { |
| 461 | selectedUri = mListFragment.getFirstContactUri(); |
| 462 | } |
| 463 | |
| 464 | mListFragment.setSelectedContactUri(selectedUri); |
| 465 | if (mContactContentDisplayed) { |
| 466 | setupContactDetailFragment(selectedUri); |
| 467 | } |
| 468 | } |
| 469 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 470 | @Override |
| 471 | public void onContactListFilterCustomizationRequest() { |
| 472 | startActivityForResult(new Intent(this, CustomContactListFilterActivity.class), |
| 473 | SUBACTIVITY_CUSTOMIZE_FILTER); |
| 474 | } |
| 475 | |
Dmitri Plotnikov | a6c2198 | 2010-10-27 10:21:16 -0700 | [diff] [blame] | 476 | private void setupContactDetailFragment(final Uri contactLookupUri) { |
Dmitri Plotnikov | 9cd1708 | 2010-07-09 14:10:04 -0700 | [diff] [blame] | 477 | if (mDetailFragment != null && contactLookupUri != null |
| 478 | && contactLookupUri.equals(mDetailFragment.getUri())) { |
| 479 | return; |
| 480 | } |
| 481 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame^] | 482 | if (mDetailFragment == null) { |
| 483 | mDetailFragment = new ContactDetailFragment(); |
| 484 | getFragmentManager().openTransaction() |
| 485 | .replace(R.id.detail_container, mDetailFragment) |
| 486 | .commit(); |
Dmitri Plotnikov | c0ca13a | 2010-07-08 14:25:37 -0700 | [diff] [blame] | 487 | } |
Dmitri Plotnikov | c0ca13a | 2010-07-08 14:25:37 -0700 | [diff] [blame] | 488 | |
Dmitri Plotnikov | 3ad2f35 | 2010-10-28 22:37:51 -0700 | [diff] [blame] | 489 | mDetailFragment.loadUri(contactLookupUri); |
Dmitri Plotnikov | c0ca13a | 2010-07-08 14:25:37 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 492 | /** |
| 493 | * Handler for action bar actions. |
| 494 | */ |
Dmitri Plotnikov | fe42e55 | 2010-05-14 14:50:32 -0700 | [diff] [blame] | 495 | @Override |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 496 | public void onAction() { |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 497 | configureListFragment(false /* from request */); |
Dmitri Plotnikov | fe42e55 | 2010-05-14 14:50:32 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 500 | /** |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 501 | * Creates the list fragment for the specified mode. |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 502 | */ |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 503 | private ContactBrowseListFragment createListFragment(int actionCode) { |
| 504 | switch (actionCode) { |
Dmitri Plotnikov | b979b42 | 2010-07-01 15:29:15 -0700 | [diff] [blame] | 505 | case ContactsRequest.ACTION_DEFAULT: { |
Dmitri Plotnikov | 238d984 | 2010-05-04 14:14:57 -0700 | [diff] [blame] | 506 | DefaultContactBrowseListFragment fragment = new DefaultContactBrowseListFragment(); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 507 | fragment.setContactsRequest(mRequest); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 508 | fragment.setOnContactListActionListener(new ContactBrowserActionListener()); |
Dmitri Plotnikov | d94c3eb | 2010-10-08 13:41:12 -0700 | [diff] [blame] | 509 | if (!mHasActionBar) { |
| 510 | fragment.setContextMenuAdapter( |
| 511 | new ContactBrowseListContextMenuAdapter(fragment)); |
| 512 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 513 | fragment.setSearchMode(mRequest.isSearchMode()); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 514 | fragment.setQueryString(mRequest.getQueryString()); |
Dmitri Plotnikov | 4d174aa | 2010-10-25 15:38:54 -0700 | [diff] [blame] | 515 | if (mRequest.isSearchMode() && mRequest.isDirectorySearchEnabled()) { |
| 516 | fragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DEFAULT); |
| 517 | } else { |
| 518 | fragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_NONE); |
| 519 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 520 | fragment.setAizyEnabled(!mRequest.isSearchMode()); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 521 | fragment.setSelectionVisible(mContactContentDisplayed); |
Dmitri Plotnikov | 39709a6 | 2010-09-03 11:15:30 -0700 | [diff] [blame] | 522 | fragment.setQuickContactEnabled(!mContactContentDisplayed); |
Dmitri Plotnikov | 1799e6d | 2010-09-16 15:51:17 -0700 | [diff] [blame] | 523 | fragment.setFilterEnabled(!mRequest.isSearchMode()); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 524 | return fragment; |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 525 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 526 | |
| 527 | case ContactsRequest.ACTION_GROUP: { |
| 528 | throw new UnsupportedOperationException("Not yet implemented"); |
| 529 | } |
| 530 | |
| 531 | case ContactsRequest.ACTION_STARRED: { |
Dmitri Plotnikov | 238d984 | 2010-05-04 14:14:57 -0700 | [diff] [blame] | 532 | StrequentContactListFragment fragment = new StrequentContactListFragment(); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 533 | fragment.setOnContactListActionListener(new ContactBrowserActionListener()); |
| 534 | fragment.setFrequentlyContactedContactsIncluded(false); |
| 535 | fragment.setStarredContactsIncluded(true); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 536 | fragment.setSelectionVisible(mContactContentDisplayed); |
Dmitri Plotnikov | 39709a6 | 2010-09-03 11:15:30 -0700 | [diff] [blame] | 537 | fragment.setQuickContactEnabled(!mContactContentDisplayed); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 538 | return fragment; |
Dmitri Plotnikov | 238d984 | 2010-05-04 14:14:57 -0700 | [diff] [blame] | 539 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 540 | |
| 541 | case ContactsRequest.ACTION_FREQUENT: { |
| 542 | StrequentContactListFragment fragment = new StrequentContactListFragment(); |
| 543 | fragment.setOnContactListActionListener(new ContactBrowserActionListener()); |
| 544 | fragment.setFrequentlyContactedContactsIncluded(true); |
| 545 | fragment.setStarredContactsIncluded(false); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 546 | fragment.setSelectionVisible(mContactContentDisplayed); |
Dmitri Plotnikov | 39709a6 | 2010-09-03 11:15:30 -0700 | [diff] [blame] | 547 | fragment.setQuickContactEnabled(!mContactContentDisplayed); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 548 | return fragment; |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | case ContactsRequest.ACTION_STREQUENT: { |
| 552 | StrequentContactListFragment fragment = new StrequentContactListFragment(); |
| 553 | fragment.setOnContactListActionListener(new ContactBrowserActionListener()); |
| 554 | fragment.setFrequentlyContactedContactsIncluded(true); |
| 555 | fragment.setStarredContactsIncluded(true); |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 556 | fragment.setSelectionVisible(mContactContentDisplayed); |
Dmitri Plotnikov | 39709a6 | 2010-09-03 11:15:30 -0700 | [diff] [blame] | 557 | fragment.setQuickContactEnabled(!mContactContentDisplayed); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 558 | return fragment; |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 561 | default: |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 562 | throw new IllegalStateException("Invalid action code: " + actionCode); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 563 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | private ContactBrowseListFragment createContactSearchFragment() { |
| 567 | DefaultContactBrowseListFragment fragment = new DefaultContactBrowseListFragment(); |
| 568 | fragment.setOnContactListActionListener(new ContactBrowserActionListener()); |
Dmitri Plotnikov | d94c3eb | 2010-10-08 13:41:12 -0700 | [diff] [blame] | 569 | if (!mHasActionBar) { |
| 570 | fragment.setContextMenuAdapter(new ContactBrowseListContextMenuAdapter(fragment)); |
| 571 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 572 | fragment.setSearchMode(true); |
Dmitri Plotnikov | 4d174aa | 2010-10-25 15:38:54 -0700 | [diff] [blame] | 573 | fragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DEFAULT); |
Dmitri Plotnikov | 6183540 | 2010-09-27 18:29:02 -0700 | [diff] [blame] | 574 | fragment.setDirectoryResultLimit(DEFAULT_DIRECTORY_RESULT_LIMIT); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 575 | fragment.setAizyEnabled(false); |
Dmitri Plotnikov | 0d57749 | 2010-07-08 13:14:45 -0700 | [diff] [blame] | 576 | fragment.setSelectionVisible(true); |
Dmitri Plotnikov | 7321688 | 2010-09-10 18:31:34 -0700 | [diff] [blame] | 577 | fragment.setQuickContactEnabled(!mContactContentDisplayed); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 578 | return fragment; |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | private final class ContactBrowserActionListener implements OnContactBrowserActionListener { |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 582 | @Override |
| 583 | public void onViewContactAction(Uri contactLookupUri) { |
Dmitri Plotnikov | e1d4c06 | 2010-07-15 16:20:36 -0700 | [diff] [blame] | 584 | if (mContactContentDisplayed) { |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 585 | mListFragment.setSelectedContactUri(contactLookupUri); |
| 586 | mListFragment.saveSelectedUri(mPrefs); |
Dmitri Plotnikov | d364314 | 2010-07-09 13:49:07 -0700 | [diff] [blame] | 587 | setupContactDetailFragment(contactLookupUri); |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 588 | } else { |
| 589 | startActivity(new Intent(Intent.ACTION_VIEW, contactLookupUri)); |
| 590 | } |
Dmitri Plotnikov | 26cda1a | 2010-04-08 17:21:36 -0700 | [diff] [blame] | 591 | } |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 592 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 593 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 594 | public void onCreateNewContactAction() { |
| 595 | Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
| 596 | Bundle extras = getIntent().getExtras(); |
| 597 | if (extras != null) { |
| 598 | intent.putExtras(extras); |
| 599 | } |
| 600 | startActivity(intent); |
| 601 | } |
| 602 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 603 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 604 | public void onEditContactAction(Uri contactLookupUri) { |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 605 | Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri); |
| 606 | Bundle extras = getIntent().getExtras(); |
| 607 | if (extras != null) { |
| 608 | intent.putExtras(extras); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 609 | } |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 610 | startActivityForResult(intent, SUBACTIVITY_EDIT_CONTACT); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 613 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 614 | public void onAddToFavoritesAction(Uri contactUri) { |
| 615 | ContentValues values = new ContentValues(1); |
| 616 | values.put(Contacts.STARRED, 1); |
| 617 | getContentResolver().update(contactUri, values, null, null); |
| 618 | } |
| 619 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 620 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 621 | public void onRemoveFromFavoritesAction(Uri contactUri) { |
| 622 | ContentValues values = new ContentValues(1); |
| 623 | values.put(Contacts.STARRED, 0); |
| 624 | getContentResolver().update(contactUri, values, null, null); |
| 625 | } |
| 626 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 627 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 628 | public void onCallContactAction(Uri contactUri) { |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 629 | getPhoneNumberCallInteraction().startInteraction(contactUri); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 632 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 633 | public void onSmsContactAction(Uri contactUri) { |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 634 | getSendTextMessageInteraction().startInteraction(contactUri); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 637 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 638 | public void onDeleteContactAction(Uri contactUri) { |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 639 | getContactDeletionInteraction().deleteContact(contactUri); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Daniel Lehmann | e20d343 | 2010-10-10 18:37:51 -0700 | [diff] [blame] | 642 | @Override |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 643 | public void onFinishAction() { |
| 644 | onBackPressed(); |
| 645 | } |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 646 | |
| 647 | @Override |
| 648 | public void onInvalidSelection() { |
Dmitri Plotnikov | 3ad2f35 | 2010-10-28 22:37:51 -0700 | [diff] [blame] | 649 | showDefaultSelection(); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 650 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 653 | private class DetailFragmentListener implements ContactDetailFragment.Listener { |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 654 | @Override |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 655 | public void onContactNotFound() { |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 656 | setupContactDetailFragment(null); |
Dmitri Plotnikov | 3ad2f35 | 2010-10-28 22:37:51 -0700 | [diff] [blame] | 657 | mRequest.setContactUri(null); |
| 658 | showDefaultSelection(); |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 661 | @Override |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 662 | public void onEditRequested(Uri contactLookupUri) { |
Dmitri Plotnikov | 8c6955f | 2010-09-08 20:46:36 -0700 | [diff] [blame] | 663 | startActivityForResult( |
| 664 | new Intent(Intent.ACTION_EDIT, contactLookupUri), SUBACTIVITY_EDIT_CONTACT); |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 667 | @Override |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 668 | public void onItemClicked(Intent intent) { |
Daniel Lehmann | 60be1a1 | 2010-08-05 18:37:21 -0700 | [diff] [blame] | 669 | try { |
| 670 | startActivity(intent); |
| 671 | } catch (ActivityNotFoundException e) { |
| 672 | Log.e(TAG, "No activity found for intent: " + intent); |
| 673 | } |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Daniel Lehmann | 69e7fec | 2010-07-20 14:14:56 -0700 | [diff] [blame] | 676 | @Override |
| 677 | public void onDeleteRequested(Uri contactLookupUri) { |
| 678 | getContactDeletionInteraction().deleteContact(contactLookupUri); |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 679 | } |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 680 | |
| 681 | @Override |
| 682 | public void onCreateRawContactRequested(ArrayList<ContentValues> values, Account account) { |
| 683 | Toast.makeText(ContactBrowserActivity.this, R.string.toast_making_personal_copy, |
| 684 | Toast.LENGTH_LONG).show(); |
| 685 | Intent serviceIntent = ContactSaveService.createNewRawContactIntent( |
| 686 | ContactBrowserActivity.this, values, account); |
| 687 | startService(serviceIntent); |
| 688 | } |
Dmitri Plotnikov | 424440b | 2010-07-01 14:48:44 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Dmitri Plotnikov | 732f652 | 2010-04-27 10:30:59 -0700 | [diff] [blame] | 691 | public void startActivityAndForwardResult(final Intent intent) { |
| 692 | intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); |
| 693 | |
| 694 | // Forward extras to the new activity |
| 695 | Bundle extras = getIntent().getExtras(); |
| 696 | if (extras != null) { |
| 697 | intent.putExtras(extras); |
| 698 | } |
| 699 | startActivity(intent); |
| 700 | finish(); |
| 701 | } |
| 702 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 703 | @Override |
| 704 | public boolean onCreateOptionsMenu(Menu menu) { |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 705 | super.onCreateOptionsMenu(menu); |
| 706 | |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 707 | MenuInflater inflater = getMenuInflater(); |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 708 | if (mHasActionBar) { |
Dmitri Plotnikov | 4af3b07 | 2010-07-01 18:40:51 -0700 | [diff] [blame] | 709 | inflater.inflate(R.menu.actions, menu); |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 710 | |
| 711 | // Change add contact button to button with a custom view |
| 712 | final MenuItem addContact = menu.findItem(R.id.menu_add); |
| 713 | addContact.setActionView(mAddContactImageView); |
Dmitri Plotnikov | 4af3b07 | 2010-07-01 18:40:51 -0700 | [diff] [blame] | 714 | return true; |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 715 | } else if (mRequest.getActionCode() == ContactsRequest.ACTION_DEFAULT || |
| 716 | mRequest.getActionCode() == ContactsRequest.ACTION_STREQUENT) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 717 | inflater.inflate(R.menu.list, menu); |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 718 | return true; |
| 719 | } else if (!mListFragment.isSearchMode()) { |
| 720 | inflater.inflate(R.menu.search, menu); |
| 721 | return true; |
| 722 | } else { |
| 723 | return false; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 724 | } |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 725 | } |
Jeff Sharkey | 3f0b7b8 | 2009-08-12 11:28:53 -0700 | [diff] [blame] | 726 | |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 727 | @Override |
| 728 | public boolean onPrepareOptionsMenu(Menu menu) { |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 729 | MenuItem displayGroups = menu.findItem(R.id.menu_display_groups); |
| 730 | if (displayGroups != null) { |
| 731 | displayGroups.setVisible( |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 732 | mRequest.getActionCode() == ContactsRequest.ACTION_DEFAULT); |
Dmitri Plotnikov | 4af3b07 | 2010-07-01 18:40:51 -0700 | [diff] [blame] | 733 | } |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 734 | return true; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 735 | } |
| 736 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 737 | @Override |
| 738 | public boolean onOptionsItemSelected(MenuItem item) { |
| 739 | switch (item.getItemId()) { |
Dmitri Plotnikov | c85ad18 | 2010-09-17 18:12:49 -0700 | [diff] [blame] | 740 | case R.id.menu_settings: { |
| 741 | final Intent intent = new Intent(this, ContactsPreferenceActivity.class); |
| 742 | startActivityForResult(intent, SUBACTIVITY_SETTINGS); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 743 | return true; |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 744 | } |
| 745 | case R.id.menu_search: { |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 746 | onSearchRequested(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 747 | return true; |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 748 | } |
| 749 | case R.id.menu_add: { |
| 750 | final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
Daniel Lehmann | 22fb205 | 2010-07-27 19:59:21 -0700 | [diff] [blame] | 751 | startActivityForResult(intent, SUBACTIVITY_NEW_CONTACT); |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 752 | return true; |
| 753 | } |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 754 | case R.id.menu_import_export: { |
Dmitri Plotnikov | aa1dffe | 2010-07-01 13:46:17 -0700 | [diff] [blame] | 755 | getImportExportInteraction().startInteraction(); |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 756 | return true; |
| 757 | } |
| 758 | case R.id.menu_accounts: { |
| 759 | final Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS); |
Dmitri Plotnikov | fe42e55 | 2010-05-14 14:50:32 -0700 | [diff] [blame] | 760 | intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] { |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 761 | ContactsContract.AUTHORITY |
| 762 | }); |
| 763 | startActivity(intent); |
| 764 | return true; |
| 765 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 766 | } |
| 767 | return false; |
| 768 | } |
| 769 | |
Daniel Lehmann | 2013058 | 2010-10-21 20:51:15 -0700 | [diff] [blame] | 770 | private void createNewContact() { |
| 771 | final ArrayList<Account> accounts = |
| 772 | AccountTypes.getInstance(this).getAccounts(true); |
| 773 | if (accounts.size() <= 1 || mAddContactImageView == null) { |
| 774 | // No account to choose or no control to anchor the popup-menu to |
| 775 | // ==> just go straight to the editor which will disambig if necessary |
| 776 | final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
| 777 | startActivityForResult(intent, SUBACTIVITY_NEW_CONTACT); |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | final ListPopupWindow popup = new ListPopupWindow(this, null); |
| 782 | popup.setWidth(getResources().getDimensionPixelSize(R.dimen.account_selector_popup_width)); |
| 783 | popup.setAnchorView(mAddContactImageView); |
| 784 | final AccountsListAdapter adapter = new AccountsListAdapter(this, true); |
| 785 | popup.setAdapter(adapter); |
| 786 | popup.setOnItemClickListener(new OnItemClickListener() { |
| 787 | @Override |
| 788 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 789 | popup.dismiss(); |
| 790 | final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
| 791 | intent.putExtra(Intents.Insert.ACCOUNT, adapter.getItem(position)); |
| 792 | startActivityForResult(intent, SUBACTIVITY_NEW_CONTACT); |
| 793 | } |
| 794 | }); |
| 795 | popup.setModal(true); |
| 796 | popup.show(); |
| 797 | } |
| 798 | |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 799 | @Override |
| 800 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 801 | boolean globalSearch) { |
Dmitri Plotnikov | 12def9d | 2010-05-06 18:13:12 -0700 | [diff] [blame] | 802 | // TODO |
| 803 | // if (mProviderStatus != ProviderStatus.STATUS_NORMAL) { |
| 804 | // return; |
| 805 | // } |
Dmitri Plotnikov | 3b73d8b | 2010-03-12 19:28:21 -0800 | [diff] [blame] | 806 | |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 807 | if (globalSearch) { |
| 808 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 809 | } else { |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 810 | mListFragment.startSearch(initialQuery); |
Dmitri Plotnikov | db3d143 | 2010-02-09 17:45:47 -0800 | [diff] [blame] | 811 | } |
Dmitri Plotnikov | db3d143 | 2010-02-09 17:45:47 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 814 | @Override |
Dmitri Plotnikov | 3b73d8b | 2010-03-12 19:28:21 -0800 | [diff] [blame] | 815 | protected Dialog onCreateDialog(int id, Bundle bundle) { |
Daniel Lehmann | 3b7d594 | 2010-07-22 18:10:50 -0700 | [diff] [blame] | 816 | if (DialogManager.isManagedId(id)) return mDialogManager.onCreateDialog(id, bundle); |
Daniel Lehmann | 3391dbe | 2010-07-12 09:50:22 -0700 | [diff] [blame] | 817 | |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 818 | Dialog dialog = getContactDeletionInteraction().onCreateDialog(id, bundle); |
Daniel Lehmann | a35a7e2 | 2010-08-03 18:13:14 -0700 | [diff] [blame] | 819 | if (dialog != null) return dialog; |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 820 | |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 821 | dialog = getPhoneNumberCallInteraction().onCreateDialog(id, bundle); |
Daniel Lehmann | a35a7e2 | 2010-08-03 18:13:14 -0700 | [diff] [blame] | 822 | if (dialog != null) return dialog; |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 823 | |
| 824 | dialog = getSendTextMessageInteraction().onCreateDialog(id, bundle); |
Daniel Lehmann | a35a7e2 | 2010-08-03 18:13:14 -0700 | [diff] [blame] | 825 | if (dialog != null) return dialog; |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 826 | |
Dmitri Plotnikov | aa1dffe | 2010-07-01 13:46:17 -0700 | [diff] [blame] | 827 | dialog = getImportExportInteraction().onCreateDialog(id, bundle); |
Daniel Lehmann | a35a7e2 | 2010-08-03 18:13:14 -0700 | [diff] [blame] | 828 | if (dialog != null) return dialog; |
Dmitri Plotnikov | aa1dffe | 2010-07-01 13:46:17 -0700 | [diff] [blame] | 829 | |
Dmitri Plotnikov | 3b73d8b | 2010-03-12 19:28:21 -0800 | [diff] [blame] | 830 | return super.onCreateDialog(id, bundle); |
Jeff Sharkey | 49d17b3 | 2009-09-07 02:14:21 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 833 | @Override |
| 834 | protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) { |
| 835 | if (getContactDeletionInteraction().onPrepareDialog(id, dialog, bundle)) { |
| 836 | return; |
| 837 | } |
| 838 | |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 839 | if (getPhoneNumberCallInteraction().onPrepareDialog(id, dialog, bundle)) { |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | if (getSendTextMessageInteraction().onPrepareDialog(id, dialog, bundle)) { |
| 844 | return; |
| 845 | } |
| 846 | |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 847 | super.onPrepareDialog(id, dialog, bundle); |
| 848 | } |
Jeff Sharkey | d9798ae | 2009-08-24 20:46:23 -0700 | [diff] [blame] | 849 | |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 850 | @Override |
| 851 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 852 | switch (requestCode) { |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 853 | case SUBACTIVITY_CUSTOMIZE_FILTER: { |
| 854 | if (resultCode == Activity.RESULT_OK) { |
| 855 | mContactListFilterController.selectCustomFilter(); |
| 856 | } |
| 857 | break; |
| 858 | } |
Dmitri Plotnikov | 8c6955f | 2010-09-08 20:46:36 -0700 | [diff] [blame] | 859 | case SUBACTIVITY_EDIT_CONTACT: { |
Dmitri Plotnikov | 3c69e21 | 2010-09-27 11:43:39 -0700 | [diff] [blame] | 860 | mListFragment.requestSelectionOnScreen(true); |
Dmitri Plotnikov | 8c6955f | 2010-09-08 20:46:36 -0700 | [diff] [blame] | 861 | break; |
| 862 | } |
| 863 | |
Daniel Lehmann | 22fb205 | 2010-07-27 19:59:21 -0700 | [diff] [blame] | 864 | case SUBACTIVITY_NEW_CONTACT: { |
| 865 | if (resultCode == RESULT_OK && mContactContentDisplayed) { |
| 866 | final Uri newContactUri = data.getData(); |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 867 | if (mContactContentDisplayed) { |
| 868 | setupContactDetailFragment(newContactUri); |
| 869 | } |
| 870 | |
| 871 | mRequest.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT); |
| 872 | mRequest.setContactUri(newContactUri); |
| 873 | mListFragment.setSelectedContactUri(newContactUri); |
| 874 | mListFragment.saveSelectedUri(mPrefs); |
| 875 | mListFragment.requestSelectionOnScreen(true); |
Daniel Lehmann | 22fb205 | 2010-07-27 19:59:21 -0700 | [diff] [blame] | 876 | } |
| 877 | break; |
| 878 | } |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 879 | |
Dmitri Plotnikov | c85ad18 | 2010-09-17 18:12:49 -0700 | [diff] [blame] | 880 | case SUBACTIVITY_SETTINGS: |
Daniel Lehmann | 7aa9b28 | 2010-07-27 20:33:27 -0700 | [diff] [blame] | 881 | // TODO: Force the ListFragment to reload its setting and update (don't lookup |
| 882 | // directories here) |
| 883 | break; |
| 884 | |
| 885 | // TODO: Using the new startActivityWithResultFromFragment API this should not be needed |
| 886 | // anymore |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame] | 887 | case ContactEntryListFragment.ACTIVITY_REQUEST_CODE_PICKER: |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 888 | if (resultCode == RESULT_OK) { |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame] | 889 | mListFragment.onPickerResult(data); |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | // TODO fix or remove multipicker code |
| 893 | // else if (resultCode == RESULT_CANCELED && mMode == MODE_PICK_MULTIPLE_PHONES) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 894 | // // Finish the activity if the sub activity was canceled as back key is used |
| 895 | // // to confirm user selection in MODE_PICK_MULTIPLE_PHONES. |
| 896 | // finish(); |
| 897 | // } |
| 898 | // break; |
Dmitri Plotnikov | d3758b0 | 2010-06-17 11:34:59 -0700 | [diff] [blame] | 899 | } |
| 900 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 901 | |
| 902 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 903 | public boolean onContextItemSelected(MenuItem item) { |
Dmitri Plotnikov | 502741d | 2010-04-27 19:06:23 -0700 | [diff] [blame] | 904 | ContextMenuAdapter menuAdapter = mListFragment.getContextMenuAdapter(); |
| 905 | if (menuAdapter != null) { |
| 906 | return menuAdapter.onContextItemSelected(item); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | return super.onContextItemSelected(item); |
| 910 | } |
| 911 | |
| 912 | @Override |
| 913 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 914 | // TODO move to the fragment |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 915 | switch (keyCode) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 916 | // case KeyEvent.KEYCODE_CALL: { |
| 917 | // if (callSelection()) { |
| 918 | // return true; |
| 919 | // } |
| 920 | // break; |
| 921 | // } |
Dmitri Plotnikov | db3d143 | 2010-02-09 17:45:47 -0800 | [diff] [blame] | 922 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 923 | case KeyEvent.KEYCODE_DEL: { |
Dmitri Plotnikov | 6c776bc | 2010-03-10 10:12:31 -0800 | [diff] [blame] | 924 | if (deleteSelection()) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 925 | return true; |
| 926 | } |
| 927 | break; |
| 928 | } |
Daniel Lehmann | 7bb2add | 2010-07-14 21:15:17 -0700 | [diff] [blame] | 929 | default: { |
| 930 | // Bring up the search UI if the user starts typing |
| 931 | final int unicodeChar = event.getUnicodeChar(); |
| 932 | |
| 933 | if (unicodeChar != 0) { |
| 934 | String query = new String(new int[]{ unicodeChar }, 0, 1); |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 935 | if (mHasActionBar) { |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 936 | if (!mActionBarAdapter.isSearchMode()) { |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 937 | mActionBarAdapter.setQueryString(query); |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 938 | mActionBarAdapter.setSearchMode(true); |
Daniel Lehmann | 7bb2add | 2010-07-14 21:15:17 -0700 | [diff] [blame] | 939 | return true; |
| 940 | } |
| 941 | } else if (!mRequest.isSearchMode()) { |
| 942 | if (!mSearchInitiated) { |
| 943 | mSearchInitiated = true; |
| 944 | startSearch(query, false, null, false); |
| 945 | return true; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | return super.onKeyDown(keyCode, event); |
| 953 | } |
| 954 | |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 955 | @Override |
| 956 | public void onBackPressed() { |
| 957 | if (mSearchMode && mActionBarAdapter != null) { |
| 958 | mActionBarAdapter.setSearchMode(false); |
| 959 | } else { |
| 960 | super.onBackPressed(); |
| 961 | } |
| 962 | } |
| 963 | |
Dmitri Plotnikov | 6c776bc | 2010-03-10 10:12:31 -0800 | [diff] [blame] | 964 | private boolean deleteSelection() { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 965 | // TODO move to the fragment |
| 966 | // if (mActionCode == ContactsRequest.ACTION_DEFAULT) { |
| 967 | // final int position = mListView.getSelectedItemPosition(); |
| 968 | // if (position != ListView.INVALID_POSITION) { |
| 969 | // Uri contactUri = getContactUri(position); |
| 970 | // if (contactUri != null) { |
| 971 | // doContactDelete(contactUri); |
| 972 | // return true; |
| 973 | // } |
| 974 | // } |
| 975 | // } |
Dmitri Plotnikov | 6c776bc | 2010-03-10 10:12:31 -0800 | [diff] [blame] | 976 | return false; |
| 977 | } |
| 978 | |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 979 | @Override |
| 980 | protected void onSaveInstanceState(Bundle outState) { |
| 981 | super.onSaveInstanceState(outState); |
Dmitri Plotnikov | 15ccbb4 | 2010-10-05 17:29:07 -0700 | [diff] [blame] | 982 | outState.putBoolean(KEY_SEARCH_MODE, mSearchMode); |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 983 | if (mActionBarAdapter != null) { |
| 984 | mActionBarAdapter.onSaveInstanceState(outState); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 988 | private PhoneNumberInteraction getPhoneNumberCallInteraction() { |
| 989 | if (mPhoneNumberCallInteraction == null) { |
| 990 | mPhoneNumberCallInteraction = new PhoneNumberInteraction(this, false, null); |
Dmitri Plotnikov | 7c5286e | 2010-05-04 16:49:36 -0700 | [diff] [blame] | 991 | } |
Dmitri Plotnikov | b4e8886 | 2010-06-30 21:24:35 -0700 | [diff] [blame] | 992 | return mPhoneNumberCallInteraction; |
| 993 | } |
| 994 | |
| 995 | private PhoneNumberInteraction getSendTextMessageInteraction() { |
| 996 | if (mSendTextMessageInteraction == null) { |
| 997 | mSendTextMessageInteraction = new PhoneNumberInteraction(this, true, null); |
| 998 | } |
| 999 | return mSendTextMessageInteraction; |
Dmitri Plotnikov | 7c5286e | 2010-05-04 16:49:36 -0700 | [diff] [blame] | 1000 | } |
Dmitri Plotnikov | 9692f26 | 2010-06-29 18:53:11 -0700 | [diff] [blame] | 1001 | |
| 1002 | private ContactDeletionInteraction getContactDeletionInteraction() { |
| 1003 | if (mContactDeletionInteraction == null) { |
| 1004 | mContactDeletionInteraction = new ContactDeletionInteraction(); |
| 1005 | mContactDeletionInteraction.attachToActivity(this); |
| 1006 | } |
| 1007 | return mContactDeletionInteraction; |
| 1008 | } |
Dmitri Plotnikov | aa1dffe | 2010-07-01 13:46:17 -0700 | [diff] [blame] | 1009 | |
| 1010 | private ImportExportInteraction getImportExportInteraction() { |
| 1011 | if (mImportExportInteraction == null) { |
| 1012 | mImportExportInteraction = new ImportExportInteraction(this); |
| 1013 | } |
| 1014 | return mImportExportInteraction; |
| 1015 | } |
Daniel Lehmann | 3391dbe | 2010-07-12 09:50:22 -0700 | [diff] [blame] | 1016 | |
| 1017 | @Override |
| 1018 | public DialogManager getDialogManager() { |
| 1019 | return mDialogManager; |
| 1020 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1021 | } |