Daniel Lehmann | c86ace7 | 2011-03-23 21:04:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.list; |
| 17 | |
Daniel Lehmann | c86ace7 | 2011-03-23 21:04:29 -0700 | [diff] [blame] | 18 | import android.net.Uri; |
| 19 | import android.view.LayoutInflater; |
| 20 | import android.view.View; |
| 21 | import android.view.ViewGroup; |
| 22 | |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 23 | import com.android.contacts.R; |
Chiao Cheng | a0233a0 | 2012-11-01 16:41:08 -0700 | [diff] [blame] | 24 | import com.android.contacts.common.list.ContactEntryListAdapter; |
Chiao Cheng | 821a657 | 2012-12-04 17:42:52 -0800 | [diff] [blame] | 25 | import com.android.contacts.common.list.ContactEntryListFragment; |
Chiao Cheng | a0233a0 | 2012-11-01 16:41:08 -0700 | [diff] [blame] | 26 | import com.android.contacts.common.list.DirectoryListLoader; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 27 | |
Daniel Lehmann | c86ace7 | 2011-03-23 21:04:29 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Fragment containing an email list for picking. |
| 30 | */ |
| 31 | public class EmailAddressPickerFragment extends ContactEntryListFragment<ContactEntryListAdapter> { |
| 32 | private OnEmailAddressPickerActionListener mListener; |
| 33 | |
| 34 | public EmailAddressPickerFragment() { |
| 35 | setQuickContactEnabled(false); |
| 36 | setPhotoLoaderEnabled(true); |
| 37 | setSectionHeaderDisplayEnabled(true); |
| 38 | setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DATA_SHORTCUT); |
| 39 | } |
| 40 | |
| 41 | public void setOnEmailAddressPickerActionListener(OnEmailAddressPickerActionListener listener) { |
| 42 | mListener = listener; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | protected void onItemClick(int position, long id) { |
| 47 | EmailAddressListAdapter adapter = (EmailAddressListAdapter)getAdapter(); |
Brian Attwell | b831b14 | 2014-10-03 15:45:18 -0700 | [diff] [blame] | 48 | if (getAdapter().getItem(position) == null) { |
| 49 | return; |
| 50 | } |
Daniel Lehmann | c86ace7 | 2011-03-23 21:04:29 -0700 | [diff] [blame] | 51 | pickEmailAddress(adapter.getDataUri(position)); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected ContactEntryListAdapter createListAdapter() { |
| 56 | EmailAddressListAdapter adapter = new EmailAddressListAdapter(getActivity()); |
| 57 | adapter.setSectionHeaderDisplayEnabled(true); |
| 58 | adapter.setDisplayPhotos(true); |
| 59 | return adapter; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | protected View inflateView(LayoutInflater inflater, ViewGroup container) { |
Daisuke Miyakawa | 34b901c | 2011-10-18 14:33:41 -0700 | [diff] [blame] | 64 | return inflater.inflate(R.layout.contact_list_content, null); |
Daniel Lehmann | c86ace7 | 2011-03-23 21:04:29 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Daisuke Miyakawa | e231f19 | 2011-11-18 10:52:25 -0800 | [diff] [blame] | 67 | @Override |
| 68 | protected void onCreateView(LayoutInflater inflater, ViewGroup container) { |
| 69 | super.onCreateView(inflater, container); |
| 70 | |
| 71 | setVisibleScrollbarEnabled(!isLegacyCompatibilityMode()); |
| 72 | } |
| 73 | |
Daniel Lehmann | c86ace7 | 2011-03-23 21:04:29 -0700 | [diff] [blame] | 74 | private void pickEmailAddress(Uri uri) { |
| 75 | mListener.onPickEmailAddressAction(uri); |
| 76 | } |
| 77 | } |