Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.contacts; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.Intent; |
| 21 | import android.provider.ContactsContract; |
| 22 | import android.provider.ContactsContract.Intents.UI; |
| 23 | |
| 24 | /** |
| 25 | * A convenience class that helps launch contact search from within the app. |
| 26 | */ |
| 27 | public class ContactsSearchManager { |
| 28 | |
| 29 | /** |
| 30 | * An extra that provides context for search UI and defines the scope for |
| 31 | * the search queries. |
| 32 | */ |
| 33 | public static final String ORIGINAL_ACTION_EXTRA_KEY = "originalAction"; |
| 34 | |
| 35 | /** |
| 36 | * An extra that provides context for search UI and defines the scope for |
| 37 | * the search queries. |
| 38 | */ |
| 39 | public static final String ORIGINAL_COMPONENT_EXTRA_KEY = "originalComponent"; |
| 40 | |
| 41 | /** |
| 42 | * Starts the contact list activity in the search mode. |
| 43 | */ |
| 44 | public static void startSearch(Activity context, String initialQuery) { |
| 45 | context.startActivity(buildIntent(context, initialQuery)); |
| 46 | } |
| 47 | |
| 48 | public static void startSearchForResult(Activity context, String initialQuery, |
| 49 | int requestCode) { |
| 50 | context.startActivityForResult(buildIntent(context, initialQuery), requestCode); |
| 51 | } |
| 52 | |
| 53 | private static Intent buildIntent(Activity context, String initialQuery) { |
| 54 | Intent intent = new Intent(); |
| 55 | intent.setData(ContactsContract.Contacts.CONTENT_URI); |
| 56 | intent.setAction(UI.FILTER_CONTACTS_ACTION); |
| 57 | intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, initialQuery); |
| 58 | intent.putExtra(ORIGINAL_ACTION_EXTRA_KEY, context.getIntent().getAction()); |
| 59 | intent.putExtra(ORIGINAL_COMPONENT_EXTRA_KEY, |
| 60 | context.getIntent().getComponent().getClassName()); |
| 61 | return intent; |
| 62 | } |
| 63 | } |