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.content.Loader; 19import android.database.Cursor; 20import android.net.Uri; 21import android.os.Bundle; 22import android.provider.ContactsContract.Directory; 23import android.util.Log; 24 25import com.android.contacts.common.list.ContactEntryListAdapter; 26import com.android.contacts.common.list.PhoneNumberPickerFragment; 27import com.android.dialer.dialpad.SmartDialCursorLoader; 28 29/** 30 * Implements a fragment to load and display SmartDial search results. 31 */ 32public class SmartDialNumberPickerFragment extends PhoneNumberPickerFragment { 33 34 private static final String TAG = SmartDialNumberPickerFragment.class.getSimpleName(); 35 36 /** 37 * Creates a SmartDialListAdapter to display and operate on search results. 38 * @return 39 */ 40 @Override 41 protected ContactEntryListAdapter createListAdapter() { 42 SmartDialNumberListAdapter adapter = new SmartDialNumberListAdapter(getActivity()); 43 adapter.setDisplayPhotos(true); 44 adapter.setUseCallableUri(super.usesCallableUri()); 45 return adapter; 46 } 47 48 /** 49 * Creates a SmartDialCursorLoader object to load query results. 50 */ 51 @Override 52 public Loader<Cursor> onCreateLoader(int id, Bundle args) { 53 /** SmartDial does not support Directory Load, falls back to normal search instead. */ 54 if (id == getDirectoryLoaderId()) { 55 Log.v(TAG, "Directory load"); 56 return super.onCreateLoader(id, args); 57 } else { 58 Log.v(TAG, "Creating loader"); 59 final SmartDialNumberListAdapter adapter = (SmartDialNumberListAdapter) getAdapter(); 60 SmartDialCursorLoader loader = new SmartDialCursorLoader(super.getContext()); 61 adapter.configureLoader(loader); 62 return loader; 63 } 64 } 65 66 /** 67 * Gets the Phone Uri of an entry for calling. 68 * @param position Location of the data of interest. 69 * @return Phone Uri to establish a phone call. 70 */ 71 @Override 72 protected Uri getPhoneUri(int position) { 73 final SmartDialNumberListAdapter adapter = (SmartDialNumberListAdapter) getAdapter(); 74 return adapter.getDataUri(position); 75 } 76} 77