1/*
2 * Copyright (C) 2011 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
18import android.net.Uri;
19import android.view.LayoutInflater;
20import android.view.View;
21import android.view.ViewGroup;
22
23import com.android.contacts.R;
24import com.android.contacts.common.list.ContactEntryListAdapter;
25import com.android.contacts.common.list.ContactEntryListFragment;
26import com.android.contacts.common.list.DirectoryListLoader;
27
28/**
29 * Fragment containing an email list for picking.
30 */
31public class EmailAddressPickerFragment extends ContactEntryListFragment<ContactEntryListAdapter> {
32    private OnEmailAddressPickerActionListener mListener;
33
34    public EmailAddressPickerFragment() {
35        setQuickContactEnabled(false);
36        setPhotoLoaderEnabled(true);
37        setSectionHeaderDisplayEnabled(true);
38        setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DATA_SHORTCUT);
39    }
40
41    public void setOnEmailAddressPickerActionListener(OnEmailAddressPickerActionListener listener) {
42        mListener = listener;
43    }
44
45    @Override
46    protected void onItemClick(int position, long id) {
47        EmailAddressListAdapter adapter = (EmailAddressListAdapter)getAdapter();
48        pickEmailAddress(adapter.getDataUri(position));
49    }
50
51    @Override
52    protected ContactEntryListAdapter createListAdapter() {
53        EmailAddressListAdapter adapter = new EmailAddressListAdapter(getActivity());
54        adapter.setSectionHeaderDisplayEnabled(true);
55        adapter.setDisplayPhotos(true);
56        return adapter;
57    }
58
59    @Override
60    protected View inflateView(LayoutInflater inflater, ViewGroup container) {
61        return inflater.inflate(R.layout.contact_list_content, null);
62    }
63
64    @Override
65    protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
66        super.onCreateView(inflater, container);
67
68        setVisibleScrollbarEnabled(!isLegacyCompatibilityMode());
69    }
70
71    private void pickEmailAddress(Uri uri) {
72        mListener.onPickEmailAddressAction(uri);
73    }
74}
75