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