Dmitri Plotnikov | d820cdb | 2010-05-06 14:11:55 -0700 | [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.list; |
| 17 | |
| 18 | import com.android.contacts.R; |
| 19 | |
| 20 | import android.net.Uri; |
| 21 | import android.view.LayoutInflater; |
| 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
| 24 | |
| 25 | /** |
| 26 | * Fragment containing a postal address list for picking. |
| 27 | */ |
| 28 | public class PostalAddressPickerFragment |
| 29 | extends ContactEntryListFragment<PostalAddressListAdapter> { |
| 30 | private OnPostalAddressPickerActionListener mListener; |
| 31 | |
| 32 | public PostalAddressPickerFragment() { |
| 33 | setPhotoLoaderEnabled(true); |
| 34 | setSectionHeaderDisplayEnabled(true); |
| 35 | } |
| 36 | |
| 37 | public void setOnPostalAddressPickerActionListener( |
| 38 | OnPostalAddressPickerActionListener listener) { |
| 39 | this.mListener = listener; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | protected void onItemClick(int position, long id) { |
| 44 | PostalAddressListAdapter adapter = getAdapter(); |
| 45 | // if (adapter.isSearchAllContactsItemPosition(position)) { |
| 46 | // searchAllContacts(); |
| 47 | // } else { |
| 48 | adapter.moveToPosition(position); |
| 49 | pickPostalAddress(adapter.getDataUri()); |
| 50 | // } |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | protected PostalAddressListAdapter createListAdapter() { |
| 55 | PostalAddressListAdapter adapter = new PostalAddressListAdapter(getActivity()); |
| 56 | |
| 57 | adapter.setSectionHeaderDisplayEnabled(true); |
| 58 | adapter.setDisplayPhotos(true); |
| 59 | |
| 60 | adapter.setSearchMode(isSearchMode()); |
| 61 | adapter.setSearchResultsMode(isSearchResultsMode()); |
| 62 | adapter.setQueryString(getQueryString()); |
| 63 | |
| 64 | adapter.setContactNameDisplayOrder(getContactNameDisplayOrder()); |
| 65 | adapter.setSortOrder(getSortOrder()); |
| 66 | |
| 67 | return adapter; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected View inflateView(LayoutInflater inflater, ViewGroup container) { |
| 72 | if (isSearchMode()) { |
| 73 | return inflater.inflate(R.layout.contacts_search_content, null); |
| 74 | } else if (isSearchResultsMode()) { |
| 75 | return inflater.inflate(R.layout.contacts_list_search_results, null); |
| 76 | } else { |
| 77 | return inflater.inflate(R.layout.contacts_list_content, null); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public void pickPostalAddress(Uri uri) { |
| 82 | mListener.onPickPostalAddressAction(uri); |
| 83 | } |
| 84 | } |