1/*
2 * Copyright (C) 2013 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.dialer.list;
17
18import android.view.LayoutInflater;
19import android.view.ViewGroup;
20
21import com.android.contacts.common.list.ContactEntryListAdapter;
22import com.android.contacts.common.list.PinnedHeaderListView;
23import com.android.dialerbind.ObjectFactory;
24import com.android.dialer.service.CachedNumberLookupService;
25
26public class RegularSearchFragment extends SearchFragment {
27
28    private static final int SEARCH_DIRECTORY_RESULT_LIMIT = 5;
29
30    private static final CachedNumberLookupService mCachedNumberLookupService =
31        ObjectFactory.newCachedNumberLookupService();
32
33    public RegularSearchFragment() {
34        configureDirectorySearch();
35    }
36
37    public void configureDirectorySearch() {
38        setDirectorySearchEnabled(true);
39        setDirectoryResultLimit(SEARCH_DIRECTORY_RESULT_LIMIT);
40    }
41
42    @Override
43    protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
44        super.onCreateView(inflater, container);
45        ((PinnedHeaderListView) getListView()).setScrollToSectionOnHeaderTouch(true);
46    }
47
48    protected ContactEntryListAdapter createListAdapter() {
49        RegularSearchListAdapter adapter = new RegularSearchListAdapter(getActivity());
50        adapter.setDisplayPhotos(true);
51        adapter.setUseCallableUri(usesCallableUri());
52        return adapter;
53    }
54
55    @Override
56    protected void cacheContactInfo(int position) {
57        if (mCachedNumberLookupService != null) {
58            final RegularSearchListAdapter adapter =
59                (RegularSearchListAdapter) getAdapter();
60            mCachedNumberLookupService.addContact(getContext(),
61                    adapter.getContactInfo(mCachedNumberLookupService, position));
62        }
63    }
64}
65