blob: abf908822b7b9fd3cbaa63b4c96377324ff293ae [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;
28import android.view.LayoutInflater;
29import android.view.View;
30import android.view.View.OnClickListener;
31import android.view.ViewGroup;
32import android.widget.BaseAdapter;
33import android.widget.Filter;
34import android.widget.Filterable;
35import android.widget.ImageView;
Michael Kolb21ce4d22010-09-15 14:55:05 -070036import android.widget.TextView;
37
38import java.util.ArrayList;
39import java.util.List;
Michael Kolb21ce4d22010-09-15 14:55:05 -070040
41/**
42 * adapter to wrap multiple cursors for url/search completions
43 */
Michael Kolbbd2dd642011-01-13 13:01:30 -080044public class SuggestionsAdapter extends BaseAdapter implements Filterable,
45 OnClickListener {
Michael Kolb21ce4d22010-09-15 14:55:05 -070046
John Reck35defff2010-11-11 14:06:45 -080047 static final int TYPE_BOOKMARK = 0;
48 static final int TYPE_SUGGEST_URL = 1;
49 static final int TYPE_HISTORY = 2;
50 static final int TYPE_SEARCH = 3;
51 static final int TYPE_SUGGEST = 4;
Michael Kolbbd2dd642011-01-13 13:01:30 -080052 static final int TYPE_VOICE_SEARCH = 5;
Michael Kolb21ce4d22010-09-15 14:55:05 -070053
54 private static final String[] COMBINED_PROJECTION =
55 {BrowserContract.Combined._ID, BrowserContract.Combined.TITLE,
56 BrowserContract.Combined.URL, BrowserContract.Combined.IS_BOOKMARK};
57
Michael Kolb21ce4d22010-09-15 14:55:05 -070058 private static final String COMBINED_SELECTION =
59 "(url LIKE ? OR url LIKE ? OR url LIKE ? OR url LIKE ? OR title LIKE ?)";
60
Michael Kolb21ce4d22010-09-15 14:55:05 -070061 Context mContext;
62 Filter mFilter;
John Reck35defff2010-11-11 14:06:45 -080063 SuggestionResults mMixedResults;
64 List<SuggestItem> mSuggestResults, mFilterResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -070065 List<CursorSource> mSources;
66 boolean mLandscapeMode;
67 CompletionListener mListener;
68 int mLinesPortrait;
69 int mLinesLandscape;
John Reck35defff2010-11-11 14:06:45 -080070 Object mResultsLock = new Object();
Michael Kolbcfa3af52010-12-14 10:36:11 -080071 List<String> mVoiceResults;
John Reck1605bef2011-01-10 18:11:18 -080072 boolean mReverseResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -070073
74 interface CompletionListener {
75
76 public void onSearch(String txt);
77
Michael Kolbbd2dd642011-01-13 13:01:30 -080078 public void onSelect(String txt, int type, String extraData);
Michael Kolb21ce4d22010-09-15 14:55:05 -070079
Michael Kolb0506f2d2010-10-14 16:20:16 -070080 public void onFilterComplete(int count);
81
Michael Kolb21ce4d22010-09-15 14:55:05 -070082 }
83
84 public SuggestionsAdapter(Context ctx, CompletionListener listener) {
85 mContext = ctx;
86 mListener = listener;
87 mLinesPortrait = mContext.getResources().
88 getInteger(R.integer.max_suggest_lines_portrait);
89 mLinesLandscape = mContext.getResources().
90 getInteger(R.integer.max_suggest_lines_landscape);
91 mFilter = new SuggestFilter();
Michael Kolb21ce4d22010-09-15 14:55:05 -070092 addSource(new CombinedCursor());
93 }
94
Michael Kolbcfa3af52010-12-14 10:36:11 -080095 void setVoiceResults(List<String> voiceResults) {
96 mVoiceResults = voiceResults;
Michael Kolba50c4462010-12-15 10:49:12 -080097 notifyDataSetChanged();
Michael Kolbcfa3af52010-12-14 10:36:11 -080098 }
99
Michael Kolb21ce4d22010-09-15 14:55:05 -0700100 public void setLandscapeMode(boolean mode) {
101 mLandscapeMode = mode;
John Reck35defff2010-11-11 14:06:45 -0800102 notifyDataSetChanged();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700103 }
104
Michael Kolb21ce4d22010-09-15 14:55:05 -0700105 public void addSource(CursorSource c) {
106 if (mSources == null) {
107 mSources = new ArrayList<CursorSource>(5);
108 }
109 mSources.add(c);
110 }
111
112 @Override
113 public void onClick(View v) {
John Reckad373302010-12-17 15:28:13 -0800114 SuggestItem item = (SuggestItem) ((View) v.getParent()).getTag();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700115 if (R.id.icon2 == v.getId()) {
116 // replace input field text with suggestion text
Michael Kolb21ce4d22010-09-15 14:55:05 -0700117 mListener.onSearch(item.title);
118 } else {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800119 mListener.onSelect(
120 (TextUtils.isEmpty(item.url)? item.title : item.url),
121 item.type, item.extra);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700122 }
123 }
124
125 @Override
126 public Filter getFilter() {
127 return mFilter;
128 }
129
130 @Override
131 public int getCount() {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800132 if (mVoiceResults != null) {
133 return mVoiceResults.size();
134 }
John Reck35defff2010-11-11 14:06:45 -0800135 return (mMixedResults == null) ? 0 : mMixedResults.getLineCount();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700136 }
137
138 @Override
139 public SuggestItem getItem(int position) {
John Reck1605bef2011-01-10 18:11:18 -0800140 if (mReverseResults) {
141 position = (getCount() - 1) - position;
142 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800143 if (mVoiceResults != null) {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800144 SuggestItem item = new SuggestItem(mVoiceResults.get(position),
145 null, TYPE_VOICE_SEARCH);
146 item.extra = Integer.toString(position);
147 return item;
Michael Kolbcfa3af52010-12-14 10:36:11 -0800148 }
John Reck35defff2010-11-11 14:06:45 -0800149 if (mMixedResults == null) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700150 return null;
151 }
John Reckad373302010-12-17 15:28:13 -0800152 return mMixedResults.items.get(position);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700153 }
154
John Reck1605bef2011-01-10 18:11:18 -0800155 public void setReverseResults(boolean reverse) {
156 mReverseResults = reverse;
157 }
158
Michael Kolb21ce4d22010-09-15 14:55:05 -0700159 @Override
160 public long getItemId(int position) {
John Reck1605bef2011-01-10 18:11:18 -0800161 return position;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700162 }
163
164 @Override
165 public View getView(int position, View convertView, ViewGroup parent) {
166 final LayoutInflater inflater = LayoutInflater.from(mContext);
John Reck35defff2010-11-11 14:06:45 -0800167 View view = convertView;
168 if (view == null) {
John Reckad373302010-12-17 15:28:13 -0800169 view = inflater.inflate(R.layout.suggestion_item, parent, false);
John Reck35defff2010-11-11 14:06:45 -0800170 }
John Reckad373302010-12-17 15:28:13 -0800171 bindView(view, getItem(position));
172 return view;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700173 }
174
175 private void bindView(View view, SuggestItem item) {
176 // store item for click handling
177 view.setTag(item);
178 TextView tv1 = (TextView) view.findViewById(android.R.id.text1);
179 TextView tv2 = (TextView) view.findViewById(android.R.id.text2);
180 ImageView ic1 = (ImageView) view.findViewById(R.id.icon1);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700181 View ic2 = view.findViewById(R.id.icon2);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700182 View div = view.findViewById(R.id.divider);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700183 tv1.setText(item.title);
John Reckad373302010-12-17 15:28:13 -0800184 if (TextUtils.isEmpty(item.url)) {
185 tv2.setVisibility(View.GONE);
186 } else {
187 tv2.setVisibility(View.VISIBLE);
188 tv2.setText(item.url);
189 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700190 int id = -1;
191 switch (item.type) {
192 case TYPE_SUGGEST:
193 case TYPE_SEARCH:
Michael Kolbbd2dd642011-01-13 13:01:30 -0800194 case TYPE_VOICE_SEARCH:
Michael Kolb21ce4d22010-09-15 14:55:05 -0700195 id = R.drawable.ic_search_category_suggest;
196 break;
197 case TYPE_BOOKMARK:
198 id = R.drawable.ic_search_category_bookmark;
199 break;
200 case TYPE_HISTORY:
201 id = R.drawable.ic_search_category_history;
202 break;
203 case TYPE_SUGGEST_URL:
204 id = R.drawable.ic_search_category_browser;
205 break;
206 default:
207 id = -1;
208 }
209 if (id != -1) {
210 ic1.setImageDrawable(mContext.getResources().getDrawable(id));
211 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800212 ic2.setVisibility(((TYPE_SUGGEST == item.type)
213 || (TYPE_SEARCH == item.type)
214 || (TYPE_VOICE_SEARCH == item.type))
Michael Kolb21ce4d22010-09-15 14:55:05 -0700215 ? View.VISIBLE : View.GONE);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700216 div.setVisibility(ic2.getVisibility());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700217 ic2.setOnClickListener(this);
John Reckad373302010-12-17 15:28:13 -0800218 view.findViewById(R.id.suggestion).setOnClickListener(this);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700219 }
220
John Reck35defff2010-11-11 14:06:45 -0800221 class SlowFilterTask extends AsyncTask<CharSequence, Void, List<SuggestItem>> {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700222
John Reck35defff2010-11-11 14:06:45 -0800223 @Override
224 protected List<SuggestItem> doInBackground(CharSequence... params) {
225 SuggestCursor cursor = new SuggestCursor();
226 cursor.runQuery(params[0]);
227 List<SuggestItem> results = new ArrayList<SuggestItem>();
228 int count = cursor.getCount();
229 for (int i = 0; i < count; i++) {
230 results.add(cursor.getItem());
231 cursor.moveToNext();
232 }
233 cursor.close();
234 return results;
235 }
236
237 @Override
238 protected void onPostExecute(List<SuggestItem> items) {
239 mSuggestResults = items;
240 mMixedResults = buildSuggestionResults();
241 notifyDataSetChanged();
242 mListener.onFilterComplete(mMixedResults.getLineCount());
243 }
244 }
245
246 SuggestionResults buildSuggestionResults() {
247 SuggestionResults mixed = new SuggestionResults();
248 List<SuggestItem> filter, suggest;
249 synchronized (mResultsLock) {
250 filter = mFilterResults;
251 suggest = mSuggestResults;
252 }
253 if (filter != null) {
254 for (SuggestItem item : filter) {
255 mixed.addResult(item);
256 }
257 }
258 if (suggest != null) {
259 for (SuggestItem item : suggest) {
260 mixed.addResult(item);
261 }
262 }
263 return mixed;
264 }
265
266 class SuggestFilter extends Filter {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700267
268 @Override
269 public CharSequence convertResultToString(Object item) {
270 if (item == null) {
271 return "";
272 }
273 SuggestItem sitem = (SuggestItem) item;
274 if (sitem.title != null) {
275 return sitem.title;
276 } else {
277 return sitem.url;
278 }
279 }
280
John Reck35defff2010-11-11 14:06:45 -0800281 void startSuggestionsAsync(final CharSequence constraint) {
282 new SlowFilterTask().execute(constraint);
283 }
284
Michael Kolb21ce4d22010-09-15 14:55:05 -0700285 @Override
286 protected FilterResults performFiltering(CharSequence constraint) {
287 FilterResults res = new FilterResults();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800288 if (mVoiceResults == null) {
289 if (TextUtils.isEmpty(constraint)) {
290 res.count = 0;
291 res.values = null;
292 return res;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700293 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800294 startSuggestionsAsync(constraint);
295 List<SuggestItem> filterResults = new ArrayList<SuggestItem>();
296 if (constraint != null) {
297 for (CursorSource sc : mSources) {
298 sc.runQuery(constraint);
299 }
300 mixResults(filterResults);
301 }
302 synchronized (mResultsLock) {
303 mFilterResults = filterResults;
304 }
305 SuggestionResults mixed = buildSuggestionResults();
306 res.count = mixed.getLineCount();
307 res.values = mixed;
308 } else {
309 res.count = mVoiceResults.size();
310 res.values = mVoiceResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700311 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700312 return res;
313 }
314
John Reck35defff2010-11-11 14:06:45 -0800315 void mixResults(List<SuggestItem> results) {
John Reckad373302010-12-17 15:28:13 -0800316 int maxLines = mLandscapeMode ? mLinesLandscape : mLinesPortrait;
317 maxLines = (int) Math.ceil(maxLines / 2.0);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700318 for (int i = 0; i < mSources.size(); i++) {
319 CursorSource s = mSources.get(i);
John Reck35defff2010-11-11 14:06:45 -0800320 int n = Math.min(s.getCount(), maxLines);
321 maxLines -= n;
Michael Kolb0506f2d2010-10-14 16:20:16 -0700322 boolean more = false;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700323 for (int j = 0; j < n; j++) {
John Reck35defff2010-11-11 14:06:45 -0800324 results.add(s.getItem());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700325 more = s.moveToNext();
326 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700327 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700328 }
329
330 @Override
331 protected void publishResults(CharSequence constraint, FilterResults fresults) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800332 if (fresults.values instanceof SuggestionResults) {
333 mMixedResults = (SuggestionResults) fresults.values;
334 mListener.onFilterComplete(fresults.count);
335 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700336 notifyDataSetChanged();
337 }
338
339 }
340
341 /**
342 * sorted list of results of a suggestion query
343 *
344 */
345 class SuggestionResults {
346
347 ArrayList<SuggestItem> items;
348 // count per type
349 int[] counts;
350
351 SuggestionResults() {
352 items = new ArrayList<SuggestItem>(24);
353 // n of types:
354 counts = new int[5];
355 }
356
357 int getTypeCount(int type) {
358 return counts[type];
359 }
360
361 void addResult(SuggestItem item) {
362 int ix = 0;
363 while ((ix < items.size()) && (item.type >= items.get(ix).type))
364 ix++;
365 items.add(ix, item);
366 counts[item.type]++;
367 }
368
369 int getLineCount() {
370 if (mLandscapeMode) {
John Reckad373302010-12-17 15:28:13 -0800371 return Math.min(mLinesLandscape, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700372 } else {
John Reckad373302010-12-17 15:28:13 -0800373 return Math.min(mLinesPortrait, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700374 }
375 }
376
John Reck35defff2010-11-11 14:06:45 -0800377 @Override
Michael Kolb21ce4d22010-09-15 14:55:05 -0700378 public String toString() {
379 if (items == null) return null;
380 if (items.size() == 0) return "[]";
381 StringBuilder sb = new StringBuilder();
382 for (int i = 0; i < items.size(); i++) {
383 SuggestItem item = items.get(i);
384 sb.append(item.type + ": " + item.title);
385 if (i < items.size() - 1) {
386 sb.append(", ");
387 }
388 }
389 return sb.toString();
390 }
391 }
392
393 /**
394 * data object to hold suggestion values
395 */
396 class SuggestItem {
397 String title;
398 String url;
399 int type;
John Reck40f720e2010-11-10 11:57:04 -0800400 String extra;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700401
402 public SuggestItem(String text, String u, int t) {
403 title = text;
404 url = u;
405 type = t;
406 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800407
Michael Kolb21ce4d22010-09-15 14:55:05 -0700408 }
409
410 abstract class CursorSource {
411
412 Cursor mCursor;
413
414 boolean moveToNext() {
415 return mCursor.moveToNext();
416 }
417
418 public abstract void runQuery(CharSequence constraint);
419
420 public abstract SuggestItem getItem();
421
422 public int getCount() {
423 return (mCursor != null) ? mCursor.getCount() : 0;
424 }
425
426 public void close() {
427 if (mCursor != null) {
428 mCursor.close();
429 }
430 }
431 }
432
433 /**
434 * combined bookmark & history source
435 */
436 class CombinedCursor extends CursorSource {
437
438 @Override
439 public SuggestItem getItem() {
440 if ((mCursor != null) && (!mCursor.isAfterLast())) {
441 String title = mCursor.getString(1);
442 String url = mCursor.getString(2);
443 boolean isBookmark = (mCursor.getInt(3) == 1);
444 return new SuggestItem(getTitle(title, url), getUrl(title, url),
445 isBookmark ? TYPE_BOOKMARK : TYPE_HISTORY);
446 }
447 return null;
448 }
449
450 @Override
451 public void runQuery(CharSequence constraint) {
452 // constraint != null
453 if (mCursor != null) {
454 mCursor.close();
455 }
456 String like = constraint + "%";
457 String[] args = null;
458 String selection = null;
459 if (like.startsWith("http") || like.startsWith("file")) {
460 args = new String[1];
461 args[0] = like;
462 selection = "url LIKE ?";
463 } else {
464 args = new String[5];
465 args[0] = "http://" + like;
466 args[1] = "http://www." + like;
467 args[2] = "https://" + like;
468 args[3] = "https://www." + like;
469 // To match against titles.
470 args[4] = like;
471 selection = COMBINED_SELECTION;
472 }
473 Uri.Builder ub = BrowserContract.Combined.CONTENT_URI.buildUpon();
Michael Kolb0506f2d2010-10-14 16:20:16 -0700474 ub.appendQueryParameter(BrowserContract.PARAM_LIMIT,
John Reckad373302010-12-17 15:28:13 -0800475 Integer.toString(Math.max(mLinesLandscape, mLinesPortrait)));
John Reck3dff1ce2010-12-10 11:13:57 -0800476 BookmarkUtils.addAccountInfo(mContext, ub);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700477 mCursor =
Michael Kolb0506f2d2010-10-14 16:20:16 -0700478 mContext.getContentResolver().query(ub.build(), COMBINED_PROJECTION,
Michael Kolb21ce4d22010-09-15 14:55:05 -0700479 selection,
480 (constraint != null) ? args : null,
John Reck3dff1ce2010-12-10 11:13:57 -0800481 BrowserContract.Combined.IS_BOOKMARK + " DESC, " +
Michael Kolb21ce4d22010-09-15 14:55:05 -0700482 BrowserContract.Combined.VISITS + " DESC, " +
483 BrowserContract.Combined.DATE_LAST_VISITED + " DESC");
484 if (mCursor != null) {
485 mCursor.moveToFirst();
486 }
487 }
488
489 /**
490 * Provides the title (text line 1) for a browser suggestion, which should be the
491 * webpage title. If the webpage title is empty, returns the stripped url instead.
492 *
493 * @return the title string to use
494 */
495 private String getTitle(String title, String url) {
496 if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
John Reckfb3017f2010-10-26 19:01:24 -0700497 title = UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700498 }
499 return title;
500 }
501
502 /**
503 * Provides the subtitle (text line 2) for a browser suggestion, which should be the
504 * webpage url. If the webpage title is empty, then the url should go in the title
505 * instead, and the subtitle should be empty, so this would return null.
506 *
507 * @return the subtitle string to use, or null if none
508 */
509 private String getUrl(String title, String url) {
John Reck7d132b12010-10-26 15:10:21 -0700510 if (TextUtils.isEmpty(title)
511 || TextUtils.getTrimmedLength(title) == 0
512 || title.equals(url)) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700513 return null;
514 } else {
John Reckfb3017f2010-10-26 19:01:24 -0700515 return UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700516 }
517 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700518 }
519
Michael Kolb21ce4d22010-09-15 14:55:05 -0700520 class SuggestCursor extends CursorSource {
521
522 @Override
523 public SuggestItem getItem() {
524 if (mCursor != null) {
525 String title = mCursor.getString(
526 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
527 String text2 = mCursor.getString(
528 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2));
529 String url = mCursor.getString(
530 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL));
531 String uri = mCursor.getString(
532 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA));
533 int type = (TextUtils.isEmpty(url)) ? TYPE_SUGGEST : TYPE_SUGGEST_URL;
John Reck40f720e2010-11-10 11:57:04 -0800534 SuggestItem item = new SuggestItem(title, url, type);
535 item.extra = mCursor.getString(
536 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA));
537 return item;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700538 }
539 return null;
540 }
541
542 @Override
543 public void runQuery(CharSequence constraint) {
544 if (mCursor != null) {
545 mCursor.close();
546 }
547 if (!TextUtils.isEmpty(constraint)) {
548 SearchEngine searchEngine = BrowserSettings.getInstance().getSearchEngine();
549 if (searchEngine != null && searchEngine.supportsSuggestions()) {
550 mCursor = searchEngine.getSuggestions(mContext, constraint.toString());
551 if (mCursor != null) {
552 mCursor.moveToFirst();
553 }
554 }
555 } else {
556 mCursor = null;
557 }
558 }
559
560 }
561
John Reck35defff2010-11-11 14:06:45 -0800562 public void clearCache() {
563 mFilterResults = null;
564 mSuggestResults = null;
565 }
566
Michael Kolb21ce4d22010-09-15 14:55:05 -0700567}