blob: d65e0790b1fdce9502b841a1ab89f40a16c7a8b9 [file] [log] [blame]
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -08001/*
2 * Copyright (C) 2010 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.contacts;
18
19import android.app.Activity;
20import android.content.Intent;
Dmitri Plotnikovf3ee8992010-02-25 15:25:19 -080021import android.os.Bundle;
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080022import android.provider.ContactsContract;
23import android.provider.ContactsContract.Intents.UI;
24
25/**
26 * A convenience class that helps launch contact search from within the app.
27 */
28public class ContactsSearchManager {
29
30 /**
31 * An extra that provides context for search UI and defines the scope for
32 * the search queries.
33 */
34 public static final String ORIGINAL_ACTION_EXTRA_KEY = "originalAction";
35
36 /**
37 * An extra that provides context for search UI and defines the scope for
38 * the search queries.
39 */
40 public static final String ORIGINAL_COMPONENT_EXTRA_KEY = "originalComponent";
41
42 /**
43 * Starts the contact list activity in the search mode.
44 */
45 public static void startSearch(Activity context, String initialQuery) {
46 context.startActivity(buildIntent(context, initialQuery));
47 }
48
49 public static void startSearchForResult(Activity context, String initialQuery,
50 int requestCode) {
51 context.startActivityForResult(buildIntent(context, initialQuery), requestCode);
52 }
53
54 private static Intent buildIntent(Activity context, String initialQuery) {
55 Intent intent = new Intent();
56 intent.setData(ContactsContract.Contacts.CONTENT_URI);
57 intent.setAction(UI.FILTER_CONTACTS_ACTION);
Dmitri Plotnikovf3ee8992010-02-25 15:25:19 -080058
59 Intent originalIntent = context.getIntent();
60 Bundle originalExtras = originalIntent.getExtras();
61 if (originalExtras != null) {
62 intent.putExtras(originalExtras);
63 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080064 intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, initialQuery);
Dmitri Plotnikovf3ee8992010-02-25 15:25:19 -080065 intent.putExtra(ORIGINAL_ACTION_EXTRA_KEY, originalIntent.getAction());
66 intent.putExtra(ORIGINAL_COMPONENT_EXTRA_KEY, originalIntent.getComponent().getClassName());
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080067 return intent;
68 }
69}