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.util.Log;
23
24import com.android.contacts.common.list.ContactEntryListAdapter;
25import com.android.dialer.dialpad.SmartDialCursorLoader;
26
27/**
28 * Implements a fragment to load and display SmartDial search results.
29 */
30public 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
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        return adapter;
45    }
46
47    /**
48     * Creates a SmartDialCursorLoader object to load query results.
49     */
50    @Override
51    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
52        // Smart dialing does not support Directory Load, falls back to normal search instead.
53        if (id == getDirectoryLoaderId()) {
54            return super.onCreateLoader(id, args);
55        } else {
56            final SmartDialNumberListAdapter adapter = (SmartDialNumberListAdapter) getAdapter();
57            SmartDialCursorLoader loader = new SmartDialCursorLoader(super.getContext());
58            adapter.configureLoader(loader);
59            return loader;
60        }
61    }
62
63    /**
64     * Gets the Phone Uri of an entry for calling.
65     * @param position Location of the data of interest.
66     * @return Phone Uri to establish a phone call.
67     */
68    @Override
69    protected Uri getPhoneUri(int position) {
70        final SmartDialNumberListAdapter adapter = (SmartDialNumberListAdapter) getAdapter();
71        return adapter.getDataUri(position);
72    }
73}
74