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