Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..283250233224c5d3a34b41ef63268d5cc9324cff |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java |
| @@ -0,0 +1,119 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser; |
| + |
| +import android.app.SearchManager; |
| +import android.content.Intent; |
| +import android.database.AbstractCursor; |
| +import android.database.Cursor; |
| +import android.provider.BaseColumns; |
| +import android.provider.Browser.BookmarkColumns; |
| + |
| +import org.chromium.content.app.AppResource; |
| + |
| +// For bookmarks/history suggestions, wrap the cursor returned in one that can feed |
|
Yaron
2012/09/10 19:30:04
This should be javadoc
Leandro Gracia Gil
2012/09/10 22:21:48
Done.
|
| +// the data back to global search in the format it wants. |
| +class ChromeBrowserProviderSuggestionsCursor extends AbstractCursor { |
| + Cursor mCursor; |
| + private static final String[] COLS = new String [] { |
| + BaseColumns._ID, // 0 |
| + SearchManager.SUGGEST_COLUMN_INTENT_ACTION, // 1 |
| + SearchManager.SUGGEST_COLUMN_INTENT_DATA, // 2 |
| + SearchManager.SUGGEST_COLUMN_TEXT_1, // 3 |
| + SearchManager.SUGGEST_COLUMN_TEXT_2, // 4 |
| + SearchManager.SUGGEST_COLUMN_TEXT_2_URL, // 5 |
| + SearchManager.SUGGEST_COLUMN_ICON_1, // 6 |
| + SearchManager.SUGGEST_COLUMN_LAST_ACCESS_HINT // 7 |
| + }; |
| + |
| + public ChromeBrowserProviderSuggestionsCursor(Cursor c) { |
| + mCursor = c; |
| + } |
| + |
| + @Override |
| + public String[] getColumnNames() { |
| + return COLS; |
| + } |
| + |
| + @Override |
| + public int getCount() { |
| + return mCursor.getCount(); |
| + } |
| + |
| + @Override |
| + public String getString(int column) { |
| + switch (column) { |
| + case 0: |
|
Yaron
2012/09/10 19:30:04
What constants do these map to? Can we used name c
Leandro Gracia Gil
2012/09/10 22:21:48
This is Michael's code, although I think the value
|
| + return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns._ID)); |
| + case 1: |
| + return Intent.ACTION_VIEW; |
| + case 2: |
| + return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL)); |
| + case 3: |
| + return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.TITLE)); |
| + case 4: |
| + case 5: |
| + return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL)); |
| + case 6: |
| + // This is the icon displayed to the left of the result in QSB. |
| + assert AppResource.DRAWABLE_ICON_APP_ICON != 0; |
| + return Integer.toString(AppResource.DRAWABLE_ICON_APP_ICON); |
| + case 7: |
| + // After clearing history, the Chrome bookmarks database will have a last |
| + // access time of 0 for all bookmarks. In the Android provider, this will |
| + // yield a negative last access time. A negative last access time will |
| + // cause global search to discard the result, so fix it up before |
| + // we return it. |
| + long lastAccess = mCursor.getLong( |
| + mCursor.getColumnIndex(BookmarkColumns.DATE)); |
| + return lastAccess < 0 ? "0" : "" + lastAccess; |
| + default: |
| + throw new UnsupportedOperationException(); |
| + } |
| + } |
| + |
| + @Override |
| + public boolean isNull(int c) { |
| + return mCursor.isNull(c); |
| + } |
| + |
| + @Override |
| + public long getLong(int c) { |
| + switch (c) { |
| + case 7: |
| + // See comments above in getString() re. negative last access times. |
| + long lastAccess = mCursor.getLong( |
| + mCursor.getColumnIndex(BookmarkColumns.DATE)); |
| + return lastAccess < 0 ? 0 : lastAccess; |
| + default: |
| + throw new UnsupportedOperationException(); |
| + } |
| + } |
| + |
| + @Override |
| + public short getShort(int c) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public double getDouble(int c) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public int getInt(int c) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public float getFloat(int c) { |
| + throw new UnsupportedOperationException(); |
| + } |
| + |
| + @Override |
| + public boolean onMove(int oldPosition, int newPosition) { |
| + return mCursor.moveToPosition(newPosition); |
| + } |
| +} |