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