The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 android.app; |
| 18 | |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 19 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.ComponentName; |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 21 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.DialogInterface; |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 24 | import android.content.Intent; |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 25 | import android.database.Cursor; |
| 26 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
| 28 | import android.os.Handler; |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 29 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.ServiceManager; |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 31 | import android.text.TextUtils; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 32 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
| 34 | |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 35 | import java.util.List; |
| 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | /** |
| 38 | * This class provides access to the system search services. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 39 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | * <p>In practice, you won't interact with this class directly, as search |
| 41 | * services are provided through methods in {@link android.app.Activity Activity} |
Scott Main | 8ad6465 | 2010-03-17 12:06:06 -0700 | [diff] [blame] | 42 | * and the {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH} |
| 43 | * {@link android.content.Intent Intent}. |
| 44 | * If you do require direct access to the SearchManager, do not instantiate |
| 45 | * this class directly. Instead, retrieve it through |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | * {@link android.content.Context#getSystemService |
| 47 | * context.getSystemService(Context.SEARCH_SERVICE)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | * |
Scott Main | 8ad6465 | 2010-03-17 12:06:06 -0700 | [diff] [blame] | 49 | * <div class="special"> |
| 50 | * <p>For a guide to using the search dialog and adding search |
| 51 | * suggestions in your application, see the Dev Guide topic about <strong><a |
| 52 | * href="{@docRoot}guide/topics/search/index.html">Search</a></strong>.</p> |
| 53 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | */ |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 55 | public class SearchManager |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener |
| 57 | { |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 58 | |
| 59 | private static final boolean DBG = false; |
| 60 | private static final String TAG = "SearchManager"; |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
| 63 | * This is a shortcut definition for the default menu key to use for invoking search. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 64 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | * See Menu.Item.setAlphabeticShortcut() for more information. |
| 66 | */ |
| 67 | public final static char MENU_KEY = 's'; |
| 68 | |
| 69 | /** |
| 70 | * This is a shortcut definition for the default menu key to use for invoking search. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 71 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | * See Menu.Item.setAlphabeticShortcut() for more information. |
| 73 | */ |
| 74 | public final static int MENU_KEYCODE = KeyEvent.KEYCODE_S; |
| 75 | |
| 76 | /** |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 77 | * Intent extra data key: Use this key with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | * {@link android.content.Intent#getStringExtra |
| 79 | * content.Intent.getStringExtra()} |
| 80 | * to obtain the query string from Intent.ACTION_SEARCH. |
| 81 | */ |
| 82 | public final static String QUERY = "query"; |
| 83 | |
| 84 | /** |
Bjorn Bringert | 5f80605 | 2009-06-24 12:02:26 +0100 | [diff] [blame] | 85 | * Intent extra data key: Use this key with |
| 86 | * {@link android.content.Intent#getStringExtra |
| 87 | * content.Intent.getStringExtra()} |
| 88 | * to obtain the query string typed in by the user. |
| 89 | * This may be different from the value of {@link #QUERY} |
| 90 | * if the intent is the result of selecting a suggestion. |
| 91 | * In that case, {@link #QUERY} will contain the value of |
| 92 | * {@link #SUGGEST_COLUMN_QUERY} for the suggestion, and |
| 93 | * {@link #USER_QUERY} will contain the string typed by the |
| 94 | * user. |
| 95 | */ |
| 96 | public final static String USER_QUERY = "user_query"; |
| 97 | |
| 98 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | * Intent extra data key: Use this key with Intent.ACTION_SEARCH and |
| 100 | * {@link android.content.Intent#getBundleExtra |
| 101 | * content.Intent.getBundleExtra()} |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 102 | * to obtain any additional app-specific data that was inserted by the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | * activity that launched the search. |
| 104 | */ |
| 105 | public final static String APP_DATA = "app_data"; |
| 106 | |
| 107 | /** |
Bjorn Bringert | be5b73c | 2009-09-21 23:05:23 +0100 | [diff] [blame] | 108 | * Intent extra data key: Use {@link android.content.Intent#getBundleExtra |
| 109 | * content.Intent.getBundleExtra(SEARCH_MODE)} to get the search mode used |
| 110 | * to launch the intent. |
| 111 | * The only current value for this is {@link #MODE_GLOBAL_SEARCH_SUGGESTION}. |
| 112 | * |
| 113 | * @hide |
| 114 | */ |
| 115 | public final static String SEARCH_MODE = "search_mode"; |
| 116 | |
| 117 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | * Intent extra data key: Use this key with Intent.ACTION_SEARCH and |
| 119 | * {@link android.content.Intent#getIntExtra content.Intent.getIntExtra()} |
| 120 | * to obtain the keycode that the user used to trigger this query. It will be zero if the |
| 121 | * user simply pressed the "GO" button on the search UI. This is primarily used in conjunction |
| 122 | * with the keycode attribute in the actionkey element of your searchable.xml configuration |
| 123 | * file. |
| 124 | */ |
| 125 | public final static String ACTION_KEY = "action_key"; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | /** |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 128 | * Intent extra data key: This key will be used for the extra populated by the |
| 129 | * {@link #SUGGEST_COLUMN_INTENT_EXTRA_DATA} column. |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 130 | */ |
| 131 | public final static String EXTRA_DATA_KEY = "intent_extra_data_key"; |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 132 | |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 133 | /** |
Bjorn Bringert | 55f3ac5 | 2010-01-14 11:38:22 +0000 | [diff] [blame] | 134 | * Boolean extra data key for {@link #INTENT_ACTION_GLOBAL_SEARCH} intents. If {@code true}, |
| 135 | * the initial query should be selected when the global search activity is started, so |
| 136 | * that the user can easily replace it with another query. |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 137 | */ |
Bjorn Bringert | 55f3ac5 | 2010-01-14 11:38:22 +0000 | [diff] [blame] | 138 | public final static String EXTRA_SELECT_QUERY = "select_query"; |
Bjorn Bringert | 32d580c | 2010-01-06 09:29:11 +0000 | [diff] [blame] | 139 | |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 140 | /** |
Leon Scroggins | af5b406 | 2011-02-22 16:35:13 -0500 | [diff] [blame] | 141 | * Boolean extra data key for {@link Intent#ACTION_WEB_SEARCH} intents. If {@code true}, |
| 142 | * this search should open a new browser window, rather than using an existing one. |
| 143 | */ |
| 144 | public final static String EXTRA_NEW_SEARCH = "new_search"; |
| 145 | |
| 146 | /** |
Amith Yamasani | c37cb24 | 2010-02-24 17:44:46 -0800 | [diff] [blame] | 147 | * Boolean extra data key for a suggestion provider to return in {@link Cursor#getExtras} to |
| 148 | * indicate that the search is not complete yet. This can be used by the search UI |
| 149 | * to indicate that a search is in progress. The suggestion provider can return partial results |
| 150 | * this way and send a change notification on the cursor when more results are available. |
| 151 | */ |
| 152 | public final static String CURSOR_EXTRA_KEY_IN_PROGRESS = "in_progress"; |
| 153 | |
| 154 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | * Intent extra data key: Use this key with Intent.ACTION_SEARCH and |
| 156 | * {@link android.content.Intent#getStringExtra content.Intent.getStringExtra()} |
| 157 | * to obtain the action message that was defined for a particular search action key and/or |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 158 | * suggestion. It will be null if the search was launched by typing "enter", touched the the |
| 159 | * "GO" button, or other means not involving any action key. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | */ |
| 161 | public final static String ACTION_MSG = "action_msg"; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * Flag to specify that the entry can be used for query refinement, i.e., the query text |
| 165 | * in the search field can be replaced with the text in this entry, when a query refinement |
| 166 | * icon is clicked. The suggestion list should show such a clickable icon beside the entry. |
| 167 | * <p>Use this flag as a bit-field for {@link #SUGGEST_COLUMN_FLAGS}. |
| 168 | */ |
| 169 | public final static int FLAG_QUERY_REFINEMENT = 1 << 0; |
| 170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Uri path for queried suggestions data. This is the path that the search manager |
| 173 | * will use when querying your content provider for suggestions data based on user input |
| 174 | * (e.g. looking for partial matches). |
| 175 | * Typically you'll use this with a URI matcher. |
| 176 | */ |
| 177 | public final static String SUGGEST_URI_PATH_QUERY = "search_suggest_query"; |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
Karl Rosaen | b619c91 | 2009-05-08 14:28:51 -0700 | [diff] [blame] | 180 | * MIME type for suggestions data. You'll use this in your suggestions content provider |
| 181 | * in the getType() function. |
| 182 | */ |
| 183 | public final static String SUGGEST_MIME_TYPE = |
| 184 | "vnd.android.cursor.dir/vnd.android.search.suggest"; |
| 185 | |
| 186 | /** |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 187 | * Uri path for shortcut validation. This is the path that the search manager will use when |
| 188 | * querying your content provider to refresh a shortcutted suggestion result and to check if it |
| 189 | * is still valid. When asked, a source may return an up to date result, or no result. No |
| 190 | * result indicates the shortcut refers to a no longer valid sugggestion. |
| 191 | * |
| 192 | * @see #SUGGEST_COLUMN_SHORTCUT_ID |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 193 | */ |
| 194 | public final static String SUGGEST_URI_PATH_SHORTCUT = "search_suggest_shortcut"; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** |
Karl Rosaen | b619c91 | 2009-05-08 14:28:51 -0700 | [diff] [blame] | 197 | * MIME type for shortcut validation. You'll use this in your suggestions content provider |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | * in the getType() function. |
| 199 | */ |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 200 | public final static String SHORTCUT_MIME_TYPE = |
Karl Rosaen | b619c91 | 2009-05-08 14:28:51 -0700 | [diff] [blame] | 201 | "vnd.android.cursor.item/vnd.android.search.suggest"; |
Karl Rosaen | d4c98c4 | 2009-06-09 17:05:54 +0100 | [diff] [blame] | 202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | /** |
| 204 | * Column name for suggestions cursor. <i>Unused - can be null or column can be omitted.</i> |
| 205 | */ |
| 206 | public final static String SUGGEST_COLUMN_FORMAT = "suggest_format"; |
| 207 | /** |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 208 | * Column name for suggestions cursor. <i>Required.</i> This is the primary line of text that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | * will be presented to the user as the suggestion. |
| 210 | */ |
| 211 | public final static String SUGGEST_COLUMN_TEXT_1 = "suggest_text_1"; |
| 212 | /** |
| 213 | * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column, |
| 214 | * then all suggestions will be provided in a two-line format. The second line of text is in |
| 215 | * a much smaller appearance. |
| 216 | */ |
| 217 | public final static String SUGGEST_COLUMN_TEXT_2 = "suggest_text_2"; |
Bjorn Bringert | 0b49ab5 | 2010-03-02 11:16:17 +0000 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Column name for suggestions cursor. <i>Optional.</i> This is a URL that will be shown |
| 221 | * as the second line of text instead of {@link #SUGGEST_COLUMN_TEXT_2}. This is a separate |
| 222 | * column so that the search UI knows to display the text as a URL, e.g. by using a different |
| 223 | * color. If this column is absent, or has the value {@code null}, |
| 224 | * {@link #SUGGEST_COLUMN_TEXT_2} will be used instead. |
| 225 | */ |
| 226 | public final static String SUGGEST_COLUMN_TEXT_2_URL = "suggest_text_2_url"; |
| 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | /** |
| 229 | * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column, |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 230 | * then all suggestions will be provided in a format that includes space for two small icons, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | * one at the left and one at the right of each suggestion. The data in the column must |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 232 | * be a resource ID of a drawable, or a URI in one of the following formats: |
| 233 | * |
| 234 | * <ul> |
| 235 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 236 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 237 | * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li> |
| 238 | * </ul> |
| 239 | * |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 240 | * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)} |
| 241 | * for more information on these schemes. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | */ |
| 243 | public final static String SUGGEST_COLUMN_ICON_1 = "suggest_icon_1"; |
| 244 | /** |
| 245 | * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column, |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 246 | * then all suggestions will be provided in a format that includes space for two small icons, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | * one at the left and one at the right of each suggestion. The data in the column must |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 248 | * be a resource ID of a drawable, or a URI in one of the following formats: |
| 249 | * |
| 250 | * <ul> |
| 251 | * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li> |
| 252 | * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li> |
| 253 | * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li> |
| 254 | * </ul> |
| 255 | * |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 256 | * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)} |
| 257 | * for more information on these schemes. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | */ |
| 259 | public final static String SUGGEST_COLUMN_ICON_2 = "suggest_icon_2"; |
| 260 | /** |
| 261 | * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i> |
| 262 | * this element exists at the given row, this is the action that will be used when |
| 263 | * forming the suggestion's intent. If the element is not provided, the action will be taken |
| 264 | * from the android:searchSuggestIntentAction field in your XML metadata. <i>At least one of |
| 265 | * these must be present for the suggestion to generate an intent.</i> Note: If your action is |
| 266 | * the same for all suggestions, it is more efficient to specify it using XML metadata and omit |
| 267 | * it from the cursor. |
| 268 | */ |
| 269 | public final static String SUGGEST_COLUMN_INTENT_ACTION = "suggest_intent_action"; |
| 270 | /** |
| 271 | * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i> |
| 272 | * this element exists at the given row, this is the data that will be used when |
| 273 | * forming the suggestion's intent. If the element is not provided, the data will be taken |
| 274 | * from the android:searchSuggestIntentData field in your XML metadata. If neither source |
| 275 | * is provided, the Intent's data field will be null. Note: If your data is |
| 276 | * the same for all suggestions, or can be described using a constant part and a specific ID, |
| 277 | * it is more efficient to specify it using XML metadata and omit it from the cursor. |
| 278 | */ |
| 279 | public final static String SUGGEST_COLUMN_INTENT_DATA = "suggest_intent_data"; |
| 280 | /** |
Satish Sampath | bf23fe0 | 2009-06-15 23:47:56 +0100 | [diff] [blame] | 281 | * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i> |
| 282 | * this element exists at the given row, this is the data that will be used when |
| 283 | * forming the suggestion's intent. If not provided, the Intent's extra data field will be null. |
| 284 | * This column allows suggestions to provide additional arbitrary data which will be included as |
Mike LeBeau | 131234c | 2009-07-20 14:09:52 -0700 | [diff] [blame] | 285 | * an extra under the key {@link #EXTRA_DATA_KEY}. |
Satish Sampath | bf23fe0 | 2009-06-15 23:47:56 +0100 | [diff] [blame] | 286 | */ |
| 287 | public final static String SUGGEST_COLUMN_INTENT_EXTRA_DATA = "suggest_intent_extra_data"; |
| 288 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i> |
| 290 | * this element exists at the given row, then "/" and this value will be appended to the data |
| 291 | * field in the Intent. This should only be used if the data field has already been set to an |
| 292 | * appropriate base string. |
| 293 | */ |
| 294 | public final static String SUGGEST_COLUMN_INTENT_DATA_ID = "suggest_intent_data_id"; |
| 295 | /** |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 296 | * Column name for suggestions cursor. <i>Required if action is |
| 297 | * {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}, optional otherwise.</i> If this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | * column exists <i>and</i> this element exists at the given row, this is the data that will be |
| 299 | * used when forming the suggestion's query. |
| 300 | */ |
| 301 | public final static String SUGGEST_COLUMN_QUERY = "suggest_intent_query"; |
| 302 | |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 303 | /** |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 304 | * Column name for suggestions cursor. <i>Optional.</i> This column is used to indicate whether |
Karl Rosaen | b504136 | 2009-08-11 11:35:07 -0700 | [diff] [blame] | 305 | * a search suggestion should be stored as a shortcut, and whether it should be refreshed. If |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 306 | * missing, the result will be stored as a shortcut and never validated. If set to |
| 307 | * {@link #SUGGEST_NEVER_MAKE_SHORTCUT}, the result will not be stored as a shortcut. |
Karl Rosaen | b504136 | 2009-08-11 11:35:07 -0700 | [diff] [blame] | 308 | * Otherwise, the shortcut id will be used to check back for an up to date suggestion using |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 309 | * {@link #SUGGEST_URI_PATH_SHORTCUT}. |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 310 | */ |
| 311 | public final static String SUGGEST_COLUMN_SHORTCUT_ID = "suggest_shortcut_id"; |
| 312 | |
| 313 | /** |
Mike LeBeau | ce0959d | 2009-06-10 23:47:54 +0100 | [diff] [blame] | 314 | * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify |
| 315 | * that a spinner should be shown in lieu of an icon2 while the shortcut of this suggestion |
| 316 | * is being refreshed. |
Mike LeBeau | ce0959d | 2009-06-10 23:47:54 +0100 | [diff] [blame] | 317 | */ |
| 318 | public final static String SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING = |
| 319 | "suggest_spinner_while_refreshing"; |
Satish Sampath | 1c5fa0f | 2009-06-08 23:10:40 +0100 | [diff] [blame] | 320 | |
| 321 | /** |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 322 | * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify |
| 323 | * additional flags per item. Multiple flags can be specified. |
| 324 | * <p> |
| 325 | * Must be one of {@link #FLAG_QUERY_REFINEMENT} or 0 to indicate no flags. |
| 326 | * </p> |
| 327 | */ |
| 328 | public final static String SUGGEST_COLUMN_FLAGS = "suggest_flags"; |
| 329 | |
| 330 | /** |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 331 | * Column value for suggestion column {@link #SUGGEST_COLUMN_SHORTCUT_ID} when a suggestion |
| 332 | * should not be stored as a shortcut in global search. |
Karl Rosaen | b2a5011 | 2009-05-05 21:14:01 -0700 | [diff] [blame] | 333 | */ |
| 334 | public final static String SUGGEST_NEVER_MAKE_SHORTCUT = "_-1"; |
| 335 | |
| 336 | /** |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 337 | * Query parameter added to suggestion queries to limit the number of suggestions returned. |
Bjorn Bringert | 86917db | 2009-09-28 22:00:50 +0100 | [diff] [blame] | 338 | * This limit is only advisory and suggestion providers may chose to ignore it. |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 339 | */ |
| 340 | public final static String SUGGEST_PARAMETER_LIMIT = "limit"; |
| 341 | |
| 342 | /** |
Bjorn Bringert | 55f3ac5 | 2010-01-14 11:38:22 +0000 | [diff] [blame] | 343 | * Intent action for starting the global search activity. |
Bjorn Bringert | 74708bb | 2009-04-28 11:26:52 +0100 | [diff] [blame] | 344 | * The global search provider should handle this intent. |
Bjorn Bringert | 55f3ac5 | 2010-01-14 11:38:22 +0000 | [diff] [blame] | 345 | * |
| 346 | * Supported extra data keys: {@link #QUERY}, |
| 347 | * {@link #EXTRA_SELECT_QUERY}, |
| 348 | * {@link #APP_DATA}. |
Bjorn Bringert | 74708bb | 2009-04-28 11:26:52 +0100 | [diff] [blame] | 349 | */ |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 350 | public final static String INTENT_ACTION_GLOBAL_SEARCH |
Bjorn Bringert | 74708bb | 2009-04-28 11:26:52 +0100 | [diff] [blame] | 351 | = "android.search.action.GLOBAL_SEARCH"; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 352 | |
Bjorn Bringert | 74708bb | 2009-04-28 11:26:52 +0100 | [diff] [blame] | 353 | /** |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 354 | * Intent action for starting the global search settings activity. |
| 355 | * The global search provider should handle this intent. |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 356 | */ |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 357 | public final static String INTENT_ACTION_SEARCH_SETTINGS |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 358 | = "android.search.action.SEARCH_SETTINGS"; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 359 | |
Mike LeBeau | 3a27803 | 2009-06-04 14:09:42 +0100 | [diff] [blame] | 360 | /** |
| 361 | * Intent action for starting a web search provider's settings activity. |
| 362 | * Web search providers should handle this intent if they have provider-specific |
| 363 | * settings to implement. |
Mike LeBeau | 3a27803 | 2009-06-04 14:09:42 +0100 | [diff] [blame] | 364 | */ |
| 365 | public final static String INTENT_ACTION_WEB_SEARCH_SETTINGS |
| 366 | = "android.search.action.WEB_SEARCH_SETTINGS"; |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 367 | |
| 368 | /** |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 369 | * Intent action broadcasted to inform that the searchables list or default have changed. |
| 370 | * Components should handle this intent if they cache any searchable data and wish to stay |
| 371 | * up to date on changes. |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 372 | */ |
| 373 | public final static String INTENT_ACTION_SEARCHABLES_CHANGED |
| 374 | = "android.search.action.SEARCHABLES_CHANGED"; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 375 | |
Mike LeBeau | d4fb7a0 | 2009-07-20 17:37:38 -0700 | [diff] [blame] | 376 | /** |
| 377 | * Intent action broadcasted to inform that the search settings have changed in some way. |
Karl Rosaen | 590f634 | 2009-08-27 17:42:48 -0700 | [diff] [blame] | 378 | * Either searchables have been enabled or disabled, or a different web search provider |
| 379 | * has been chosen. |
Mike LeBeau | d4fb7a0 | 2009-07-20 17:37:38 -0700 | [diff] [blame] | 380 | */ |
| 381 | public final static String INTENT_ACTION_SEARCH_SETTINGS_CHANGED |
| 382 | = "android.search.action.SETTINGS_CHANGED"; |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 383 | |
| 384 | /** |
Leon Scroggins | 4f22a54 | 2010-03-09 17:28:13 -0500 | [diff] [blame] | 385 | * This means that context is voice, and therefore the SearchDialog should |
| 386 | * continue showing the microphone until the user indicates that he/she does |
| 387 | * not want to re-speak (e.g. by typing). |
| 388 | * |
| 389 | * @hide |
| 390 | */ |
| 391 | public final static String CONTEXT_IS_VOICE = "android.search.CONTEXT_IS_VOICE"; |
| 392 | |
| 393 | /** |
Leon Scroggins III | 4a02800 | 2010-09-14 10:56:25 -0400 | [diff] [blame] | 394 | * This means that the voice icon should not be shown at all, because the |
| 395 | * current search engine does not support voice search. |
| 396 | * @hide |
| 397 | */ |
| 398 | public final static String DISABLE_VOICE_SEARCH |
| 399 | = "android.search.DISABLE_VOICE_SEARCH"; |
| 400 | |
| 401 | /** |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 402 | * Reference to the shared system search service. |
| 403 | */ |
Bjorn Bringert | 8d15382 | 2009-06-22 10:31:44 +0100 | [diff] [blame] | 404 | private static ISearchManager mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | |
| 406 | private final Context mContext; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 407 | |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 408 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 409 | * The package associated with this seach manager. |
| 410 | */ |
| 411 | private String mAssociatedPackage; |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 412 | |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 413 | // package private since they are used by the inner class SearchManagerCallback |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 414 | /* package */ final Handler mHandler; |
| 415 | /* package */ OnDismissListener mDismissListener = null; |
| 416 | /* package */ OnCancelListener mCancelListener = null; |
| 417 | |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 418 | private SearchDialog mSearchDialog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | |
| 420 | /*package*/ SearchManager(Context context, Handler handler) { |
| 421 | mContext = context; |
| 422 | mHandler = handler; |
Bjorn Bringert | 8d15382 | 2009-06-22 10:31:44 +0100 | [diff] [blame] | 423 | mService = ISearchManager.Stub.asInterface( |
| 424 | ServiceManager.getService(Context.SEARCH_SERVICE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | } |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | /** |
| 428 | * Launch search UI. |
| 429 | * |
| 430 | * <p>The search manager will open a search widget in an overlapping |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 431 | * window, and the underlying activity may be obscured. The search |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | * entry state will remain in effect until one of the following events: |
| 433 | * <ul> |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 434 | * <li>The user completes the search. In most cases this will launch |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | * a search intent.</li> |
| 436 | * <li>The user uses the back, home, or other keys to exit the search.</li> |
| 437 | * <li>The application calls the {@link #stopSearch} |
| 438 | * method, which will hide the search window and return focus to the |
| 439 | * activity from which it was launched.</li> |
| 440 | * |
| 441 | * <p>Most applications will <i>not</i> use this interface to invoke search. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 442 | * The primary method for invoking search is to call |
| 443 | * {@link android.app.Activity#onSearchRequested Activity.onSearchRequested()} or |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | * {@link android.app.Activity#startSearch Activity.startSearch()}. |
| 445 | * |
| 446 | * @param initialQuery A search string can be pre-entered here, but this |
| 447 | * is typically null or empty. |
| 448 | * @param selectInitialQuery If true, the intial query will be preselected, which means that |
| 449 | * any further typing will replace it. This is useful for cases where an entire pre-formed |
| 450 | * query is being inserted. If false, the selection point will be placed at the end of the |
| 451 | * inserted query. This is useful when the inserted query is text that the user entered, |
| 452 | * and the user would expect to be able to keep typing. <i>This parameter is only meaningful |
| 453 | * if initialQuery is a non-empty string.</i> |
| 454 | * @param launchActivity The ComponentName of the activity that has launched this search. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 455 | * @param appSearchData An application can insert application-specific |
| 456 | * context here, in order to improve quality or specificity of its own |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 458 | * no extra data is required. |
| 459 | * @param globalSearch If false, this will only launch the search that has been specifically |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 460 | * defined by the application (which is usually defined as a local search). If no default |
Mike LeBeau | cfa419b | 2009-08-17 10:56:02 -0700 | [diff] [blame] | 461 | * search is defined in the current application or activity, global search will be launched. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | * If true, this will always launch a platform-global (e.g. web-based) search instead. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 463 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | * @see android.app.Activity#onSearchRequested |
| 465 | * @see #stopSearch |
| 466 | */ |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 467 | public void startSearch(String initialQuery, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | boolean selectInitialQuery, |
| 469 | ComponentName launchActivity, |
| 470 | Bundle appSearchData, |
| 471 | boolean globalSearch) { |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 472 | if (globalSearch) { |
| 473 | startGlobalSearch(initialQuery, selectInitialQuery, appSearchData); |
| 474 | return; |
| 475 | } |
| 476 | |
Amith Yamasani | 479ae0a | 2010-02-04 14:52:32 -0800 | [diff] [blame] | 477 | ensureSearchDialog(); |
| 478 | |
| 479 | mSearchDialog.show(initialQuery, selectInitialQuery, launchActivity, appSearchData); |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | private void ensureSearchDialog() { |
| 483 | if (mSearchDialog == null) { |
| 484 | mSearchDialog = new SearchDialog(mContext, this); |
| 485 | mSearchDialog.setOnCancelListener(this); |
| 486 | mSearchDialog.setOnDismissListener(this); |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 491 | * Starts the global search activity. |
| 492 | */ |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 493 | /* package */ void startGlobalSearch(String initialQuery, boolean selectInitialQuery, |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 494 | Bundle appSearchData) { |
| 495 | ComponentName globalSearchActivity = getGlobalSearchActivity(); |
| 496 | if (globalSearchActivity == null) { |
| 497 | Log.w(TAG, "No global search activity found."); |
| 498 | return; |
| 499 | } |
Bjorn Bringert | a94e7af | 2010-01-13 21:09:20 +0000 | [diff] [blame] | 500 | Intent intent = new Intent(INTENT_ACTION_GLOBAL_SEARCH); |
Bjorn Bringert | b8144a9 | 2010-02-22 20:48:57 +0000 | [diff] [blame] | 501 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 502 | intent.setComponent(globalSearchActivity); |
Bjorn Bringert | 3c24cb7 | 2010-03-16 12:54:41 +0000 | [diff] [blame] | 503 | // Make sure that we have a Bundle to put source in |
| 504 | if (appSearchData == null) { |
| 505 | appSearchData = new Bundle(); |
| 506 | } else { |
| 507 | appSearchData = new Bundle(appSearchData); |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 508 | } |
Bjorn Bringert | 3c24cb7 | 2010-03-16 12:54:41 +0000 | [diff] [blame] | 509 | // Set source to package name of app that starts global search, if not set already. |
| 510 | if (!appSearchData.containsKey("source")) { |
| 511 | appSearchData.putString("source", mContext.getPackageName()); |
| 512 | } |
| 513 | intent.putExtra(APP_DATA, appSearchData); |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 514 | if (!TextUtils.isEmpty(initialQuery)) { |
Bjorn Bringert | 55f3ac5 | 2010-01-14 11:38:22 +0000 | [diff] [blame] | 515 | intent.putExtra(QUERY, initialQuery); |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 516 | } |
| 517 | if (selectInitialQuery) { |
Bjorn Bringert | 55f3ac5 | 2010-01-14 11:38:22 +0000 | [diff] [blame] | 518 | intent.putExtra(EXTRA_SELECT_QUERY, selectInitialQuery); |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 519 | } |
| 520 | try { |
| 521 | if (DBG) Log.d(TAG, "Starting global search: " + intent.toUri(0)); |
| 522 | mContext.startActivity(intent); |
| 523 | } catch (ActivityNotFoundException ex) { |
| 524 | Log.e(TAG, "Global search activity not found: " + globalSearchActivity); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * Gets the name of the global search activity. |
| 530 | * |
Bjorn Bringert | 38015f3 | 2010-01-14 14:56:18 +0000 | [diff] [blame] | 531 | * @hide |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 532 | */ |
Bjorn Bringert | 38015f3 | 2010-01-14 14:56:18 +0000 | [diff] [blame] | 533 | public ComponentName getGlobalSearchActivity() { |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 534 | try { |
| 535 | return mService.getGlobalSearchActivity(); |
| 536 | } catch (RemoteException ex) { |
| 537 | Log.e(TAG, "getGlobalSearchActivity() failed: " + ex); |
| 538 | return null; |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 539 | } |
Bjorn Bringert | 3c50ef6 | 2009-12-09 12:23:12 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
Bjorn Bringert | ea125f4 | 2010-02-18 21:57:59 +0000 | [diff] [blame] | 543 | * Gets the name of the web search activity. |
| 544 | * |
| 545 | * @return The name of the default activity for web searches. This activity |
| 546 | * can be used to get web search suggestions. Returns {@code null} if |
| 547 | * there is no default web search activity. |
| 548 | * |
| 549 | * @hide |
| 550 | */ |
| 551 | public ComponentName getWebSearchActivity() { |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 552 | try { |
| 553 | return mService.getWebSearchActivity(); |
| 554 | } catch (RemoteException ex) { |
| 555 | Log.e(TAG, "getWebSearchActivity() failed: " + ex); |
Bjorn Bringert | ea125f4 | 2010-02-18 21:57:59 +0000 | [diff] [blame] | 556 | return null; |
| 557 | } |
Bjorn Bringert | ea125f4 | 2010-02-18 21:57:59 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /** |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 561 | * Similar to {@link #startSearch} but actually fires off the search query after invoking |
| 562 | * the search dialog. Made available for testing purposes. |
| 563 | * |
| 564 | * @param query The query to trigger. If empty, request will be ignored. |
| 565 | * @param launchActivity The ComponentName of the activity that has launched this search. |
| 566 | * @param appSearchData An application can insert application-specific |
| 567 | * context here, in order to improve quality or specificity of its own |
| 568 | * searches. This data will be returned with SEARCH intent(s). Null if |
| 569 | * no extra data is required. |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 570 | * |
| 571 | * @see #startSearch |
| 572 | */ |
| 573 | public void triggerSearch(String query, |
| 574 | ComponentName launchActivity, |
Bjorn Bringert | b782a2f | 2009-10-01 09:57:33 +0100 | [diff] [blame] | 575 | Bundle appSearchData) { |
krosaen | d2d6014 | 2009-08-17 08:56:48 -0700 | [diff] [blame] | 576 | if (!mAssociatedPackage.equals(launchActivity.getPackageName())) { |
| 577 | throw new IllegalArgumentException("invoking app search on a different package " + |
| 578 | "not associated with this search manager"); |
| 579 | } |
| 580 | if (query == null || TextUtils.getTrimmedLength(query) == 0) { |
| 581 | Log.w(TAG, "triggerSearch called with empty query, ignoring."); |
| 582 | return; |
| 583 | } |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 584 | startSearch(query, false, launchActivity, appSearchData, false); |
| 585 | mSearchDialog.launchQuerySearch(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Terminate search UI. |
| 590 | * |
| 591 | * <p>Typically the user will terminate the search UI by launching a |
| 592 | * search or by canceling. This function allows the underlying application |
| 593 | * or activity to cancel the search prematurely (for any reason). |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 594 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | * <p>This function can be safely called at any time (even if no search is active.) |
| 596 | * |
| 597 | * @see #startSearch |
| 598 | */ |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 599 | public void stopSearch() { |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 600 | if (mSearchDialog != null) { |
| 601 | mSearchDialog.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
| 605 | /** |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 606 | * Determine if the Search UI is currently displayed. |
| 607 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | * This is provided primarily for application test purposes. |
| 609 | * |
| 610 | * @return Returns true if the search UI is currently displayed. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 611 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | * @hide |
| 613 | */ |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 614 | public boolean isVisible() { |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 615 | return mSearchDialog == null? false : mSearchDialog.isShowing(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | } |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | /** |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 619 | * See {@link SearchManager#setOnDismissListener} for configuring your activity to monitor |
| 620 | * search UI state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | */ |
| 622 | public interface OnDismissListener { |
| 623 | /** |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 624 | * This method will be called when the search UI is dismissed. To make use of it, you must |
| 625 | * implement this method in your activity, and call |
| 626 | * {@link SearchManager#setOnDismissListener} to register it. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | */ |
| 628 | public void onDismiss(); |
| 629 | } |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | /** |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 632 | * See {@link SearchManager#setOnCancelListener} for configuring your activity to monitor |
| 633 | * search UI state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | */ |
| 635 | public interface OnCancelListener { |
| 636 | /** |
| 637 | * This method will be called when the search UI is canceled. To make use if it, you must |
Karl Rosaen | a058f02 | 2009-06-01 23:11:44 +0100 | [diff] [blame] | 638 | * implement this method in your activity, and call |
| 639 | * {@link SearchManager#setOnCancelListener} to register it. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | */ |
| 641 | public void onCancel(); |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Set or clear the callback that will be invoked whenever the search UI is dismissed. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 646 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | * @param listener The {@link OnDismissListener} to use, or null. |
| 648 | */ |
| 649 | public void setOnDismissListener(final OnDismissListener listener) { |
| 650 | mDismissListener = listener; |
| 651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | |
| 653 | /** |
| 654 | * Set or clear the callback that will be invoked whenever the search UI is canceled. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 655 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | * @param listener The {@link OnCancelListener} to use, or null. |
| 657 | */ |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 658 | public void setOnCancelListener(OnCancelListener listener) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | mCancelListener = listener; |
| 660 | } |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 661 | |
Bjorn Bringert | 0e01ea4 | 2009-07-08 22:01:29 +0100 | [diff] [blame] | 662 | /** |
| 663 | * @deprecated This method is an obsolete internal implementation detail. Do not use. |
| 664 | */ |
Dianne Hackborn | 4a51c20 | 2009-08-21 15:14:02 -0700 | [diff] [blame] | 665 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | public void onCancel(DialogInterface dialog) { |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 667 | if (mCancelListener != null) { |
| 668 | mCancelListener.onCancel(); |
| 669 | } |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 670 | } |
Bjorn Bringert | 0e01ea4 | 2009-07-08 22:01:29 +0100 | [diff] [blame] | 671 | |
| 672 | /** |
| 673 | * @deprecated This method is an obsolete internal implementation detail. Do not use. |
| 674 | */ |
Dianne Hackborn | 4a51c20 | 2009-08-21 15:14:02 -0700 | [diff] [blame] | 675 | @Deprecated |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 676 | public void onDismiss(DialogInterface dialog) { |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 677 | if (mDismissListener != null) { |
| 678 | mDismissListener.onDismiss(); |
| 679 | } |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /** |
Bjorn Bringert | 0408675 | 2010-01-12 15:50:04 +0000 | [diff] [blame] | 683 | * Gets information about a searchable activity. |
| 684 | * |
| 685 | * @param componentName The activity to get searchable information for. |
| 686 | * @return Searchable information, or <code>null</code> if the activity does not |
| 687 | * exist, or is not searchable. |
| 688 | */ |
| 689 | public SearchableInfo getSearchableInfo(ComponentName componentName) { |
| 690 | try { |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 691 | return mService.getSearchableInfo(componentName); |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 692 | } catch (RemoteException ex) { |
| 693 | Log.e(TAG, "getSearchableInfo() failed: " + ex); |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 694 | return null; |
| 695 | } |
| 696 | } |
Bjorn Bringert | 8d15382 | 2009-06-22 10:31:44 +0100 | [diff] [blame] | 697 | |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 698 | /** |
Bjorn Bringert | 97325db | 2009-06-22 11:37:03 +0100 | [diff] [blame] | 699 | * Gets a cursor with search suggestions. |
| 700 | * |
| 701 | * @param searchable Information about how to get the suggestions. |
| 702 | * @param query The search text entered (so far). |
| 703 | * @return a cursor with suggestions, or <code>null</null> the suggestion query failed. |
| 704 | * |
| 705 | * @hide because SearchableInfo is not part of the API. |
| 706 | */ |
| 707 | public Cursor getSuggestions(SearchableInfo searchable, String query) { |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 708 | return getSuggestions(searchable, query, -1); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Gets a cursor with search suggestions. |
| 713 | * |
| 714 | * @param searchable Information about how to get the suggestions. |
| 715 | * @param query The search text entered (so far). |
| 716 | * @param limit The query limit to pass to the suggestion provider. This is advisory, |
| 717 | * the returned cursor may contain more rows. Pass {@code -1} for no limit. |
| 718 | * @return a cursor with suggestions, or <code>null</null> the suggestion query failed. |
| 719 | * |
| 720 | * @hide because SearchableInfo is not part of the API. |
| 721 | */ |
| 722 | public Cursor getSuggestions(SearchableInfo searchable, String query, int limit) { |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 723 | if (searchable == null) { |
| 724 | return null; |
| 725 | } |
| 726 | |
| 727 | String authority = searchable.getSuggestAuthority(); |
| 728 | if (authority == null) { |
| 729 | return null; |
| 730 | } |
| 731 | |
| 732 | Uri.Builder uriBuilder = new Uri.Builder() |
| 733 | .scheme(ContentResolver.SCHEME_CONTENT) |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 734 | .authority(authority) |
| 735 | .query("") // TODO: Remove, workaround for a bug in Uri.writeToParcel() |
| 736 | .fragment(""); // TODO: Remove, workaround for a bug in Uri.writeToParcel() |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 737 | |
| 738 | // if content path provided, insert it now |
| 739 | final String contentPath = searchable.getSuggestPath(); |
| 740 | if (contentPath != null) { |
| 741 | uriBuilder.appendEncodedPath(contentPath); |
| 742 | } |
| 743 | |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 744 | // append standard suggestion query path |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 745 | uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY); |
| 746 | |
| 747 | // get the query selection, may be null |
| 748 | String selection = searchable.getSuggestSelection(); |
| 749 | // inject query, either as selection args or inline |
| 750 | String[] selArgs = null; |
| 751 | if (selection != null) { // use selection if provided |
| 752 | selArgs = new String[] { query }; |
| 753 | } else { // no selection, use REST pattern |
| 754 | uriBuilder.appendPath(query); |
| 755 | } |
| 756 | |
Bjorn Bringert | 3fc7c67 | 2009-09-28 20:11:52 +0100 | [diff] [blame] | 757 | if (limit > 0) { |
| 758 | uriBuilder.appendQueryParameter(SUGGEST_PARAMETER_LIMIT, String.valueOf(limit)); |
| 759 | } |
| 760 | |
| 761 | Uri uri = uriBuilder.build(); |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 762 | |
| 763 | // finally, make the query |
Bjorn Bringert | 8d15382 | 2009-06-22 10:31:44 +0100 | [diff] [blame] | 764 | return mContext.getContentResolver().query(uri, null, selection, selArgs, null); |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 765 | } |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 766 | |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 767 | /** |
| 768 | * Returns a list of the searchable activities that can be included in global search. |
Amith Yamasani | e678f46 | 2010-09-15 16:13:43 -0700 | [diff] [blame] | 769 | * |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 770 | * @return a list containing searchable information for all searchable activities |
Bjorn Bringert | 13107bb | 2009-12-07 10:41:24 +0000 | [diff] [blame] | 771 | * that have the <code>android:includeInGlobalSearch</code> attribute set |
| 772 | * in their searchable meta-data. |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 773 | */ |
Bjorn Bringert | 8d15382 | 2009-06-22 10:31:44 +0100 | [diff] [blame] | 774 | public List<SearchableInfo> getSearchablesInGlobalSearch() { |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 775 | try { |
Bjorn Bringert | 8d15382 | 2009-06-22 10:31:44 +0100 | [diff] [blame] | 776 | return mService.getSearchablesInGlobalSearch(); |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 777 | } catch (RemoteException e) { |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 778 | Log.e(TAG, "getSearchablesInGlobalSearch() failed: " + e); |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 779 | return null; |
| 780 | } |
| 781 | } |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 782 | |
Amith Yamasani | e9ce3f0 | 2010-01-25 09:15:50 -0800 | [diff] [blame] | 783 | } |