blob: 5482f605ec8fc6281cb8bd02a7f7d502a0e00693 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Bjorn Bringert2126aac2009-12-03 15:48:19 +000017package android.app;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19import org.xmlpull.v1.XmlPullParser;
20import org.xmlpull.v1.XmlPullParserException;
21
22import android.content.ComponentName;
23import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.pm.ActivityInfo;
25import android.content.pm.PackageManager;
26import android.content.pm.ProviderInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.res.TypedArray;
28import android.content.res.XmlResourceParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.Parcel;
30import android.os.Parcelable;
31import android.text.InputType;
32import android.util.AttributeSet;
33import android.util.Log;
34import android.util.Xml;
35import android.view.inputmethod.EditorInfo;
36
37import java.io.IOException;
Bjorn Bringerta9204132009-05-05 14:06:35 +010038import java.util.HashMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Bjorn Bringert2126aac2009-12-03 15:48:19 +000040/**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010041 * Searchability meta-data for an activity. Only applications that search other applications
42 * should need to use this class.
43 * See <a href="{@docRoot}guide/topics/search/searchable-config.html">Searchable Configuration</a>
44 * for more information about declaring searchability meta-data for your application.
45 *
46 * @see SearchManager#getSearchableInfo(ComponentName)
47 * @see SearchManager#getSearchablesInGlobalSearch()
Bjorn Bringert2126aac2009-12-03 15:48:19 +000048 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049public final class SearchableInfo implements Parcelable {
50
51 // general debugging support
Mike LeBeau0f7e9142009-06-04 15:07:24 +010052 private static final boolean DBG = false;
Bjorn Bringerta9204132009-05-05 14:06:35 +010053 private static final String LOG_TAG = "SearchableInfo";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
Karl Rosaen875d50a2009-04-23 19:00:21 -070055 // static strings used for XML lookups.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 // TODO how should these be documented for the developer, in a more structured way than
57 // the current long wordy javadoc in SearchManager.java ?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 private static final String MD_LABEL_SEARCHABLE = "android.app.searchable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 private static final String MD_XML_ELEMENT_SEARCHABLE = "searchable";
60 private static final String MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY = "actionkey";
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010061
Bjorn Bringerta9204132009-05-05 14:06:35 +010062 // flags in the searchMode attribute
63 private static final int SEARCH_MODE_BADGE_LABEL = 0x04;
64 private static final int SEARCH_MODE_BADGE_ICON = 0x08;
65 private static final int SEARCH_MODE_QUERY_REWRITE_FROM_DATA = 0x10;
66 private static final int SEARCH_MODE_QUERY_REWRITE_FROM_TEXT = 0x20;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 // true member variables - what we know about the searchability
Bjorn Bringerta9204132009-05-05 14:06:35 +010069 private final int mLabelId;
70 private final ComponentName mSearchActivity;
71 private final int mHintId;
72 private final int mSearchMode;
73 private final int mIconId;
74 private final int mSearchButtonText;
75 private final int mSearchInputType;
76 private final int mSearchImeOptions;
77 private final boolean mIncludeInGlobalSearch;
Satish Sampath35379ab2009-06-11 14:05:51 +010078 private final boolean mQueryAfterZeroResults;
Satish Sampathd21572c2009-07-08 14:54:11 +010079 private final boolean mAutoUrlDetect;
Bjorn Bringert23897c12010-02-10 16:10:54 +000080 private final int mSettingsDescriptionId;
Bjorn Bringerta9204132009-05-05 14:06:35 +010081 private final String mSuggestAuthority;
82 private final String mSuggestPath;
83 private final String mSuggestSelection;
84 private final String mSuggestIntentAction;
85 private final String mSuggestIntentData;
86 private final int mSuggestThreshold;
87 // Maps key codes to action key information. auto-boxing is not so bad here,
88 // since keycodes for the hard keys are < 127. For such values, Integer.valueOf()
89 // uses shared Integer objects.
90 // This is not final, to allow lazy initialization.
91 private HashMap<Integer,ActionKeyInfo> mActionKeys = null;
92 private final String mSuggestProviderPackage;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 // Flag values for Searchable_voiceSearchMode
Bjorn Bringert13107bb2009-12-07 10:41:24 +000095 private static final int VOICE_SEARCH_SHOW_BUTTON = 1;
96 private static final int VOICE_SEARCH_LAUNCH_WEB_SEARCH = 2;
97 private static final int VOICE_SEARCH_LAUNCH_RECOGNIZER = 4;
Bjorn Bringerta9204132009-05-05 14:06:35 +010098 private final int mVoiceSearchMode;
99 private final int mVoiceLanguageModeId; // voiceLanguageModel
100 private final int mVoicePromptTextId; // voicePromptText
101 private final int mVoiceLanguageId; // voiceLanguage
102 private final int mVoiceMaxResults; // voiceMaxResults
Karl Rosaen875d50a2009-04-23 19:00:21 -0700103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100105 * Gets the search suggestion content provider authority.
106 *
107 * @return The search suggestions authority, or {@code null} if not set.
108 * @see android.R.styleable#Searchable_searchSuggestAuthority
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 */
110 public String getSuggestAuthority() {
111 return mSuggestAuthority;
112 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100113
114 /**
Bjorn Bringert83dba192009-07-30 13:58:23 +0100115 * Gets the name of the package where the suggestion provider lives,
116 * or {@code null}.
117 */
118 public String getSuggestPackage() {
119 return mSuggestProviderPackage;
120 }
121
122 /**
Bjorn Bringerta9204132009-05-05 14:06:35 +0100123 * Gets the component name of the searchable activity.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100124 *
125 * @return A component name, never {@code null}.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100126 */
127 public ComponentName getSearchActivity() {
128 return mSearchActivity;
129 }
130
131 /**
132 * Checks whether the badge should be a text label.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000133 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100134 * @see android.R.styleable#Searchable_searchMode
135 *
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000136 * @hide This feature is deprecated, no need to add it to the API.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100137 */
138 public boolean useBadgeLabel() {
139 return 0 != (mSearchMode & SEARCH_MODE_BADGE_LABEL);
140 }
141
142 /**
143 * Checks whether the badge should be an icon.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000144 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100145 * @see android.R.styleable#Searchable_searchMode
146 *
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000147 * @hide This feature is deprecated, no need to add it to the API.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100148 */
149 public boolean useBadgeIcon() {
150 return (0 != (mSearchMode & SEARCH_MODE_BADGE_ICON)) && (mIconId != 0);
151 }
152
153 /**
154 * Checks whether the text in the query field should come from the suggestion intent data.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100155 *
156 * @see android.R.styleable#Searchable_searchMode
Bjorn Bringerta9204132009-05-05 14:06:35 +0100157 */
158 public boolean shouldRewriteQueryFromData() {
159 return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_DATA);
160 }
161
162 /**
163 * Checks whether the text in the query field should come from the suggestion title.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100164 *
165 * @see android.R.styleable#Searchable_searchMode
Bjorn Bringerta9204132009-05-05 14:06:35 +0100166 */
167 public boolean shouldRewriteQueryFromText() {
168 return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_TEXT);
169 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100170
Mike LeBeau735b3332009-06-30 18:27:40 -0700171 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100172 * Gets the resource id of the description string to use for this source in system search
Bjorn Bringert23897c12010-02-10 16:10:54 +0000173 * settings, or {@code 0} if none has been specified.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100174 *
175 * @see android.R.styleable#Searchable_searchSettingsDescription
Mike LeBeau735b3332009-06-30 18:27:40 -0700176 */
Bjorn Bringert23897c12010-02-10 16:10:54 +0000177 public int getSettingsDescriptionId() {
178 return mSettingsDescriptionId;
Mike LeBeau735b3332009-06-30 18:27:40 -0700179 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100182 * Gets the content provider path for obtaining search suggestions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100184 * @return The suggestion path, or {@code null} if not set.
185 * @see android.R.styleable#Searchable_searchSuggestPath
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 */
187 public String getSuggestPath() {
188 return mSuggestPath;
189 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100192 * Gets the selection for obtaining search suggestions.
193 *
194 * @see android.R.styleable#Searchable_searchSuggestSelection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 */
196 public String getSuggestSelection() {
197 return mSuggestSelection;
198 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100201 * Gets the optional intent action for use with these suggestions. This is
202 * useful if all intents will have the same action
203 * (e.g. {@link android.content.Intent#ACTION_VIEW})
204 *
205 * This can be overriden in any given suggestion using the column
206 * {@link SearchManager#SUGGEST_COLUMN_INTENT_ACTION}.
207 *
208 * @return The default intent action, or {@code null} if not set.
209 * @see android.R.styleable#Searchable_searchSuggestIntentAction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 */
211 public String getSuggestIntentAction() {
212 return mSuggestIntentAction;
213 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100216 * Gets the optional intent data for use with these suggestions. This is
217 * useful if all intents will have similar data URIs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 * but you'll likely need to provide a specific ID as well via the column
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100219 * {@link SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID}, which will be appended to the
220 * intent data URI.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100222 * This can be overriden in any given suggestion using the column
223 * {@link SearchManager#SUGGEST_COLUMN_INTENT_DATA}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100225 * @return The default intent data, or {@code null} if not set.
226 * @see android.R.styleable#Searchable_searchSuggestIntentData
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 */
228 public String getSuggestIntentData() {
229 return mSuggestIntentData;
230 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100233 * Gets the suggestion threshold.
Bjorn Bringert203464a2009-04-27 17:08:11 +0100234 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100235 * @return The suggestion threshold, or {@code 0} if not set.
236 * @see android.R.styleable#Searchable_searchSuggestThreshold
Bjorn Bringert203464a2009-04-27 17:08:11 +0100237 */
238 public int getSuggestThreshold() {
239 return mSuggestThreshold;
240 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100241
Bjorn Bringert203464a2009-04-27 17:08:11 +0100242 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100243 * Get the context for the searchable activity.
244 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 * @param context You need to supply a context to start with
246 * @return Returns a context related to the searchable activity
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000247 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 */
249 public Context getActivityContext(Context context) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700250 return createActivityContext(context, mSearchActivity);
251 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100252
Karl Rosaen875d50a2009-04-23 19:00:21 -0700253 /**
254 * Creates a context for another activity.
255 */
256 private static Context createActivityContext(Context context, ComponentName activity) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 Context theirContext = null;
258 try {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700259 theirContext = context.createPackageContext(activity.getPackageName(), 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 } catch (PackageManager.NameNotFoundException e) {
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100261 Log.e(LOG_TAG, "Package not found " + activity.getPackageName());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 } catch (java.lang.SecurityException e) {
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100263 Log.e(LOG_TAG, "Can't make context for " + activity.getPackageName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 }
265
266 return theirContext;
267 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100270 * Get the context for the suggestions provider.
271 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 * @param context You need to supply a context to start with
273 * @param activityContext If we can determine that the provider and the activity are the
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100274 * same, we'll just return this one.
275 * @return Returns a context related to the suggestion provider
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000276 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 */
278 public Context getProviderContext(Context context, Context activityContext) {
279 Context theirContext = null;
280 if (mSearchActivity.getPackageName().equals(mSuggestProviderPackage)) {
281 return activityContext;
282 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100283 if (mSuggestProviderPackage != null) {
284 try {
285 theirContext = context.createPackageContext(mSuggestProviderPackage, 0);
286 } catch (PackageManager.NameNotFoundException e) {
287 // unexpected, but we deal with this by null-checking theirContext
288 } catch (java.lang.SecurityException e) {
289 // unexpected, but we deal with this by null-checking theirContext
290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 return theirContext;
293 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 * Constructor
297 *
298 * Given a ComponentName, get the searchability info
299 * and build a local copy of it. Use the factory, not this.
300 *
Karl Rosaen875d50a2009-04-23 19:00:21 -0700301 * @param activityContext runtime context for the activity that the searchable info is about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 * @param attr The attribute set we found in the XML file, contains the values that are used to
303 * construct the object.
304 * @param cName The component name of the searchable activity
Bjorn Bringerta9204132009-05-05 14:06:35 +0100305 * @throws IllegalArgumentException if the searchability info is invalid or insufficient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 */
Karl Rosaen875d50a2009-04-23 19:00:21 -0700307 private SearchableInfo(Context activityContext, AttributeSet attr, final ComponentName cName) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 mSearchActivity = cName;
309
Karl Rosaen875d50a2009-04-23 19:00:21 -0700310 TypedArray a = activityContext.obtainStyledAttributes(attr,
311 com.android.internal.R.styleable.Searchable);
312 mSearchMode = a.getInt(com.android.internal.R.styleable.Searchable_searchMode, 0);
313 mLabelId = a.getResourceId(com.android.internal.R.styleable.Searchable_label, 0);
314 mHintId = a.getResourceId(com.android.internal.R.styleable.Searchable_hint, 0);
315 mIconId = a.getResourceId(com.android.internal.R.styleable.Searchable_icon, 0);
316 mSearchButtonText = a.getResourceId(
317 com.android.internal.R.styleable.Searchable_searchButtonText, 0);
318 mSearchInputType = a.getInt(com.android.internal.R.styleable.Searchable_inputType,
319 InputType.TYPE_CLASS_TEXT |
320 InputType.TYPE_TEXT_VARIATION_NORMAL);
321 mSearchImeOptions = a.getInt(com.android.internal.R.styleable.Searchable_imeOptions,
Amith Yamasani747d2d42010-03-12 15:42:45 -0800322 EditorInfo.IME_ACTION_GO);
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100323 mIncludeInGlobalSearch = a.getBoolean(
324 com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false);
Satish Sampath35379ab2009-06-11 14:05:51 +0100325 mQueryAfterZeroResults = a.getBoolean(
326 com.android.internal.R.styleable.Searchable_queryAfterZeroResults, false);
Satish Sampathd21572c2009-07-08 14:54:11 +0100327 mAutoUrlDetect = a.getBoolean(
328 com.android.internal.R.styleable.Searchable_autoUrlDetect, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
Bjorn Bringert23897c12010-02-10 16:10:54 +0000330 mSettingsDescriptionId = a.getResourceId(
331 com.android.internal.R.styleable.Searchable_searchSettingsDescription, 0);
Bjorn Bringerta9204132009-05-05 14:06:35 +0100332 mSuggestAuthority = a.getString(
333 com.android.internal.R.styleable.Searchable_searchSuggestAuthority);
334 mSuggestPath = a.getString(
335 com.android.internal.R.styleable.Searchable_searchSuggestPath);
336 mSuggestSelection = a.getString(
337 com.android.internal.R.styleable.Searchable_searchSuggestSelection);
338 mSuggestIntentAction = a.getString(
339 com.android.internal.R.styleable.Searchable_searchSuggestIntentAction);
340 mSuggestIntentData = a.getString(
341 com.android.internal.R.styleable.Searchable_searchSuggestIntentData);
342 mSuggestThreshold = a.getInt(
343 com.android.internal.R.styleable.Searchable_searchSuggestThreshold, 0);
344
Karl Rosaen875d50a2009-04-23 19:00:21 -0700345 mVoiceSearchMode =
346 a.getInt(com.android.internal.R.styleable.Searchable_voiceSearchMode, 0);
347 // TODO this didn't work - came back zero from YouTube
348 mVoiceLanguageModeId =
349 a.getResourceId(com.android.internal.R.styleable.Searchable_voiceLanguageModel, 0);
350 mVoicePromptTextId =
351 a.getResourceId(com.android.internal.R.styleable.Searchable_voicePromptText, 0);
352 mVoiceLanguageId =
353 a.getResourceId(com.android.internal.R.styleable.Searchable_voiceLanguage, 0);
354 mVoiceMaxResults =
355 a.getInt(com.android.internal.R.styleable.Searchable_voiceMaxResults, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356
Karl Rosaen875d50a2009-04-23 19:00:21 -0700357 a.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358
Karl Rosaen875d50a2009-04-23 19:00:21 -0700359 // get package info for suggestions provider (if any)
Bjorn Bringerta9204132009-05-05 14:06:35 +0100360 String suggestProviderPackage = null;
Karl Rosaen875d50a2009-04-23 19:00:21 -0700361 if (mSuggestAuthority != null) {
362 PackageManager pm = activityContext.getPackageManager();
363 ProviderInfo pi = pm.resolveContentProvider(mSuggestAuthority, 0);
364 if (pi != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100365 suggestProviderPackage = pi.packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100368 mSuggestProviderPackage = suggestProviderPackage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369
370 // for now, implement some form of rules - minimal data
Bjorn Bringerta9204132009-05-05 14:06:35 +0100371 if (mLabelId == 0) {
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100372 throw new IllegalArgumentException("Search label must be a resource reference.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 }
374 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 /**
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000377 * Information about an action key in searchability meta-data.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000378 *
379 * @see SearchableInfo#findActionKey(int)
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100380 *
381 * @hide This feature is used very little, and on many devices there are no reasonable
382 * keys to use for actions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 */
Karl Rosaen875d50a2009-04-23 19:00:21 -0700384 public static class ActionKeyInfo implements Parcelable {
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100385
Bjorn Bringerta9204132009-05-05 14:06:35 +0100386 private final int mKeyCode;
387 private final String mQueryActionMsg;
388 private final String mSuggestActionMsg;
389 private final String mSuggestActionMsgColumn;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 /**
392 * Create one object using attributeset as input data.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700393 * @param activityContext runtime context of the activity that the action key information
394 * is about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 * @param attr The attribute set we found in the XML file, contains the values that are used to
396 * construct the object.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100397 * @throws IllegalArgumentException if the action key configuration is invalid
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000399 ActionKeyInfo(Context activityContext, AttributeSet attr) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700400 TypedArray a = activityContext.obtainStyledAttributes(attr,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 com.android.internal.R.styleable.SearchableActionKey);
402
403 mKeyCode = a.getInt(
404 com.android.internal.R.styleable.SearchableActionKey_keycode, 0);
405 mQueryActionMsg = a.getString(
406 com.android.internal.R.styleable.SearchableActionKey_queryActionMsg);
Bjorn Bringerta9204132009-05-05 14:06:35 +0100407 mSuggestActionMsg = a.getString(
408 com.android.internal.R.styleable.SearchableActionKey_suggestActionMsg);
409 mSuggestActionMsgColumn = a.getString(
410 com.android.internal.R.styleable.SearchableActionKey_suggestActionMsgColumn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 a.recycle();
412
Bjorn Bringerta9204132009-05-05 14:06:35 +0100413 // sanity check.
414 if (mKeyCode == 0) {
415 throw new IllegalArgumentException("No keycode.");
416 } else if ((mQueryActionMsg == null) &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 (mSuggestActionMsg == null) &&
418 (mSuggestActionMsgColumn == null)) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100419 throw new IllegalArgumentException("No message information.");
420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 }
422
423 /**
424 * Instantiate a new ActionKeyInfo from the data in a Parcel that was
425 * previously written with {@link #writeToParcel(Parcel, int)}.
426 *
427 * @param in The Parcel containing the previously written ActionKeyInfo,
428 * positioned at the location in the buffer where it was written.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000430 private ActionKeyInfo(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 mKeyCode = in.readInt();
432 mQueryActionMsg = in.readString();
433 mSuggestActionMsg = in.readString();
434 mSuggestActionMsgColumn = in.readString();
Bjorn Bringerta9204132009-05-05 14:06:35 +0100435 }
436
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100437 /**
438 * Gets the key code that this action key info is for.
439 * @see android.R.styleable#SearchableActionKey_keycode
440 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100441 public int getKeyCode() {
442 return mKeyCode;
443 }
444
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100445 /**
446 * Gets the action message to use for queries.
447 * @see android.R.styleable#SearchableActionKey_queryActionMsg
448 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100449 public String getQueryActionMsg() {
450 return mQueryActionMsg;
451 }
452
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100453 /**
454 * Gets the action message to use for suggestions.
455 * @see android.R.styleable#SearchableActionKey_suggestActionMsg
456 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100457 public String getSuggestActionMsg() {
458 return mSuggestActionMsg;
459 }
460
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100461 /**
462 * Gets the name of the column to get the suggestion action message from.
463 * @see android.R.styleable#SearchableActionKey_suggestActionMsgColumn
464 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100465 public String getSuggestActionMsgColumn() {
466 return mSuggestActionMsgColumn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 }
468
469 public int describeContents() {
470 return 0;
471 }
472
473 public void writeToParcel(Parcel dest, int flags) {
474 dest.writeInt(mKeyCode);
475 dest.writeString(mQueryActionMsg);
476 dest.writeString(mSuggestActionMsg);
477 dest.writeString(mSuggestActionMsgColumn);
478 }
479 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 /**
482 * If any action keys were defined for this searchable activity, look up and return.
483 *
484 * @param keyCode The key that was pressed
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100485 * @return Returns the action key info, or {@code null} if none defined.
486 *
487 * @hide ActionKeyInfo is hidden
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 */
489 public ActionKeyInfo findActionKey(int keyCode) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100490 if (mActionKeys == null) {
491 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100493 return mActionKeys.get(keyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100495
496 private void addActionKey(ActionKeyInfo keyInfo) {
497 if (mActionKeys == null) {
498 mActionKeys = new HashMap<Integer,ActionKeyInfo>();
499 }
500 mActionKeys.put(keyInfo.getKeyCode(), keyInfo);
501 }
502
Bjorn Bringert13b24b72009-07-13 15:29:59 +0100503 /**
504 * Gets search information for the given activity.
505 *
506 * @param context Context to use for reading activity resources.
507 * @param activityInfo Activity to get search information from.
508 * @return Search information about the given activity, or {@code null} if
509 * the activity has no or invalid searchability meta-data.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000510 *
511 * @hide For use by SearchManagerService.
Bjorn Bringert13b24b72009-07-13 15:29:59 +0100512 */
Karl Rosaen875d50a2009-04-23 19:00:21 -0700513 public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo) {
514 // for each component, try to find metadata
515 XmlResourceParser xml =
516 activityInfo.loadXmlMetaData(context.getPackageManager(), MD_LABEL_SEARCHABLE);
517 if (xml == null) {
518 return null;
519 }
520 ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
521
522 SearchableInfo searchable = getActivityMetaData(context, xml, cName);
523 xml.close();
Bjorn Bringerta9204132009-05-05 14:06:35 +0100524
525 if (DBG) {
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100526 if (searchable != null) {
527 Log.d(LOG_TAG, "Checked " + activityInfo.name
528 + ",label=" + searchable.getLabelId()
529 + ",icon=" + searchable.getIconId()
530 + ",suggestAuthority=" + searchable.getSuggestAuthority()
531 + ",target=" + searchable.getSearchActivity().getClassName()
532 + ",global=" + searchable.shouldIncludeInGlobalSearch()
Bjorn Bringert23897c12010-02-10 16:10:54 +0000533 + ",settingsDescription=" + searchable.getSettingsDescriptionId()
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100534 + ",threshold=" + searchable.getSuggestThreshold());
535 } else {
536 Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
537 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100538 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700539 return searchable;
540 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 /**
543 * Get the metadata for a given activity
544 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 * @param context runtime context
546 * @param xml XML parser for reading attributes
547 * @param cName The component name of the searchable activity
548 *
549 * @result A completely constructed SearchableInfo, or null if insufficient XML data for it
550 */
551 private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml,
552 final ComponentName cName) {
553 SearchableInfo result = null;
Karl Rosaen875d50a2009-04-23 19:00:21 -0700554 Context activityContext = createActivityContext(context, cName);
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100555 if (activityContext == null) return null;
556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 // in order to use the attributes mechanism, we have to walk the parser
558 // forward through the file until it's reading the tag of interest.
559 try {
560 int tagType = xml.next();
561 while (tagType != XmlPullParser.END_DOCUMENT) {
562 if (tagType == XmlPullParser.START_TAG) {
563 if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
564 AttributeSet attr = Xml.asAttributeSet(xml);
565 if (attr != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100566 try {
567 result = new SearchableInfo(activityContext, attr, cName);
568 } catch (IllegalArgumentException ex) {
569 Log.w(LOG_TAG, "Invalid searchable metadata for " +
570 cName.flattenToShortString() + ": " + ex.getMessage());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 return null;
572 }
573 }
574 } else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
575 if (result == null) {
576 // Can't process an embedded element if we haven't seen the enclosing
577 return null;
578 }
579 AttributeSet attr = Xml.asAttributeSet(xml);
580 if (attr != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100581 try {
582 result.addActionKey(new ActionKeyInfo(activityContext, attr));
583 } catch (IllegalArgumentException ex) {
584 Log.w(LOG_TAG, "Invalid action key for " +
585 cName.flattenToShortString() + ": " + ex.getMessage());
586 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
588 }
589 }
590 }
591 tagType = xml.next();
592 }
593 } catch (XmlPullParserException e) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100594 Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
595 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 } catch (IOException e) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100597 Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
598 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 return result;
602 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100605 * Gets the "label" (user-visible name) of this searchable context. This must be
606 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100608 * @return A resource id, or {@code 0} if no label was specified.
609 * @see android.R.styleable#Searchable_label
610 *
611 * @hide deprecated functionality
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 */
613 public int getLabelId() {
614 return mLabelId;
615 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100618 * Gets the resource id of the hint text. This must be
619 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100621 * @return A resource id, or {@code 0} if no hint was specified.
622 * @see android.R.styleable#Searchable_hint
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 */
624 public int getHintId() {
625 return mHintId;
626 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100629 * Gets the icon id specified by the Searchable_icon meta-data entry. This must be
630 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100632 * @return A resource id, or {@code 0} if no icon was specified.
633 * @see android.R.styleable#Searchable_icon
634 *
635 * @hide deprecated functionality
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 */
637 public int getIconId() {
638 return mIconId;
639 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100642 * Checks if the searchable activity wants the voice search button to be shown.
643 *
644 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 */
646 public boolean getVoiceSearchEnabled() {
647 return 0 != (mVoiceSearchMode & VOICE_SEARCH_SHOW_BUTTON);
648 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100651 * Checks if voice search should start web search.
652 *
653 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 */
655 public boolean getVoiceSearchLaunchWebSearch() {
656 return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_WEB_SEARCH);
657 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100660 * Checks if voice search should start in-app search.
661 *
662 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 */
664 public boolean getVoiceSearchLaunchRecognizer() {
665 return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_RECOGNIZER);
666 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100669 * Gets the resource id of the voice search language model string.
670 *
671 * @return A resource id, or {@code 0} if no language model was specified.
672 * @see android.R.styleable#Searchable_voiceLanguageModel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 */
674 public int getVoiceLanguageModeId() {
675 return mVoiceLanguageModeId;
676 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100679 * Gets the resource id of the voice prompt text string.
680 *
681 * @return A resource id, or {@code 0} if no voice prompt text was specified.
682 * @see android.R.styleable#Searchable_voicePromptText
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 */
684 public int getVoicePromptTextId() {
685 return mVoicePromptTextId;
686 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100689 * Gets the resource id of the spoken language to recognize in voice search.
690 *
691 * @return A resource id, or {@code 0} if no language was specified.
692 * @see android.R.styleable#Searchable_voiceLanguage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 */
694 public int getVoiceLanguageId() {
695 return mVoiceLanguageId;
696 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100699 * The maximum number of voice recognition results to return.
700 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 * @return the max results count, if specified in the searchable
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100702 * activity's metadata, or {@code 0} if not specified.
703 * @see android.R.styleable#Searchable_voiceMaxResults
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 */
705 public int getVoiceMaxResults() {
706 return mVoiceMaxResults;
707 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100710 * Gets the resource id of replacement text for the "Search" button.
711 *
712 * @return A resource id, or {@code 0} if no replacement text was specified.
713 * @see android.R.styleable#Searchable_searchButtonText
714 * @hide This feature is deprecated, no need to add it to the API.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 */
716 public int getSearchButtonText() {
717 return mSearchButtonText;
718 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100721 * Gets the input type as specified in the searchable attributes. This will default to
722 * {@link InputType#TYPE_CLASS_TEXT} if not specified (which is appropriate
723 * for free text input).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 *
725 * @return the input type
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100726 * @see android.R.styleable#Searchable_inputType
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 */
728 public int getInputType() {
729 return mSearchInputType;
730 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100733 * Gets the input method options specified in the searchable attributes.
734 * This will default to {@link EditorInfo#IME_ACTION_GO} if not specified (which is
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 * appropriate for a search box).
736 *
737 * @return the input type
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100738 * @see android.R.styleable#Searchable_imeOptions
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 */
740 public int getImeOptions() {
741 return mSearchImeOptions;
742 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100745 * Checks whether the searchable should be included in global search.
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100746 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100747 * @return The value of the {@link android.R.styleable#Searchable_includeInGlobalSearch}
748 * attribute, or {@code false} if the attribute is not set.
749 * @see android.R.styleable#Searchable_includeInGlobalSearch
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100750 */
751 public boolean shouldIncludeInGlobalSearch() {
752 return mIncludeInGlobalSearch;
753 }
754
755 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100756 * Checks whether this searchable activity should be queried for suggestions if a prefix
757 * of the query has returned no results.
Satish Sampath35379ab2009-06-11 14:05:51 +0100758 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100759 * @see android.R.styleable#Searchable_queryAfterZeroResults
Satish Sampath35379ab2009-06-11 14:05:51 +0100760 */
761 public boolean queryAfterZeroResults() {
762 return mQueryAfterZeroResults;
763 }
764
765 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100766 * Checks whether this searchable activity has auto URL detection turned on.
Satish Sampathd21572c2009-07-08 14:54:11 +0100767 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100768 * @see android.R.styleable#Searchable_autoUrlDetect
Satish Sampathd21572c2009-07-08 14:54:11 +0100769 */
770 public boolean autoUrlDetect() {
771 return mAutoUrlDetect;
772 }
773
774 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 * Support for parcelable and aidl operations.
776 */
777 public static final Parcelable.Creator<SearchableInfo> CREATOR
778 = new Parcelable.Creator<SearchableInfo>() {
779 public SearchableInfo createFromParcel(Parcel in) {
780 return new SearchableInfo(in);
781 }
782
783 public SearchableInfo[] newArray(int size) {
784 return new SearchableInfo[size];
785 }
786 };
787
788 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100789 * Instantiates a new SearchableInfo from the data in a Parcel that was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 * previously written with {@link #writeToParcel(Parcel, int)}.
791 *
792 * @param in The Parcel containing the previously written SearchableInfo,
793 * positioned at the location in the buffer where it was written.
794 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000795 SearchableInfo(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 mLabelId = in.readInt();
797 mSearchActivity = ComponentName.readFromParcel(in);
798 mHintId = in.readInt();
799 mSearchMode = in.readInt();
800 mIconId = in.readInt();
801 mSearchButtonText = in.readInt();
802 mSearchInputType = in.readInt();
803 mSearchImeOptions = in.readInt();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100804 mIncludeInGlobalSearch = in.readInt() != 0;
Satish Sampath35379ab2009-06-11 14:05:51 +0100805 mQueryAfterZeroResults = in.readInt() != 0;
Satish Sampathd21572c2009-07-08 14:54:11 +0100806 mAutoUrlDetect = in.readInt() != 0;
Mike LeBeau735b3332009-06-30 18:27:40 -0700807
Bjorn Bringert23897c12010-02-10 16:10:54 +0000808 mSettingsDescriptionId = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 mSuggestAuthority = in.readString();
810 mSuggestPath = in.readString();
811 mSuggestSelection = in.readString();
812 mSuggestIntentAction = in.readString();
813 mSuggestIntentData = in.readString();
Bjorn Bringert203464a2009-04-27 17:08:11 +0100814 mSuggestThreshold = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815
Bjorn Bringerta9204132009-05-05 14:06:35 +0100816 for (int count = in.readInt(); count > 0; count--) {
817 addActionKey(new ActionKeyInfo(in));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 mSuggestProviderPackage = in.readString();
821
822 mVoiceSearchMode = in.readInt();
823 mVoiceLanguageModeId = in.readInt();
824 mVoicePromptTextId = in.readInt();
825 mVoiceLanguageId = in.readInt();
826 mVoiceMaxResults = in.readInt();
827 }
828
829 public int describeContents() {
830 return 0;
831 }
832
833 public void writeToParcel(Parcel dest, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 dest.writeInt(mLabelId);
835 mSearchActivity.writeToParcel(dest, flags);
836 dest.writeInt(mHintId);
837 dest.writeInt(mSearchMode);
838 dest.writeInt(mIconId);
839 dest.writeInt(mSearchButtonText);
840 dest.writeInt(mSearchInputType);
841 dest.writeInt(mSearchImeOptions);
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100842 dest.writeInt(mIncludeInGlobalSearch ? 1 : 0);
Satish Sampath35379ab2009-06-11 14:05:51 +0100843 dest.writeInt(mQueryAfterZeroResults ? 1 : 0);
Satish Sampathd21572c2009-07-08 14:54:11 +0100844 dest.writeInt(mAutoUrlDetect ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845
Bjorn Bringert23897c12010-02-10 16:10:54 +0000846 dest.writeInt(mSettingsDescriptionId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 dest.writeString(mSuggestAuthority);
848 dest.writeString(mSuggestPath);
849 dest.writeString(mSuggestSelection);
850 dest.writeString(mSuggestIntentAction);
851 dest.writeString(mSuggestIntentData);
Bjorn Bringert203464a2009-04-27 17:08:11 +0100852 dest.writeInt(mSuggestThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853
Bjorn Bringerta9204132009-05-05 14:06:35 +0100854 if (mActionKeys == null) {
855 dest.writeInt(0);
856 } else {
857 dest.writeInt(mActionKeys.size());
858 for (ActionKeyInfo actionKey : mActionKeys.values()) {
859 actionKey.writeToParcel(dest, flags);
860 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 dest.writeString(mSuggestProviderPackage);
864
865 dest.writeInt(mVoiceSearchMode);
866 dest.writeInt(mVoiceLanguageModeId);
867 dest.writeInt(mVoicePromptTextId);
868 dest.writeInt(mVoiceLanguageId);
869 dest.writeInt(mVoiceMaxResults);
870 }
871}