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 | |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 25 | import com.android.contacts.list.ContactsRequest; |
| 26 | |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 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 | */ |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 36 | public static final String ORIGINAL_REQUEST_KEY = "originalRequest"; |
| 37 | |
| 38 | /** |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 39 | * Starts the contact list activity in the search mode. |
| 40 | */ |
| 41 | public static void startSearch(Activity context, String initialQuery) { |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 42 | context.startActivity(buildIntent(context, initialQuery, null)); |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | public static void startSearchForResult(Activity context, String initialQuery, |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 46 | int requestCode, ContactsRequest originalRequest) { |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 47 | context.startActivityForResult( |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 48 | buildIntent(context, initialQuery, originalRequest), requestCode); |
| 49 | } |
| 50 | |
| 51 | public static void startSearch(Activity context, String initialQuery, |
| 52 | ContactsRequest originalRequest) { |
| 53 | context.startActivity(buildIntent(context, initialQuery, originalRequest)); |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 56 | private static Intent buildIntent( |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 57 | Activity context, String initialQuery, ContactsRequest originalRequest) { |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 58 | Intent intent = new Intent(); |
| 59 | intent.setData(ContactsContract.Contacts.CONTENT_URI); |
| 60 | intent.setAction(UI.FILTER_CONTACTS_ACTION); |
Dmitri Plotnikov | f3ee899 | 2010-02-25 15:25:19 -0800 | [diff] [blame] | 61 | |
| 62 | Intent originalIntent = context.getIntent(); |
| 63 | Bundle originalExtras = originalIntent.getExtras(); |
| 64 | if (originalExtras != null) { |
| 65 | intent.putExtras(originalExtras); |
| 66 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 67 | intent.putExtra(UI.FILTER_TEXT_EXTRA_KEY, initialQuery); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 68 | if (originalRequest != null) { |
| 69 | intent.putExtra(ORIGINAL_REQUEST_KEY, originalRequest); |
Bai Tao | df5e05f | 2010-04-09 00:44:44 +0800 | [diff] [blame] | 70 | } |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 71 | return intent; |
| 72 | } |
| 73 | } |