blob: c64e17337aac726e13cf60f0e0627c90b79ad6f3 [file] [log] [blame]
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -07001/*
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 */
16package com.android.contacts.list;
17
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070018import android.net.Uri;
19import android.view.LayoutInflater;
20import android.view.View;
21import android.view.ViewGroup;
22
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070023import com.android.contacts.R;
Chiao Chenga0233a02012-11-01 16:41:08 -070024import com.android.contacts.common.list.ContactEntryListAdapter;
Chiao Cheng821a6572012-12-04 17:42:52 -080025import com.android.contacts.common.list.ContactEntryListFragment;
Chiao Chenga0233a02012-11-01 16:41:08 -070026import com.android.contacts.common.list.DirectoryListLoader;
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070027
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070028/**
29 * Fragment containing a postal address list for picking.
30 */
31public class PostalAddressPickerFragment
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070032 extends ContactEntryListFragment<ContactEntryListAdapter> {
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070033 private OnPostalAddressPickerActionListener mListener;
34
35 public PostalAddressPickerFragment() {
Dmitri Plotnikov98fa1b02011-01-13 16:54:29 -080036 setQuickContactEnabled(false);
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070037 setPhotoLoaderEnabled(true);
38 setSectionHeaderDisplayEnabled(true);
Dmitri Plotnikov4d174aa2010-10-25 15:38:54 -070039 setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DATA_SHORTCUT);
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070040 }
41
42 public void setOnPostalAddressPickerActionListener(
43 OnPostalAddressPickerActionListener listener) {
44 this.mListener = listener;
45 }
46
47 @Override
48 protected void onItemClick(int position, long id) {
Brian Attwellb831b142014-10-03 15:45:18 -070049 if (getAdapter().getItem(position) == null) {
50 return;
51 }
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070052 if (!isLegacyCompatibilityMode()) {
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070053 PostalAddressListAdapter adapter = (PostalAddressListAdapter)getAdapter();
Dmitri Plotnikove1247222010-06-02 18:14:21 -070054 pickPostalAddress(adapter.getDataUri(position));
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070055 } else {
56 LegacyPostalAddressListAdapter adapter = (LegacyPostalAddressListAdapter)getAdapter();
Dmitri Plotnikove1247222010-06-02 18:14:21 -070057 pickPostalAddress(adapter.getContactMethodUri(position));
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070058 }
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070059 }
60
61 @Override
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070062 protected ContactEntryListAdapter createListAdapter() {
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070063 if (!isLegacyCompatibilityMode()) {
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070064 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 }
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070075 }
76
77 @Override
78 protected View inflateView(LayoutInflater inflater, ViewGroup container) {
Daisuke Miyakawa34b901c2011-10-18 14:33:41 -070079 return inflater.inflate(R.layout.contact_list_content, null);
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070080 }
81
Daisuke Miyakawae231f192011-11-18 10:52:25 -080082 @Override
83 protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
84 super.onCreateView(inflater, container);
85
86 setVisibleScrollbarEnabled(!isLegacyCompatibilityMode());
87 }
88
Daniel Lehmannc86ace72011-03-23 21:04:29 -070089 private void pickPostalAddress(Uri uri) {
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070090 mListener.onPickPostalAddressAction(uri);
91 }
92}