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 android.net.Uri;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 
23 import com.android.contacts.R;
24 import com.android.contacts.common.list.ContactEntryListAdapter;
25 import com.android.contacts.common.list.ContactEntryListFragment;
26 import com.android.contacts.common.list.DirectoryListLoader;
27 
28 /**
29  * Fragment containing a postal address list for picking.
30  */
31 public class PostalAddressPickerFragment
32         extends ContactEntryListFragment<ContactEntryListAdapter> {
33     private OnPostalAddressPickerActionListener mListener;
34 
PostalAddressPickerFragment()35     public PostalAddressPickerFragment() {
36         setQuickContactEnabled(false);
37         setPhotoLoaderEnabled(true);
38         setSectionHeaderDisplayEnabled(true);
39         setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DATA_SHORTCUT);
40     }
41 
setOnPostalAddressPickerActionListener( OnPostalAddressPickerActionListener listener)42     public void setOnPostalAddressPickerActionListener(
43             OnPostalAddressPickerActionListener listener) {
44         this.mListener = listener;
45     }
46 
47     @Override
onItemClick(int position, long id)48     protected void onItemClick(int position, long id) {
49         if (getAdapter().getItem(position) == null) {
50             return;
51         }
52         if (!isLegacyCompatibilityMode()) {
53             PostalAddressListAdapter adapter = (PostalAddressListAdapter)getAdapter();
54             pickPostalAddress(adapter.getDataUri(position));
55         } else {
56             LegacyPostalAddressListAdapter adapter = (LegacyPostalAddressListAdapter)getAdapter();
57             pickPostalAddress(adapter.getContactMethodUri(position));
58         }
59     }
60 
61     @Override
createListAdapter()62     protected ContactEntryListAdapter createListAdapter() {
63         if (!isLegacyCompatibilityMode()) {
64             PostalAddressListAdapter adapter = new PostalAddressListAdapter(getActivity());
65             adapter.setSectionHeaderDisplayEnabled(true);
66             adapter.setDisplayPhotos(true);
67             return adapter;
68         } else {
69             LegacyPostalAddressListAdapter adapter =
70                     new LegacyPostalAddressListAdapter(getActivity());
71             adapter.setSectionHeaderDisplayEnabled(false);
72             adapter.setDisplayPhotos(false);
73             return adapter;
74         }
75     }
76 
77     @Override
inflateView(LayoutInflater inflater, ViewGroup container)78     protected View inflateView(LayoutInflater inflater, ViewGroup container) {
79         return inflater.inflate(R.layout.contact_list_content, null);
80     }
81 
82     @Override
onCreateView(LayoutInflater inflater, ViewGroup container)83     protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
84         super.onCreateView(inflater, container);
85 
86         setVisibleScrollbarEnabled(!isLegacyCompatibilityMode());
87     }
88 
pickPostalAddress(Uri uri)89     private void pickPostalAddress(Uri uri) {
90         mListener.onPickPostalAddressAction(uri);
91     }
92 }
93