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 | |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame^] | 19 | import com.android.contacts.list.ContactsRequest; |
| 20 | |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 21 | import android.app.Activity; |
| 22 | import android.content.Intent; |
Dmitri Plotnikov | f3ee899 | 2010-02-25 15:25:19 -0800 | [diff] [blame] | 23 | import android.os.Bundle; |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 24 | import android.provider.ContactsContract; |
| 25 | import android.provider.ContactsContract.Intents.UI; |
| 26 | |
| 27 | /** |
| 28 | * A convenience class that helps launch contact search from within the app. |
| 29 | */ |
| 30 | public class ContactsSearchManager { |
| 31 | |
| 32 | /** |
| 33 | * An extra that provides context for search UI and defines the scope for |
| 34 | * the search queries. |
| 35 | */ |
| 36 | public static final String ORIGINAL_ACTION_EXTRA_KEY = "originalAction"; |
| 37 | |
| 38 | /** |
| 39 | * An extra that provides context for search UI and defines the scope for |
| 40 | * the search queries. |
| 41 | */ |
| 42 | public static final String ORIGINAL_COMPONENT_EXTRA_KEY = "originalComponent"; |
| 43 | |
| 44 | /** |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 45 | * An extra that provides context for search UI and defines the scope for |
| 46 | * the search queries. |
| 47 | */ |
| 48 | public static final String ORIGINAL_TYPE_EXTRA_KEY = "originalType"; |
| 49 | |
| 50 | /** |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame^] | 51 | * An extra that provides context for search UI and defines the scope for |
| 52 | * the search queries. |
| 53 | */ |
| 54 | public static final String ORIGINAL_ACTION_CODE_EXTRA_KEY = "originalActionCode"; |
| 55 | |
| 56 | public static final String ORIGINAL_REQUEST_KEY = "originalRequest"; |
| 57 | |
| 58 | /** |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 59 | * Starts the contact list activity in the search mode. |
| 60 | */ |
| 61 | public static void startSearch(Activity context, String initialQuery) { |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 62 | context.startActivity(buildIntent(context, initialQuery, null)); |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | public static void startSearchForResult(Activity context, String initialQuery, |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame^] | 66 | int requestCode, ContactsRequest originalRequest) { |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 67 | context.startActivityForResult( |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame^] | 68 | buildIntent(context, initialQuery, originalRequest), requestCode); |
| 69 | } |
| 70 | |
| 71 | public static void startSearch(Activity context, String initialQuery, |
| 72 | ContactsRequest originalRequest) { |
| 73 | context.startActivity(buildIntent(context, initialQuery, originalRequest)); |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 76 | private static Intent buildIntent( |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame^] | 77 | Activity context, String initialQuery, ContactsRequest originalRequest) { |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 78 | Intent intent = new Intent(); |
| 79 | intent.setData(ContactsContract.Contacts.CONTENT_URI); |
| 80 | intent.setAction(UI.FILTER_CONTACTS_ACTION); |
Dmitri Plotnikov | f3ee899 | 2010-02-25 15:25:19 -0800 | [diff] [blame] | 81 | |
| 82 | Intent originalIntent = context.getIntent(); |
| 83 | Bundle originalExtras = originalIntent.getExtras(); |
| 84 | if (originalExtras != null) { |
| 85 | intent.putExtras(originalExtras); |
| 86 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 87 | intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, initialQuery); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame^] | 88 | if (originalRequest != null) { |
| 89 | intent.putExtra(ORIGINAL_REQUEST_KEY, originalRequest); |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 90 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 91 | return intent; |
| 92 | } |
| 93 | } |