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