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; |
Dmitri Plotnikov | f3ee899 | 2010-02-25 15:25:19 -0800 | [diff] [blame] | 21 | import android.os.Bundle; |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 22 | import android.provider.ContactsContract; |
| 23 | import android.provider.ContactsContract.Intents.UI; |
| 24 | |
| 25 | /** |
| 26 | * A convenience class that helps launch contact search from within the app. |
| 27 | */ |
| 28 | public 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 Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame^] | 43 | * 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 Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 49 | * Starts the contact list activity in the search mode. |
| 50 | */ |
| 51 | public static void startSearch(Activity context, String initialQuery) { |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame^] | 52 | context.startActivity(buildIntent(context, initialQuery, null)); |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public static void startSearchForResult(Activity context, String initialQuery, |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame^] | 56 | int requestCode, Bundle includedExtras) { |
| 57 | context.startActivityForResult( |
| 58 | buildIntent(context, initialQuery, includedExtras), requestCode); |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame^] | 61 | private static Intent buildIntent( |
| 62 | Activity context, String initialQuery, Bundle includedExtras) { |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 63 | Intent intent = new Intent(); |
| 64 | intent.setData(ContactsContract.Contacts.CONTENT_URI); |
| 65 | intent.setAction(UI.FILTER_CONTACTS_ACTION); |
Dmitri Plotnikov | f3ee899 | 2010-02-25 15:25:19 -0800 | [diff] [blame] | 66 | |
| 67 | Intent originalIntent = context.getIntent(); |
| 68 | Bundle originalExtras = originalIntent.getExtras(); |
| 69 | if (originalExtras != null) { |
| 70 | intent.putExtras(originalExtras); |
| 71 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 72 | intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, initialQuery); |
Dmitri Plotnikov | f3ee899 | 2010-02-25 15:25:19 -0800 | [diff] [blame] | 73 | intent.putExtra(ORIGINAL_ACTION_EXTRA_KEY, originalIntent.getAction()); |
| 74 | intent.putExtra(ORIGINAL_COMPONENT_EXTRA_KEY, originalIntent.getComponent().getClassName()); |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame^] | 75 | intent.putExtra(ORIGINAL_TYPE_EXTRA_KEY, originalIntent.getType()); |
| 76 | if (includedExtras != null) { |
| 77 | intent.putExtras(includedExtras); |
| 78 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 79 | return intent; |
| 80 | } |
| 81 | } |