blob: 3636bbf09383f985e43c7b8d026f56261e04976a [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;
John Reckdd7d7512011-01-17 13:08:30 -080048 static final int TYPE_HISTORY = 1;
49 static final int TYPE_SUGGEST_URL = 2;
John Reck35defff2010-11-11 14:06:45 -080050 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;
John Reck117f07d2011-01-24 09:39:03 -080073 boolean mIncognitoMode;
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
81 }
82
83 public SuggestionsAdapter(Context ctx, CompletionListener listener) {
84 mContext = ctx;
85 mListener = listener;
86 mLinesPortrait = mContext.getResources().
87 getInteger(R.integer.max_suggest_lines_portrait);
88 mLinesLandscape = mContext.getResources().
89 getInteger(R.integer.max_suggest_lines_landscape);
90 mFilter = new SuggestFilter();
Michael Kolb21ce4d22010-09-15 14:55:05 -070091 addSource(new CombinedCursor());
92 }
93
Michael Kolbcfa3af52010-12-14 10:36:11 -080094 void setVoiceResults(List<String> voiceResults) {
95 mVoiceResults = voiceResults;
Michael Kolba50c4462010-12-15 10:49:12 -080096 notifyDataSetChanged();
Michael Kolbcfa3af52010-12-14 10:36:11 -080097 }
98
Michael Kolb21ce4d22010-09-15 14:55:05 -070099 public void setLandscapeMode(boolean mode) {
100 mLandscapeMode = mode;
John Reck35defff2010-11-11 14:06:45 -0800101 notifyDataSetChanged();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700102 }
103
Michael Kolb21ce4d22010-09-15 14:55:05 -0700104 public void addSource(CursorSource c) {
105 if (mSources == null) {
106 mSources = new ArrayList<CursorSource>(5);
107 }
108 mSources.add(c);
109 }
110
111 @Override
112 public void onClick(View v) {
John Reckad373302010-12-17 15:28:13 -0800113 SuggestItem item = (SuggestItem) ((View) v.getParent()).getTag();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700114 if (R.id.icon2 == v.getId()) {
115 // replace input field text with suggestion text
Michael Kolb21ce4d22010-09-15 14:55:05 -0700116 mListener.onSearch(item.title);
117 } else {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800118 mListener.onSelect(
119 (TextUtils.isEmpty(item.url)? item.title : item.url),
120 item.type, item.extra);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700121 }
122 }
123
124 @Override
125 public Filter getFilter() {
126 return mFilter;
127 }
128
129 @Override
130 public int getCount() {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800131 if (mVoiceResults != null) {
132 return mVoiceResults.size();
133 }
John Reck35defff2010-11-11 14:06:45 -0800134 return (mMixedResults == null) ? 0 : mMixedResults.getLineCount();
Michael Kolb21ce4d22010-09-15 14:55:05 -0700135 }
136
137 @Override
138 public SuggestItem getItem(int position) {
John Reck1605bef2011-01-10 18:11:18 -0800139 if (mReverseResults) {
140 position = (getCount() - 1) - position;
141 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800142 if (mVoiceResults != null) {
Michael Kolbbd2dd642011-01-13 13:01:30 -0800143 SuggestItem item = new SuggestItem(mVoiceResults.get(position),
144 null, TYPE_VOICE_SEARCH);
145 item.extra = Integer.toString(position);
146 return item;
Michael Kolbcfa3af52010-12-14 10:36:11 -0800147 }
John Reck35defff2010-11-11 14:06:45 -0800148 if (mMixedResults == null) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700149 return null;
150 }
John Reckad373302010-12-17 15:28:13 -0800151 return mMixedResults.items.get(position);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700152 }
153
John Reck1605bef2011-01-10 18:11:18 -0800154 public void setReverseResults(boolean reverse) {
155 mReverseResults = reverse;
156 }
157
Michael Kolb21ce4d22010-09-15 14:55:05 -0700158 @Override
159 public long getItemId(int position) {
John Reck1605bef2011-01-10 18:11:18 -0800160 return position;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700161 }
162
163 @Override
164 public View getView(int position, View convertView, ViewGroup parent) {
165 final LayoutInflater inflater = LayoutInflater.from(mContext);
John Reck35defff2010-11-11 14:06:45 -0800166 View view = convertView;
167 if (view == null) {
John Reckad373302010-12-17 15:28:13 -0800168 view = inflater.inflate(R.layout.suggestion_item, parent, false);
John Reck35defff2010-11-11 14:06:45 -0800169 }
John Reckad373302010-12-17 15:28:13 -0800170 bindView(view, getItem(position));
171 return view;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700172 }
173
174 private void bindView(View view, SuggestItem item) {
175 // store item for click handling
176 view.setTag(item);
177 TextView tv1 = (TextView) view.findViewById(android.R.id.text1);
178 TextView tv2 = (TextView) view.findViewById(android.R.id.text2);
179 ImageView ic1 = (ImageView) view.findViewById(R.id.icon1);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700180 View ic2 = view.findViewById(R.id.icon2);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700181 View div = view.findViewById(R.id.divider);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700182 tv1.setText(item.title);
John Reckad373302010-12-17 15:28:13 -0800183 if (TextUtils.isEmpty(item.url)) {
184 tv2.setVisibility(View.GONE);
185 } else {
186 tv2.setVisibility(View.VISIBLE);
187 tv2.setText(item.url);
188 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700189 int id = -1;
190 switch (item.type) {
191 case TYPE_SUGGEST:
192 case TYPE_SEARCH:
Michael Kolbbd2dd642011-01-13 13:01:30 -0800193 case TYPE_VOICE_SEARCH:
Michael Kolb21ce4d22010-09-15 14:55:05 -0700194 id = R.drawable.ic_search_category_suggest;
195 break;
196 case TYPE_BOOKMARK:
197 id = R.drawable.ic_search_category_bookmark;
198 break;
199 case TYPE_HISTORY:
200 id = R.drawable.ic_search_category_history;
201 break;
202 case TYPE_SUGGEST_URL:
203 id = R.drawable.ic_search_category_browser;
204 break;
205 default:
206 id = -1;
207 }
208 if (id != -1) {
209 ic1.setImageDrawable(mContext.getResources().getDrawable(id));
210 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800211 ic2.setVisibility(((TYPE_SUGGEST == item.type)
212 || (TYPE_SEARCH == item.type)
213 || (TYPE_VOICE_SEARCH == item.type))
Michael Kolb21ce4d22010-09-15 14:55:05 -0700214 ? View.VISIBLE : View.GONE);
Michael Kolb7b20ddd2010-10-14 15:03:28 -0700215 div.setVisibility(ic2.getVisibility());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700216 ic2.setOnClickListener(this);
John Reckad373302010-12-17 15:28:13 -0800217 view.findViewById(R.id.suggestion).setOnClickListener(this);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700218 }
219
John Reck35defff2010-11-11 14:06:45 -0800220 class SlowFilterTask extends AsyncTask<CharSequence, Void, List<SuggestItem>> {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700221
John Reck35defff2010-11-11 14:06:45 -0800222 @Override
223 protected List<SuggestItem> doInBackground(CharSequence... params) {
224 SuggestCursor cursor = new SuggestCursor();
225 cursor.runQuery(params[0]);
226 List<SuggestItem> results = new ArrayList<SuggestItem>();
227 int count = cursor.getCount();
228 for (int i = 0; i < count; i++) {
229 results.add(cursor.getItem());
230 cursor.moveToNext();
231 }
232 cursor.close();
233 return results;
234 }
235
236 @Override
237 protected void onPostExecute(List<SuggestItem> items) {
238 mSuggestResults = items;
239 mMixedResults = buildSuggestionResults();
240 notifyDataSetChanged();
John Reck35defff2010-11-11 14:06:45 -0800241 }
242 }
243
244 SuggestionResults buildSuggestionResults() {
245 SuggestionResults mixed = new SuggestionResults();
246 List<SuggestItem> filter, suggest;
247 synchronized (mResultsLock) {
248 filter = mFilterResults;
249 suggest = mSuggestResults;
250 }
251 if (filter != null) {
252 for (SuggestItem item : filter) {
253 mixed.addResult(item);
254 }
255 }
256 if (suggest != null) {
257 for (SuggestItem item : suggest) {
258 mixed.addResult(item);
259 }
260 }
261 return mixed;
262 }
263
264 class SuggestFilter extends Filter {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700265
266 @Override
267 public CharSequence convertResultToString(Object item) {
268 if (item == null) {
269 return "";
270 }
271 SuggestItem sitem = (SuggestItem) item;
272 if (sitem.title != null) {
273 return sitem.title;
274 } else {
275 return sitem.url;
276 }
277 }
278
John Reck35defff2010-11-11 14:06:45 -0800279 void startSuggestionsAsync(final CharSequence constraint) {
John Reck117f07d2011-01-24 09:39:03 -0800280 if (!mIncognitoMode) {
281 new SlowFilterTask().execute(constraint);
282 }
John Reck35defff2010-11-11 14:06:45 -0800283 }
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;
John Recka005cd72011-02-01 11:46:53 -0800334 notifyDataSetChanged();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800335 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700336 }
337
338 }
339
340 /**
341 * sorted list of results of a suggestion query
342 *
343 */
344 class SuggestionResults {
345
346 ArrayList<SuggestItem> items;
347 // count per type
348 int[] counts;
349
350 SuggestionResults() {
351 items = new ArrayList<SuggestItem>(24);
352 // n of types:
353 counts = new int[5];
354 }
355
356 int getTypeCount(int type) {
357 return counts[type];
358 }
359
360 void addResult(SuggestItem item) {
361 int ix = 0;
362 while ((ix < items.size()) && (item.type >= items.get(ix).type))
363 ix++;
364 items.add(ix, item);
365 counts[item.type]++;
366 }
367
368 int getLineCount() {
369 if (mLandscapeMode) {
John Reckad373302010-12-17 15:28:13 -0800370 return Math.min(mLinesLandscape, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700371 } else {
John Reckad373302010-12-17 15:28:13 -0800372 return Math.min(mLinesPortrait, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700373 }
374 }
375
John Reck35defff2010-11-11 14:06:45 -0800376 @Override
Michael Kolb21ce4d22010-09-15 14:55:05 -0700377 public String toString() {
378 if (items == null) return null;
379 if (items.size() == 0) return "[]";
380 StringBuilder sb = new StringBuilder();
381 for (int i = 0; i < items.size(); i++) {
382 SuggestItem item = items.get(i);
383 sb.append(item.type + ": " + item.title);
384 if (i < items.size() - 1) {
385 sb.append(", ");
386 }
387 }
388 return sb.toString();
389 }
390 }
391
392 /**
393 * data object to hold suggestion values
394 */
Narayan Kamath80aad8d2011-02-23 12:01:13 +0000395 public class SuggestItem {
396 public String title;
397 public String url;
398 public int type;
399 public String extra;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700400
401 public SuggestItem(String text, String u, int t) {
402 title = text;
403 url = u;
404 type = t;
405 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800406
Michael Kolb21ce4d22010-09-15 14:55:05 -0700407 }
408
409 abstract class CursorSource {
410
411 Cursor mCursor;
412
413 boolean moveToNext() {
414 return mCursor.moveToNext();
415 }
416
417 public abstract void runQuery(CharSequence constraint);
418
419 public abstract SuggestItem getItem();
420
421 public int getCount() {
422 return (mCursor != null) ? mCursor.getCount() : 0;
423 }
424
425 public void close() {
426 if (mCursor != null) {
427 mCursor.close();
428 }
429 }
430 }
431
432 /**
433 * combined bookmark & history source
434 */
435 class CombinedCursor extends CursorSource {
436
437 @Override
438 public SuggestItem getItem() {
439 if ((mCursor != null) && (!mCursor.isAfterLast())) {
440 String title = mCursor.getString(1);
441 String url = mCursor.getString(2);
442 boolean isBookmark = (mCursor.getInt(3) == 1);
443 return new SuggestItem(getTitle(title, url), getUrl(title, url),
444 isBookmark ? TYPE_BOOKMARK : TYPE_HISTORY);
445 }
446 return null;
447 }
448
449 @Override
450 public void runQuery(CharSequence constraint) {
451 // constraint != null
452 if (mCursor != null) {
453 mCursor.close();
454 }
455 String like = constraint + "%";
456 String[] args = null;
457 String selection = null;
458 if (like.startsWith("http") || like.startsWith("file")) {
459 args = new String[1];
460 args[0] = like;
461 selection = "url LIKE ?";
462 } else {
463 args = new String[5];
464 args[0] = "http://" + like;
465 args[1] = "http://www." + like;
466 args[2] = "https://" + like;
467 args[3] = "https://www." + like;
468 // To match against titles.
469 args[4] = like;
470 selection = COMBINED_SELECTION;
471 }
472 Uri.Builder ub = BrowserContract.Combined.CONTENT_URI.buildUpon();
Michael Kolb0506f2d2010-10-14 16:20:16 -0700473 ub.appendQueryParameter(BrowserContract.PARAM_LIMIT,
John Reckad373302010-12-17 15:28:13 -0800474 Integer.toString(Math.max(mLinesLandscape, mLinesPortrait)));
John Reck3dff1ce2010-12-10 11:13:57 -0800475 BookmarkUtils.addAccountInfo(mContext, ub);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700476 mCursor =
Michael Kolb0506f2d2010-10-14 16:20:16 -0700477 mContext.getContentResolver().query(ub.build(), COMBINED_PROJECTION,
Michael Kolb21ce4d22010-09-15 14:55:05 -0700478 selection,
479 (constraint != null) ? args : null,
John Reck3dff1ce2010-12-10 11:13:57 -0800480 BrowserContract.Combined.IS_BOOKMARK + " DESC, " +
Michael Kolb21ce4d22010-09-15 14:55:05 -0700481 BrowserContract.Combined.VISITS + " DESC, " +
482 BrowserContract.Combined.DATE_LAST_VISITED + " DESC");
483 if (mCursor != null) {
484 mCursor.moveToFirst();
485 }
486 }
487
488 /**
489 * Provides the title (text line 1) for a browser suggestion, which should be the
490 * webpage title. If the webpage title is empty, returns the stripped url instead.
491 *
492 * @return the title string to use
493 */
494 private String getTitle(String title, String url) {
495 if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
John Reckfb3017f2010-10-26 19:01:24 -0700496 title = UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700497 }
498 return title;
499 }
500
501 /**
502 * Provides the subtitle (text line 2) for a browser suggestion, which should be the
503 * webpage url. If the webpage title is empty, then the url should go in the title
504 * instead, and the subtitle should be empty, so this would return null.
505 *
506 * @return the subtitle string to use, or null if none
507 */
508 private String getUrl(String title, String url) {
John Reck7d132b12010-10-26 15:10:21 -0700509 if (TextUtils.isEmpty(title)
510 || TextUtils.getTrimmedLength(title) == 0
511 || title.equals(url)) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700512 return null;
513 } else {
John Reckfb3017f2010-10-26 19:01:24 -0700514 return UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700515 }
516 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700517 }
518
Michael Kolb21ce4d22010-09-15 14:55:05 -0700519 class SuggestCursor extends CursorSource {
520
521 @Override
522 public SuggestItem getItem() {
523 if (mCursor != null) {
524 String title = mCursor.getString(
525 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
526 String text2 = mCursor.getString(
527 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2));
528 String url = mCursor.getString(
529 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL));
530 String uri = mCursor.getString(
531 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA));
532 int type = (TextUtils.isEmpty(url)) ? TYPE_SUGGEST : TYPE_SUGGEST_URL;
John Reck40f720e2010-11-10 11:57:04 -0800533 SuggestItem item = new SuggestItem(title, url, type);
534 item.extra = mCursor.getString(
535 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA));
536 return item;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700537 }
538 return null;
539 }
540
541 @Override
542 public void runQuery(CharSequence constraint) {
543 if (mCursor != null) {
544 mCursor.close();
545 }
546 if (!TextUtils.isEmpty(constraint)) {
547 SearchEngine searchEngine = BrowserSettings.getInstance().getSearchEngine();
548 if (searchEngine != null && searchEngine.supportsSuggestions()) {
549 mCursor = searchEngine.getSuggestions(mContext, constraint.toString());
550 if (mCursor != null) {
551 mCursor.moveToFirst();
552 }
553 }
554 } else {
555 mCursor = null;
556 }
557 }
558
559 }
560
John Reck35defff2010-11-11 14:06:45 -0800561 public void clearCache() {
562 mFilterResults = null;
563 mSuggestResults = null;
564 }
565
John Reck117f07d2011-01-24 09:39:03 -0800566 public void setIncognitoMode(boolean incognito) {
567 mIncognitoMode = incognito;
568 clearCache();
569 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700570}