blob: 2297817e6f458797a33b00dc90bafe05eddf49e9 [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 /**
Bai Taodf5e05f2010-04-09 00:44:44 +080043 * An extra that provides context for search UI and defines the scope for
44 * the search queries.
45 */
46 public static final String ORIGINAL_TYPE_EXTRA_KEY = "originalType";
47
48 /**
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080049 * Starts the contact list activity in the search mode.
50 */
51 public static void startSearch(Activity context, String initialQuery) {
Bai Taodf5e05f2010-04-09 00:44:44 +080052 context.startActivity(buildIntent(context, initialQuery, null));
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080053 }
54
55 public static void startSearchForResult(Activity context, String initialQuery,
Bai Taodf5e05f2010-04-09 00:44:44 +080056 int requestCode, Bundle includedExtras) {
57 context.startActivityForResult(
58 buildIntent(context, initialQuery, includedExtras), requestCode);
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080059 }
60
Bai Taodf5e05f2010-04-09 00:44:44 +080061 private static Intent buildIntent(
62 Activity context, String initialQuery, Bundle includedExtras) {
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080063 Intent intent = new Intent();
64 intent.setData(ContactsContract.Contacts.CONTENT_URI);
65 intent.setAction(UI.FILTER_CONTACTS_ACTION);
Dmitri Plotnikovf3ee8992010-02-25 15:25:19 -080066
67 Intent originalIntent = context.getIntent();
68 Bundle originalExtras = originalIntent.getExtras();
69 if (originalExtras != null) {
70 intent.putExtras(originalExtras);
71 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080072 intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, initialQuery);
Dmitri Plotnikovf3ee8992010-02-25 15:25:19 -080073 intent.putExtra(ORIGINAL_ACTION_EXTRA_KEY, originalIntent.getAction());
74 intent.putExtra(ORIGINAL_COMPONENT_EXTRA_KEY, originalIntent.getComponent().getClassName());
Bai Taodf5e05f2010-04-09 00:44:44 +080075 intent.putExtra(ORIGINAL_TYPE_EXTRA_KEY, originalIntent.getType());
76 if (includedExtras != null) {
77 intent.putExtras(includedExtras);
78 }
Dmitri Plotnikov8e86b752010-02-22 17:47:57 -080079 return intent;
80 }
81}