blob: c2aacee40e472d58720c7da6398e9b83ee23b6bc [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;
24
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070025/**
26 * Fragment containing a postal address list for picking.
27 */
28public class PostalAddressPickerFragment
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070029 extends ContactEntryListFragment<ContactEntryListAdapter> {
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070030 private OnPostalAddressPickerActionListener mListener;
31
32 public PostalAddressPickerFragment() {
Dmitri Plotnikov98fa1b02011-01-13 16:54:29 -080033 setQuickContactEnabled(false);
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070034 setPhotoLoaderEnabled(true);
35 setSectionHeaderDisplayEnabled(true);
Dmitri Plotnikov4d174aa2010-10-25 15:38:54 -070036 setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DATA_SHORTCUT);
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070037 }
38
39 public void setOnPostalAddressPickerActionListener(
40 OnPostalAddressPickerActionListener listener) {
41 this.mListener = listener;
42 }
43
44 @Override
45 protected void onItemClick(int position, long id) {
Brian Attwellb831b142014-10-03 15:45:18 -070046 if (getAdapter().getItem(position) == null) {
47 return;
48 }
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070049 if (!isLegacyCompatibilityMode()) {
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070050 PostalAddressListAdapter adapter = (PostalAddressListAdapter)getAdapter();
Dmitri Plotnikove1247222010-06-02 18:14:21 -070051 pickPostalAddress(adapter.getDataUri(position));
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070052 } else {
53 LegacyPostalAddressListAdapter adapter = (LegacyPostalAddressListAdapter)getAdapter();
Dmitri Plotnikove1247222010-06-02 18:14:21 -070054 pickPostalAddress(adapter.getContactMethodUri(position));
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070055 }
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070056 }
57
58 @Override
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070059 protected ContactEntryListAdapter createListAdapter() {
Dmitri Plotnikov1ce1e7c2010-05-13 16:41:00 -070060 if (!isLegacyCompatibilityMode()) {
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070061 PostalAddressListAdapter adapter = new PostalAddressListAdapter(getActivity());
62 adapter.setSectionHeaderDisplayEnabled(true);
63 adapter.setDisplayPhotos(true);
64 return adapter;
65 } else {
66 LegacyPostalAddressListAdapter adapter =
67 new LegacyPostalAddressListAdapter(getActivity());
68 adapter.setSectionHeaderDisplayEnabled(false);
69 adapter.setDisplayPhotos(false);
70 return adapter;
71 }
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070072 }
73
74 @Override
75 protected View inflateView(LayoutInflater inflater, ViewGroup container) {
Daisuke Miyakawa34b901c2011-10-18 14:33:41 -070076 return inflater.inflate(R.layout.contact_list_content, null);
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070077 }
78
Daisuke Miyakawae231f192011-11-18 10:52:25 -080079 @Override
80 protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
81 super.onCreateView(inflater, container);
82
83 setVisibleScrollbarEnabled(!isLegacyCompatibilityMode());
84 }
85
Daniel Lehmannc86ace72011-03-23 21:04:29 -070086 private void pickPostalAddress(Uri uri) {
Dmitri Plotnikovd820cdb2010-05-06 14:11:55 -070087 mListener.onPickPostalAddressAction(uri);
88 }
89}