Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeBrowserProviderSuggestionsCursor.java

Issue 10912172: [Android] Upstream ChromeBrowserProvider, the Android port ContentProvider implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 package org.chromium.chrome.browser;
6
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;
13
14 import org.chromium.content.app.AppResource;
15
16 // For bookmarks/history suggestions, wrap the cursor returned in one that can f eed
Yaron 2012/09/10 19:30:04 This should be javadoc
Leandro Gracia Gil 2012/09/10 22:21:48 Done.
17 // the data back to global search in the format it wants.
18 class ChromeBrowserProviderSuggestionsCursor extends AbstractCursor {
19 Cursor mCursor;
20 private static final String[] COLS = new String [] {
21 BaseColumns._ID, // 0
22 SearchManager.SUGGEST_COLUMN_INTENT_ACTION, // 1
23 SearchManager.SUGGEST_COLUMN_INTENT_DATA, // 2
24 SearchManager.SUGGEST_COLUMN_TEXT_1, // 3
25 SearchManager.SUGGEST_COLUMN_TEXT_2, // 4
26 SearchManager.SUGGEST_COLUMN_TEXT_2_URL, // 5
27 SearchManager.SUGGEST_COLUMN_ICON_1, // 6
28 SearchManager.SUGGEST_COLUMN_LAST_ACCESS_HINT // 7
29 };
30
31 public ChromeBrowserProviderSuggestionsCursor(Cursor c) {
32 mCursor = c;
33 }
34
35 @Override
36 public String[] getColumnNames() {
37 return COLS;
38 }
39
40 @Override
41 public int getCount() {
42 return mCursor.getCount();
43 }
44
45 @Override
46 public String getString(int column) {
47 switch (column) {
48 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
49 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns._ID) );
50 case 1:
51 return Intent.ACTION_VIEW;
52 case 2:
53 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL) );
54 case 3:
55 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.TITL E));
56 case 4:
57 case 5:
58 return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL) );
59 case 6:
60 // This is the icon displayed to the left of the result in QSB.
61 assert AppResource.DRAWABLE_ICON_APP_ICON != 0;
62 return Integer.toString(AppResource.DRAWABLE_ICON_APP_ICON);
63 case 7:
64 // After clearing history, the Chrome bookmarks database will have a last
65 // access time of 0 for all bookmarks. In the Android provider, this will
66 // yield a negative last access time. A negative last access time wi ll
67 // cause global search to discard the result, so fix it up before
68 // we return it.
69 long lastAccess = mCursor.getLong(
70 mCursor.getColumnIndex(BookmarkColumns.DATE));
71 return lastAccess < 0 ? "0" : "" + lastAccess;
72 default:
73 throw new UnsupportedOperationException();
74 }
75 }
76
77 @Override
78 public boolean isNull(int c) {
79 return mCursor.isNull(c);
80 }
81
82 @Override
83 public long getLong(int c) {
84 switch (c) {
85 case 7:
86 // See comments above in getString() re. negative last access ti mes.
87 long lastAccess = mCursor.getLong(
88 mCursor.getColumnIndex(BookmarkColumns.DATE));
89 return lastAccess < 0 ? 0 : lastAccess;
90 default:
91 throw new UnsupportedOperationException();
92 }
93 }
94
95 @Override
96 public short getShort(int c) {
97 throw new UnsupportedOperationException();
98 }
99
100 @Override
101 public double getDouble(int c) {
102 throw new UnsupportedOperationException();
103 }
104
105 @Override
106 public int getInt(int c) {
107 throw new UnsupportedOperationException();
108 }
109
110 @Override
111 public float getFloat(int c) {
112 throw new UnsupportedOperationException();
113 }
114
115 @Override
116 public boolean onMove(int oldPosition, int newPosition) {
117 return mCursor.moveToPosition(newPosition);
118 }
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698