blob: 029877c9273d3a90b148807eecaf0a809fcc400f [file] [log] [blame]
Michael Kolb21ce4d22010-09-15 14:55:05 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
19import com.android.browser.search.SearchEngine;
20
21import android.app.SearchManager;
22import android.content.Context;
23import android.database.Cursor;
24import android.net.Uri;
John Reck35defff2010-11-11 14:06:45 -080025import android.os.AsyncTask;
Michael Kolb21ce4d22010-09-15 14:55:05 -070026import android.provider.BrowserContract;
27import android.text.TextUtils;
Michael Kolbbd2dd642011-01-13 13:01:30 -080028import android.util.Log;
Michael Kolb21ce4d22010-09-15 14:55:05 -070029import android.view.LayoutInflater;
30import android.view.View;
31import android.view.View.OnClickListener;
32import android.view.ViewGroup;
33import android.widget.BaseAdapter;
34import android.widget.Filter;
35import android.widget.Filterable;
36import android.widget.ImageView;
Michael Kolb21ce4d22010-09-15 14:55:05 -070037import android.widget.TextView;
38
39import java.util.ArrayList;
40import java.util.List;
Michael Kolb21ce4d22010-09-15 14:55:05 -070041
42/**
43 * adapter to wrap multiple cursors for url/search completions
44 */
Michael Kolbbd2dd642011-01-13 13:01:30 -080045public class SuggestionsAdapter extends BaseAdapter implements Filterable,
46 OnClickListener {
Michael Kolb21ce4d22010-09-15 14:55:05 -070047
John Reck35defff2010-11-11 14:06:45 -080048 static final int TYPE_BOOKMARK = 0;
49 static final int TYPE_SUGGEST_URL = 1;
50 static final int TYPE_HISTORY = 2;
51 static final int TYPE_SEARCH = 3;
52 static final int TYPE_SUGGEST = 4;
Michael Kolbbd2dd642011-01-13 13:01:30 -080053 static final int TYPE_VOICE_SEARCH = 5;
Michael Kolb21ce4d22010-09-15 14:55:05 -070054
55 private static final String[] COMBINED_PROJECTION =
56 {BrowserContract.Combined._ID, BrowserContract.Combined.TITLE,
57 BrowserContract.Combined.URL, BrowserContract.Combined.IS_BOOKMARK};
58
Michael Kolb21ce4d22010-09-15 14:55:05 -070059 private static final String COMBINED_SELECTION =
60 "(url LIKE ? OR url LIKE ? OR url LIKE ? OR url LIKE ? OR title LIKE ?)";
61
Michael Kolb21ce4d22010-09-15 14:55:05 -070062 Context mContext;
63 Filter mFilter;
John Reck35defff2010-11-11 14:06:45 -080064 SuggestionResults mMixedResults;
65 List<SuggestItem> mSuggestResults, mFilterResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -070066 List<CursorSource> mSources;
67 boolean mLandscapeMode;
68 CompletionListener mListener;
69 int mLinesPortrait;
70 int mLinesLandscape;
John Reck35defff2010-11-11 14:06:45 -080071 Object mResultsLock = new Object();
Michael Kolbcfa3af52010-12-14 10:36:11 -080072 List<String> mVoiceResults;
John Reck1605bef2011-01-10 18:11:18 -080073 boolean mReverseResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -070074
75 interface CompletionListener {
76
77 public void onSearch(String txt);
78
Michael Kolbbd2dd642011-01-13 13:01:30 -080079 public void onSelect(String txt, int type, String extraData);
Michael Kolb21ce4d22010-09-15 14:55:05 -070080
Michael Kolb0506f2d2010-10-14 16:20:16 -070081 public void onFilterComplete(int count);
82
Michael Kolb21ce4d22010-09-15 14:55:05 -070083 }
84
85 public SuggestionsAdapter(Context ctx, CompletionListener listener) {
86 mContext = ctx;
87 mListener = listener;
88 mLinesPortrait = mContext.getResources().
89 getInteger(R.integer.max_suggest_lines_portrait);
90 mLinesLandscape = mContext.getResources().
91 getInteger(R.integer.max_suggest_lines_landscape);
92 mFilter = new SuggestFilter();
Michael Kolb21ce4d22010-09-15 14:55:05 -070093 addSource(new CombinedCursor());
94 }
95
Michael Kolbcfa3af52010-12-14 10:36:11 -080096 void setVoiceResults(List<String> voiceResults) {
97 mVoiceResults = voiceResults;
Michael Kolba50c4462010-12-15 10:49:12 -080098 notifyDataSetChanged();
Michael Kolbcfa3af52010-12-14 10:36:11 -080099 }
100
Michael Kolb21ce4d22010-09-15 14:55:05 -0700101 public void setLandscapeMode(boolean mode) {
102 mLandscapeMode = mode;
John Reck35defff2010-11-11 14:06:45 -0800103 notifyDataSetChanged();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700104 }
105
Michael Kolb21ce4d22010-09-15 14:55:05 -0700106 public void addSource(CursorSource c) {
107 if (mSources == null) {
108 mSources = new ArrayList<CursorSource>(5);
109 }
110 mSources.add(c);
111 }
112
113 @Override
114 public void onClick(View v) {
John Reckad373302010-12-17 15:28:13 -0800115 SuggestItem item = (SuggestItem) ((View) v.getParent()).getTag();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700116 if (R.id.icon2 == v.getId()) {
117 // replace input field text with suggestion text
Michael Kolb21ce4d22010-09-15 14:55:05 -0700118 mListener.onSearch(item.title);
119 } else {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800120 mListener.onSelect(
121 (TextUtils.isEmpty(item.url)? item.title : item.url),
122 item.type, item.extra);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700123 }
124 }
125
126 @Override
127 public Filter getFilter() {
128 return mFilter;
129 }
130
131 @Override
132 public int getCount() {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800133 if (mVoiceResults != null) {
134 return mVoiceResults.size();
135 }
John Reck35defff2010-11-11 14:06:45 -0800136 return (mMixedResults == null) ? 0 : mMixedResults.getLineCount();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700137 }
138
139 @Override
140 public SuggestItem getItem(int position) {
John Reck1605bef2011-01-10 18:11:18 -0800141 if (mReverseResults) {
142 position = (getCount() - 1) - position;
143 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800144 if (mVoiceResults != null) {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800145 SuggestItem item = new SuggestItem(mVoiceResults.get(position),
146 null, TYPE_VOICE_SEARCH);
147 item.extra = Integer.toString(position);
148 return item;
Michael Kolbcfa3af52010-12-14 10:36:11 -0800149 }
John Reck35defff2010-11-11 14:06:45 -0800150 if (mMixedResults == null) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700151 return null;
152 }
John Reckad373302010-12-17 15:28:13 -0800153 return mMixedResults.items.get(position);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700154 }
155
John Reck1605bef2011-01-10 18:11:18 -0800156 public void setReverseResults(boolean reverse) {
157 mReverseResults = reverse;
158 }
159
Michael Kolb21ce4d22010-09-15 14:55:05 -0700160 @Override
161 public long getItemId(int position) {
John Reck1605bef2011-01-10 18:11:18 -0800162 return position;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700163 }
164
165 @Override
166 public View getView(int position, View convertView, ViewGroup parent) {
167 final LayoutInflater inflater = LayoutInflater.from(mContext);
John Reck35defff2010-11-11 14:06:45 -0800168 View view = convertView;
169 if (view == null) {
John Reckad373302010-12-17 15:28:13 -0800170 view = inflater.inflate(R.layout.suggestion_item, parent, false);
John Reck35defff2010-11-11 14:06:45 -0800171 }
John Reckad373302010-12-17 15:28:13 -0800172 bindView(view, getItem(position));
173 return view;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700174 }
175
176 private void bindView(View view, SuggestItem item) {
177 // store item for click handling
178 view.setTag(item);
179 TextView tv1 = (TextView) view.findViewById(android.R.id.text1);
180 TextView tv2 = (TextView) view.findViewById(android.R.id.text2);
181 ImageView ic1 = (ImageView) view.findViewById(R.id.icon1);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700182 View ic2 = view.findViewById(R.id.icon2);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700183 View div = view.findViewById(R.id.divider);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700184 tv1.setText(item.title);
John Reckad373302010-12-17 15:28:13 -0800185 if (TextUtils.isEmpty(item.url)) {
186 tv2.setVisibility(View.GONE);
187 } else {
188 tv2.setVisibility(View.VISIBLE);
189 tv2.setText(item.url);
190 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700191 int id = -1;
192 switch (item.type) {
193 case TYPE_SUGGEST:
194 case TYPE_SEARCH:
Michael Kolbbd2dd642011-01-13 13:01:30 -0800195 case TYPE_VOICE_SEARCH:
Michael Kolb21ce4d22010-09-15 14:55:05 -0700196 id = R.drawable.ic_search_category_suggest;
197 break;
198 case TYPE_BOOKMARK:
199 id = R.drawable.ic_search_category_bookmark;
200 break;
201 case TYPE_HISTORY:
202 id = R.drawable.ic_search_category_history;
203 break;
204 case TYPE_SUGGEST_URL:
205 id = R.drawable.ic_search_category_browser;
206 break;
207 default:
208 id = -1;
209 }
210 if (id != -1) {
211 ic1.setImageDrawable(mContext.getResources().getDrawable(id));
212 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800213 ic2.setVisibility(((TYPE_SUGGEST == item.type)
214 || (TYPE_SEARCH == item.type)
215 || (TYPE_VOICE_SEARCH == item.type))
Michael Kolb21ce4d22010-09-15 14:55:05 -0700216 ? View.VISIBLE : View.GONE);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700217 div.setVisibility(ic2.getVisibility());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700218 ic2.setOnClickListener(this);
John Reckad373302010-12-17 15:28:13 -0800219 view.findViewById(R.id.suggestion).setOnClickListener(this);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700220 }
221
John Reck35defff2010-11-11 14:06:45 -0800222 class SlowFilterTask extends AsyncTask<CharSequence, Void, List<SuggestItem>> {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700223
John Reck35defff2010-11-11 14:06:45 -0800224 @Override
225 protected List<SuggestItem> doInBackground(CharSequence... params) {
226 SuggestCursor cursor = new SuggestCursor();
227 cursor.runQuery(params[0]);
228 List<SuggestItem> results = new ArrayList<SuggestItem>();
229 int count = cursor.getCount();
230 for (int i = 0; i < count; i++) {
231 results.add(cursor.getItem());
232 cursor.moveToNext();
233 }
234 cursor.close();
235 return results;
236 }
237
238 @Override
239 protected void onPostExecute(List<SuggestItem> items) {
240 mSuggestResults = items;
241 mMixedResults = buildSuggestionResults();
242 notifyDataSetChanged();
243 mListener.onFilterComplete(mMixedResults.getLineCount());
244 }
245 }
246
247 SuggestionResults buildSuggestionResults() {
248 SuggestionResults mixed = new SuggestionResults();
249 List<SuggestItem> filter, suggest;
250 synchronized (mResultsLock) {
251 filter = mFilterResults;
252 suggest = mSuggestResults;
253 }
254 if (filter != null) {
255 for (SuggestItem item : filter) {
256 mixed.addResult(item);
257 }
258 }
259 if (suggest != null) {
260 for (SuggestItem item : suggest) {
261 mixed.addResult(item);
262 }
263 }
264 return mixed;
265 }
266
267 class SuggestFilter extends Filter {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700268
269 @Override
270 public CharSequence convertResultToString(Object item) {
271 if (item == null) {
272 return "";
273 }
274 SuggestItem sitem = (SuggestItem) item;
275 if (sitem.title != null) {
276 return sitem.title;
277 } else {
278 return sitem.url;
279 }
280 }
281
John Reck35defff2010-11-11 14:06:45 -0800282 void startSuggestionsAsync(final CharSequence constraint) {
283 new SlowFilterTask().execute(constraint);
284 }
285
Michael Kolb21ce4d22010-09-15 14:55:05 -0700286 @Override
287 protected FilterResults performFiltering(CharSequence constraint) {
288 FilterResults res = new FilterResults();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800289 if (mVoiceResults == null) {
290 if (TextUtils.isEmpty(constraint)) {
291 res.count = 0;
292 res.values = null;
293 return res;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700294 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800295 startSuggestionsAsync(constraint);
296 List<SuggestItem> filterResults = new ArrayList<SuggestItem>();
297 if (constraint != null) {
298 for (CursorSource sc : mSources) {
299 sc.runQuery(constraint);
300 }
301 mixResults(filterResults);
302 }
303 synchronized (mResultsLock) {
304 mFilterResults = filterResults;
305 }
306 SuggestionResults mixed = buildSuggestionResults();
307 res.count = mixed.getLineCount();
308 res.values = mixed;
309 } else {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800310 Log.i("voice", "using voice results");
Michael Kolbcfa3af52010-12-14 10:36:11 -0800311 res.count = mVoiceResults.size();
312 res.values = mVoiceResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700313 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700314 return res;
315 }
316
John Reck35defff2010-11-11 14:06:45 -0800317 void mixResults(List<SuggestItem> results) {
John Reckad373302010-12-17 15:28:13 -0800318 int maxLines = mLandscapeMode ? mLinesLandscape : mLinesPortrait;
319 maxLines = (int) Math.ceil(maxLines / 2.0);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700320 for (int i = 0; i < mSources.size(); i++) {
321 CursorSource s = mSources.get(i);
John Reck35defff2010-11-11 14:06:45 -0800322 int n = Math.min(s.getCount(), maxLines);
323 maxLines -= n;
Michael Kolb0506f2d2010-10-14 16:20:16 -0700324 boolean more = false;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700325 for (int j = 0; j < n; j++) {
John Reck35defff2010-11-11 14:06:45 -0800326 results.add(s.getItem());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700327 more = s.moveToNext();
328 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700329 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700330 }
331
332 @Override
333 protected void publishResults(CharSequence constraint, FilterResults fresults) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800334 if (fresults.values instanceof SuggestionResults) {
335 mMixedResults = (SuggestionResults) fresults.values;
336 mListener.onFilterComplete(fresults.count);
337 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700338 notifyDataSetChanged();
339 }
340
341 }
342
343 /**
344 * sorted list of results of a suggestion query
345 *
346 */
347 class SuggestionResults {
348
349 ArrayList<SuggestItem> items;
350 // count per type
351 int[] counts;
352
353 SuggestionResults() {
354 items = new ArrayList<SuggestItem>(24);
355 // n of types:
356 counts = new int[5];
357 }
358
359 int getTypeCount(int type) {
360 return counts[type];
361 }
362
363 void addResult(SuggestItem item) {
364 int ix = 0;
365 while ((ix < items.size()) && (item.type >= items.get(ix).type))
366 ix++;
367 items.add(ix, item);
368 counts[item.type]++;
369 }
370
371 int getLineCount() {
372 if (mLandscapeMode) {
John Reckad373302010-12-17 15:28:13 -0800373 return Math.min(mLinesLandscape, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700374 } else {
John Reckad373302010-12-17 15:28:13 -0800375 return Math.min(mLinesPortrait, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700376 }
377 }
378
John Reck35defff2010-11-11 14:06:45 -0800379 @Override
Michael Kolb21ce4d22010-09-15 14:55:05 -0700380 public String toString() {
381 if (items == null) return null;
382 if (items.size() == 0) return "[]";
383 StringBuilder sb = new StringBuilder();
384 for (int i = 0; i < items.size(); i++) {
385 SuggestItem item = items.get(i);
386 sb.append(item.type + ": " + item.title);
387 if (i < items.size() - 1) {
388 sb.append(", ");
389 }
390 }
391 return sb.toString();
392 }
393 }
394
395 /**
396 * data object to hold suggestion values
397 */
398 class SuggestItem {
399 String title;
400 String url;
401 int type;
John Reck40f720e2010-11-10 11:57:04 -0800402 String extra;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700403
404 public SuggestItem(String text, String u, int t) {
405 title = text;
406 url = u;
407 type = t;
408 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800409
Michael Kolb21ce4d22010-09-15 14:55:05 -0700410 }
411
412 abstract class CursorSource {
413
414 Cursor mCursor;
415
416 boolean moveToNext() {
417 return mCursor.moveToNext();
418 }
419
420 public abstract void runQuery(CharSequence constraint);
421
422 public abstract SuggestItem getItem();
423
424 public int getCount() {
425 return (mCursor != null) ? mCursor.getCount() : 0;
426 }
427
428 public void close() {
429 if (mCursor != null) {
430 mCursor.close();
431 }
432 }
433 }
434
435 /**
436 * combined bookmark & history source
437 */
438 class CombinedCursor extends CursorSource {
439
440 @Override
441 public SuggestItem getItem() {
442 if ((mCursor != null) && (!mCursor.isAfterLast())) {
443 String title = mCursor.getString(1);
444 String url = mCursor.getString(2);
445 boolean isBookmark = (mCursor.getInt(3) == 1);
446 return new SuggestItem(getTitle(title, url), getUrl(title, url),
447 isBookmark ? TYPE_BOOKMARK : TYPE_HISTORY);
448 }
449 return null;
450 }
451
452 @Override
453 public void runQuery(CharSequence constraint) {
454 // constraint != null
455 if (mCursor != null) {
456 mCursor.close();
457 }
458 String like = constraint + "%";
459 String[] args = null;
460 String selection = null;
461 if (like.startsWith("http") || like.startsWith("file")) {
462 args = new String[1];
463 args[0] = like;
464 selection = "url LIKE ?";
465 } else {
466 args = new String[5];
467 args[0] = "http://" + like;
468 args[1] = "http://www." + like;
469 args[2] = "https://" + like;
470 args[3] = "https://www." + like;
471 // To match against titles.
472 args[4] = like;
473 selection = COMBINED_SELECTION;
474 }
475 Uri.Builder ub = BrowserContract.Combined.CONTENT_URI.buildUpon();
Michael Kolb0506f2d2010-10-14 16:20:16 -0700476 ub.appendQueryParameter(BrowserContract.PARAM_LIMIT,
John Reckad373302010-12-17 15:28:13 -0800477 Integer.toString(Math.max(mLinesLandscape, mLinesPortrait)));
John Reck3dff1ce2010-12-10 11:13:57 -0800478 BookmarkUtils.addAccountInfo(mContext, ub);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700479 mCursor =
Michael Kolb0506f2d2010-10-14 16:20:16 -0700480 mContext.getContentResolver().query(ub.build(), COMBINED_PROJECTION,
Michael Kolb21ce4d22010-09-15 14:55:05 -0700481 selection,
482 (constraint != null) ? args : null,
John Reck3dff1ce2010-12-10 11:13:57 -0800483 BrowserContract.Combined.IS_BOOKMARK + " DESC, " +
Michael Kolb21ce4d22010-09-15 14:55:05 -0700484 BrowserContract.Combined.VISITS + " DESC, " +
485 BrowserContract.Combined.DATE_LAST_VISITED + " DESC");
486 if (mCursor != null) {
487 mCursor.moveToFirst();
488 }
489 }
490
491 /**
492 * Provides the title (text line 1) for a browser suggestion, which should be the
493 * webpage title. If the webpage title is empty, returns the stripped url instead.
494 *
495 * @return the title string to use
496 */
497 private String getTitle(String title, String url) {
498 if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
John Reckfb3017f2010-10-26 19:01:24 -0700499 title = UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700500 }
501 return title;
502 }
503
504 /**
505 * Provides the subtitle (text line 2) for a browser suggestion, which should be the
506 * webpage url. If the webpage title is empty, then the url should go in the title
507 * instead, and the subtitle should be empty, so this would return null.
508 *
509 * @return the subtitle string to use, or null if none
510 */
511 private String getUrl(String title, String url) {
John Reck7d132b12010-10-26 15:10:21 -0700512 if (TextUtils.isEmpty(title)
513 || TextUtils.getTrimmedLength(title) == 0
514 || title.equals(url)) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700515 return null;
516 } else {
John Reckfb3017f2010-10-26 19:01:24 -0700517 return UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700518 }
519 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700520 }
521
Michael Kolb21ce4d22010-09-15 14:55:05 -0700522 class SuggestCursor extends CursorSource {
523
524 @Override
525 public SuggestItem getItem() {
526 if (mCursor != null) {
527 String title = mCursor.getString(
528 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
529 String text2 = mCursor.getString(
530 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2));
531 String url = mCursor.getString(
532 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL));
533 String uri = mCursor.getString(
534 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA));
535 int type = (TextUtils.isEmpty(url)) ? TYPE_SUGGEST : TYPE_SUGGEST_URL;
John Reck40f720e2010-11-10 11:57:04 -0800536 SuggestItem item = new SuggestItem(title, url, type);
537 item.extra = mCursor.getString(
538 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA));
539 return item;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700540 }
541 return null;
542 }
543
544 @Override
545 public void runQuery(CharSequence constraint) {
546 if (mCursor != null) {
547 mCursor.close();
548 }
549 if (!TextUtils.isEmpty(constraint)) {
550 SearchEngine searchEngine = BrowserSettings.getInstance().getSearchEngine();
551 if (searchEngine != null && searchEngine.supportsSuggestions()) {
552 mCursor = searchEngine.getSuggestions(mContext, constraint.toString());
553 if (mCursor != null) {
554 mCursor.moveToFirst();
555 }
556 }
557 } else {
558 mCursor = null;
559 }
560 }
561
562 }
563
John Reck35defff2010-11-11 14:06:45 -0800564 public void clearCache() {
565 mFilterResults = null;
566 mSuggestResults = null;
567 }
568
Michael Kolb21ce4d22010-09-15 14:55:05 -0700569}