1/*
2 * Copyright (C) 2017 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
17package com.android.dialer.searchfragment.nearbyplaces;
18
19import android.content.Context;
20import android.content.CursorLoader;
21import android.net.Uri;
22import android.provider.ContactsContract;
23import com.android.contacts.common.extensions.PhoneDirectoryExtenderAccessor;
24import com.android.dialer.searchfragment.common.Projections;
25
26/** Cursor loader for nearby places search results. */
27public final class NearbyPlacesCursorLoader extends CursorLoader {
28
29  private static final String MAX_RESULTS = "3";
30
31  public NearbyPlacesCursorLoader(Context context, String query) {
32    super(context, getContentUri(context, query), Projections.PHONE_PROJECTION, null, null, null);
33  }
34
35  private static Uri getContentUri(Context context, String query) {
36    return PhoneDirectoryExtenderAccessor.get(context)
37        .getContentUri()
38        .buildUpon()
39        .appendPath(query)
40        .appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY, MAX_RESULTS)
41        .build();
42  }
43}
44