1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.browser;
7 import android.app.SearchManager;
8 import android.content.Intent;
9 import android.database.AbstractCursor;
10 import android.database.Cursor;
11 import android.provider.BaseColumns;
12 import android.provider.Browser.BookmarkColumns;
14 import org.chromium.chrome.R;
17 * For bookmarks/history suggestions, wrap the cursor returned in one that can feed
18 * the data back to global search in the format it wants.
20 class ChromeBrowserProviderSuggestionsCursor extends AbstractCursor {
22 private static final String[] COLS = new String [] {
24 SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
25 SearchManager.SUGGEST_COLUMN_INTENT_DATA,
26 SearchManager.SUGGEST_COLUMN_TEXT_1,
27 SearchManager.SUGGEST_COLUMN_TEXT_2,
28 SearchManager.SUGGEST_COLUMN_TEXT_2_URL,
29 SearchManager.SUGGEST_COLUMN_ICON_1,
30 SearchManager.SUGGEST_COLUMN_LAST_ACCESS_HINT
33 private static final int COLUMN_ID = 0;
34 private static final int COLUMN_SUGGEST_INTENT_ACTION = 1;
35 private static final int COLUMN_SUGGEST_INTENT_DATA = 2;
36 private static final int COLUMN_SUGGEST_TEXT_1 = 3;
37 private static final int COLUMN_SUGGEST_TEXT_2 = 4;
38 private static final int COLUMN_SUGGEST_TEXT_2_URL = 5;
39 private static final int COLUMN_SUGGEST_ICON_1 = 6;
40 private static final int COLUMN_SUGGEST_LAST_ACCESS_HINT = 7;
42 private Cursor mCursor;
44 public ChromeBrowserProviderSuggestionsCursor(Cursor c) {
49 public String[] getColumnNames() {
54 public int getCount() {
55 return mCursor.getCount();
59 public String getString(int column) {
62 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns._ID));
63 case COLUMN_SUGGEST_INTENT_ACTION:
64 return Intent.ACTION_VIEW;
65 case COLUMN_SUGGEST_INTENT_DATA:
66 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL));
67 case COLUMN_SUGGEST_TEXT_1:
68 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.TITLE));
69 case COLUMN_SUGGEST_TEXT_2:
70 case COLUMN_SUGGEST_TEXT_2_URL:
71 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL));
72 case COLUMN_SUGGEST_ICON_1:
73 // This is the icon displayed to the left of the result in QSB.
74 return Integer.toString(R.mipmap.app_icon);
75 case COLUMN_SUGGEST_LAST_ACCESS_HINT:
76 // After clearing history, the Chrome bookmarks database will have a last
77 // access time of 0 for all bookmarks. In the Android provider, this will
78 // yield a negative last access time. A negative last access time will
79 // cause global search to discard the result, so fix it up before
81 long lastAccess = mCursor.getLong(
82 mCursor.getColumnIndex(BookmarkColumns.DATE));
83 return lastAccess < 0 ? "0" : "" + lastAccess;
85 throw new UnsupportedOperationException();
90 public boolean isNull(int c) {
91 return mCursor.isNull(c);
95 public long getLong(int c) {
98 // See comments above in getString() re. negative last access times.
99 long lastAccess = mCursor.getLong(
100 mCursor.getColumnIndex(BookmarkColumns.DATE));
101 return lastAccess < 0 ? 0 : lastAccess;
103 throw new UnsupportedOperationException();
108 public short getShort(int c) {
109 throw new UnsupportedOperationException();
113 public double getDouble(int c) {
114 throw new UnsupportedOperationException();
118 public int getInt(int c) {
119 throw new UnsupportedOperationException();
123 public float getFloat(int c) {
124 throw new UnsupportedOperationException();
128 public boolean onMove(int oldPosition, int newPosition) {
129 return mCursor.moveToPosition(newPosition);