blob: 3c1a68948eef98569a6689f1b532f567903606a7 [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
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) {
John Reck117f07d2011-01-24 09:39:03 -0800283 if (!mIncognitoMode) {
284 new SlowFilterTask().execute(constraint);
285 }
John Reck35defff2010-11-11 14:06:45 -0800286 }
287
Michael Kolb21ce4d22010-09-15 14:55:05 -0700288 @Override
289 protected FilterResults performFiltering(CharSequence constraint) {
290 FilterResults res = new FilterResults();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800291 if (mVoiceResults == null) {
292 if (TextUtils.isEmpty(constraint)) {
293 res.count = 0;
294 res.values = null;
295 return res;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700296 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800297 startSuggestionsAsync(constraint);
298 List<SuggestItem> filterResults = new ArrayList<SuggestItem>();
299 if (constraint != null) {
300 for (CursorSource sc : mSources) {
301 sc.runQuery(constraint);
302 }
303 mixResults(filterResults);
304 }
305 synchronized (mResultsLock) {
306 mFilterResults = filterResults;
307 }
308 SuggestionResults mixed = buildSuggestionResults();
309 res.count = mixed.getLineCount();
310 res.values = mixed;
311 } else {
312 res.count = mVoiceResults.size();
313 res.values = mVoiceResults;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700314 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700315 return res;
316 }
317
John Reck35defff2010-11-11 14:06:45 -0800318 void mixResults(List<SuggestItem> results) {
John Reckad373302010-12-17 15:28:13 -0800319 int maxLines = mLandscapeMode ? mLinesLandscape : mLinesPortrait;
320 maxLines = (int) Math.ceil(maxLines / 2.0);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700321 for (int i = 0; i < mSources.size(); i++) {
322 CursorSource s = mSources.get(i);
John Reck35defff2010-11-11 14:06:45 -0800323 int n = Math.min(s.getCount(), maxLines);
324 maxLines -= n;
Michael Kolb0506f2d2010-10-14 16:20:16 -0700325 boolean more = false;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700326 for (int j = 0; j < n; j++) {
John Reck35defff2010-11-11 14:06:45 -0800327 results.add(s.getItem());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700328 more = s.moveToNext();
329 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700330 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700331 }
332
333 @Override
334 protected void publishResults(CharSequence constraint, FilterResults fresults) {
Michael Kolbcfa3af52010-12-14 10:36:11 -0800335 if (fresults.values instanceof SuggestionResults) {
336 mMixedResults = (SuggestionResults) fresults.values;
337 mListener.onFilterComplete(fresults.count);
338 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700339 notifyDataSetChanged();
340 }
341
342 }
343
344 /**
345 * sorted list of results of a suggestion query
346 *
347 */
348 class SuggestionResults {
349
350 ArrayList<SuggestItem> items;
351 // count per type
352 int[] counts;
353
354 SuggestionResults() {
355 items = new ArrayList<SuggestItem>(24);
356 // n of types:
357 counts = new int[5];
358 }
359
360 int getTypeCount(int type) {
361 return counts[type];
362 }
363
364 void addResult(SuggestItem item) {
365 int ix = 0;
366 while ((ix < items.size()) && (item.type >= items.get(ix).type))
367 ix++;
368 items.add(ix, item);
369 counts[item.type]++;
370 }
371
372 int getLineCount() {
373 if (mLandscapeMode) {
John Reckad373302010-12-17 15:28:13 -0800374 return Math.min(mLinesLandscape, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700375 } else {
John Reckad373302010-12-17 15:28:13 -0800376 return Math.min(mLinesPortrait, items.size());
Michael Kolb21ce4d22010-09-15 14:55:05 -0700377 }
378 }
379
John Reck35defff2010-11-11 14:06:45 -0800380 @Override
Michael Kolb21ce4d22010-09-15 14:55:05 -0700381 public String toString() {
382 if (items == null) return null;
383 if (items.size() == 0) return "[]";
384 StringBuilder sb = new StringBuilder();
385 for (int i = 0; i < items.size(); i++) {
386 SuggestItem item = items.get(i);
387 sb.append(item.type + ": " + item.title);
388 if (i < items.size() - 1) {
389 sb.append(", ");
390 }
391 }
392 return sb.toString();
393 }
394 }
395
396 /**
397 * data object to hold suggestion values
398 */
399 class SuggestItem {
400 String title;
401 String url;
402 int type;
John Reck40f720e2010-11-10 11:57:04 -0800403 String extra;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700404
405 public SuggestItem(String text, String u, int t) {
406 title = text;
407 url = u;
408 type = t;
409 }
Michael Kolbbd2dd642011-01-13 13:01:30 -0800410
Michael Kolb21ce4d22010-09-15 14:55:05 -0700411 }
412
413 abstract class CursorSource {
414
415 Cursor mCursor;
416
417 boolean moveToNext() {
418 return mCursor.moveToNext();
419 }
420
421 public abstract void runQuery(CharSequence constraint);
422
423 public abstract SuggestItem getItem();
424
425 public int getCount() {
426 return (mCursor != null) ? mCursor.getCount() : 0;
427 }
428
429 public void close() {
430 if (mCursor != null) {
431 mCursor.close();
432 }
433 }
434 }
435
436 /**
437 * combined bookmark & history source
438 */
439 class CombinedCursor extends CursorSource {
440
441 @Override
442 public SuggestItem getItem() {
443 if ((mCursor != null) && (!mCursor.isAfterLast())) {
444 String title = mCursor.getString(1);
445 String url = mCursor.getString(2);
446 boolean isBookmark = (mCursor.getInt(3) == 1);
447 return new SuggestItem(getTitle(title, url), getUrl(title, url),
448 isBookmark ? TYPE_BOOKMARK : TYPE_HISTORY);
449 }
450 return null;
451 }
452
453 @Override
454 public void runQuery(CharSequence constraint) {
455 // constraint != null
456 if (mCursor != null) {
457 mCursor.close();
458 }
459 String like = constraint + "%";
460 String[] args = null;
461 String selection = null;
462 if (like.startsWith("http") || like.startsWith("file")) {
463 args = new String[1];
464 args[0] = like;
465 selection = "url LIKE ?";
466 } else {
467 args = new String[5];
468 args[0] = "http://" + like;
469 args[1] = "http://www." + like;
470 args[2] = "https://" + like;
471 args[3] = "https://www." + like;
472 // To match against titles.
473 args[4] = like;
474 selection = COMBINED_SELECTION;
475 }
476 Uri.Builder ub = BrowserContract.Combined.CONTENT_URI.buildUpon();
Michael Kolb0506f2d2010-10-14 16:20:16 -0700477 ub.appendQueryParameter(BrowserContract.PARAM_LIMIT,
John Reckad373302010-12-17 15:28:13 -0800478 Integer.toString(Math.max(mLinesLandscape, mLinesPortrait)));
John Reck3dff1ce2010-12-10 11:13:57 -0800479 BookmarkUtils.addAccountInfo(mContext, ub);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700480 mCursor =
Michael Kolb0506f2d2010-10-14 16:20:16 -0700481 mContext.getContentResolver().query(ub.build(), COMBINED_PROJECTION,
Michael Kolb21ce4d22010-09-15 14:55:05 -0700482 selection,
483 (constraint != null) ? args : null,
John Reck3dff1ce2010-12-10 11:13:57 -0800484 BrowserContract.Combined.IS_BOOKMARK + " DESC, " +
Michael Kolb21ce4d22010-09-15 14:55:05 -0700485 BrowserContract.Combined.VISITS + " DESC, " +
486 BrowserContract.Combined.DATE_LAST_VISITED + " DESC");
487 if (mCursor != null) {
488 mCursor.moveToFirst();
489 }
490 }
491
492 /**
493 * Provides the title (text line 1) for a browser suggestion, which should be the
494 * webpage title. If the webpage title is empty, returns the stripped url instead.
495 *
496 * @return the title string to use
497 */
498 private String getTitle(String title, String url) {
499 if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
John Reckfb3017f2010-10-26 19:01:24 -0700500 title = UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700501 }
502 return title;
503 }
504
505 /**
506 * Provides the subtitle (text line 2) for a browser suggestion, which should be the
507 * webpage url. If the webpage title is empty, then the url should go in the title
508 * instead, and the subtitle should be empty, so this would return null.
509 *
510 * @return the subtitle string to use, or null if none
511 */
512 private String getUrl(String title, String url) {
John Reck7d132b12010-10-26 15:10:21 -0700513 if (TextUtils.isEmpty(title)
514 || TextUtils.getTrimmedLength(title) == 0
515 || title.equals(url)) {
Michael Kolb21ce4d22010-09-15 14:55:05 -0700516 return null;
517 } else {
John Reckfb3017f2010-10-26 19:01:24 -0700518 return UrlUtils.stripUrl(url);
Michael Kolb21ce4d22010-09-15 14:55:05 -0700519 }
520 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700521 }
522
Michael Kolb21ce4d22010-09-15 14:55:05 -0700523 class SuggestCursor extends CursorSource {
524
525 @Override
526 public SuggestItem getItem() {
527 if (mCursor != null) {
528 String title = mCursor.getString(
529 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
530 String text2 = mCursor.getString(
531 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2));
532 String url = mCursor.getString(
533 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL));
534 String uri = mCursor.getString(
535 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA));
536 int type = (TextUtils.isEmpty(url)) ? TYPE_SUGGEST : TYPE_SUGGEST_URL;
John Reck40f720e2010-11-10 11:57:04 -0800537 SuggestItem item = new SuggestItem(title, url, type);
538 item.extra = mCursor.getString(
539 mCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA));
540 return item;
Michael Kolb21ce4d22010-09-15 14:55:05 -0700541 }
542 return null;
543 }
544
545 @Override
546 public void runQuery(CharSequence constraint) {
547 if (mCursor != null) {
548 mCursor.close();
549 }
550 if (!TextUtils.isEmpty(constraint)) {
551 SearchEngine searchEngine = BrowserSettings.getInstance().getSearchEngine();
552 if (searchEngine != null && searchEngine.supportsSuggestions()) {
553 mCursor = searchEngine.getSuggestions(mContext, constraint.toString());
554 if (mCursor != null) {
555 mCursor.moveToFirst();
556 }
557 }
558 } else {
559 mCursor = null;
560 }
561 }
562
563 }
564
John Reck35defff2010-11-11 14:06:45 -0800565 public void clearCache() {
566 mFilterResults = null;
567 mSuggestResults = null;
568 }
569
John Reck117f07d2011-01-24 09:39:03 -0800570 public void setIncognitoMode(boolean incognito) {
571 mIncognitoMode = incognito;
572 clearCache();
573 }
Michael Kolb21ce4d22010-09-15 14:55:05 -0700574}