android.provider.Browser.BookmarkColumns Java Examples
The following examples show how to use
android.provider.Browser.BookmarkColumns.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 7 votes |
private long addBookmark(ContentValues values) { String url = values.getAsString(Browser.BookmarkColumns.URL); String title = values.getAsString(Browser.BookmarkColumns.TITLE); boolean isFolder = false; if (values.containsKey(BOOKMARK_IS_FOLDER_PARAM)) { isFolder = values.getAsBoolean(BOOKMARK_IS_FOLDER_PARAM); } long parentId = INVALID_BOOKMARK_ID; if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) { parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM); } long id = nativeAddBookmark(mNativeChromeBrowserProvider, url, title, isFolder, parentId); if (id == INVALID_BOOKMARK_ID) return id; if (isFolder) { updateLastModifiedBookmarkFolder(id); } else { updateLastModifiedBookmarkFolder(parentId); } return id; }
Example #2
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
private long addBookmark(ContentValues values) { String url = values.getAsString(Browser.BookmarkColumns.URL); String title = values.getAsString(Browser.BookmarkColumns.TITLE); boolean isFolder = false; if (values.containsKey(BOOKMARK_IS_FOLDER_PARAM)) { isFolder = values.getAsBoolean(BOOKMARK_IS_FOLDER_PARAM); } long parentId = INVALID_BOOKMARK_ID; if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) { parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM); } long id = nativeAddBookmark(mNativeChromeBrowserProvider, url, title, isFolder, parentId); if (id == INVALID_BOOKMARK_ID) return id; if (isFolder) { updateLastModifiedBookmarkFolder(id); } else { updateLastModifiedBookmarkFolder(parentId); } return id; }
Example #3
Source File: ChromeBrowserProviderSuggestionsCursor.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public String getString(int column) { switch (column) { case COLUMN_ID: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns._ID)); case COLUMN_SUGGEST_INTENT_ACTION: return Intent.ACTION_VIEW; case COLUMN_SUGGEST_INTENT_DATA: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL)); case COLUMN_SUGGEST_TEXT_1: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.TITLE)); case COLUMN_SUGGEST_TEXT_2: case COLUMN_SUGGEST_TEXT_2_URL: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL)); case COLUMN_SUGGEST_ICON_1: // This is the icon displayed to the left of the result in QSB. return Integer.toString(R.mipmap.app_icon); case COLUMN_SUGGEST_LAST_ACCESS_HINT: // 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(); } }
Example #4
Source File: ChromeBrowserProviderSuggestionsCursor.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@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(); } }
Example #5
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Uri insert(Uri uri, ContentValues values) { if (!canHandleContentProviderApiCall()) return null; int match = mUriMatcher.match(uri); Uri res = null; long id; switch (match) { case URI_MATCH_BOOKMARKS: id = addBookmark(values); if (id == INVALID_BOOKMARK_ID) return null; break; case URL_MATCH_API_BOOKMARK_CONTENT: values.put(BookmarkColumns.BOOKMARK, 1); //$FALL-THROUGH$ case URL_MATCH_API_BOOKMARK: case URL_MATCH_API_HISTORY_CONTENT: id = addBookmarkFromAPI(values); if (id == INVALID_CONTENT_PROVIDER_ID) return null; break; case URL_MATCH_API_SEARCHES: id = addSearchTermFromAPI(values); if (id == INVALID_CONTENT_PROVIDER_ID) return null; break; default: throw new IllegalArgumentException(TAG + ": insert - unknown URL " + uri); } res = ContentUris.withAppendedId(uri, id); getContext().getContentResolver().notifyChange(res, null); return res; }
Example #6
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return a SQL where class which is inserted the bookmark condition. */ private static String buildBookmarkWhereClause(String selection, boolean is_bookmark) { StringBuffer sb = new StringBuffer(); sb.append(BookmarkColumns.BOOKMARK); sb.append(is_bookmark ? " = 1 " : " = 0"); if (!TextUtils.isEmpty(selection)) { sb.append(" AND ("); sb.append(selection); sb.append(")"); } return sb.toString(); }
Example #7
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
static BookmarkRow fromContentValues(ContentValues values) { BookmarkRow row = new BookmarkRow(); if (values.containsKey(BookmarkColumns.URL)) { row.url = values.getAsString(BookmarkColumns.URL); } if (values.containsKey(BookmarkColumns.BOOKMARK)) { row.isBookmark = values.getAsInteger(BookmarkColumns.BOOKMARK) != 0; } if (values.containsKey(BookmarkColumns.CREATED)) { row.created = values.getAsLong(BookmarkColumns.CREATED); } if (values.containsKey(BookmarkColumns.DATE)) { row.date = values.getAsLong(BookmarkColumns.DATE); } if (values.containsKey(BookmarkColumns.FAVICON)) { row.favicon = values.getAsByteArray(BookmarkColumns.FAVICON); // We need to know that the caller set the favicon column. if (row.favicon == null) { row.favicon = new byte[0]; } } if (values.containsKey(BookmarkColumns.TITLE)) { row.title = values.getAsString(BookmarkColumns.TITLE); } if (values.containsKey(BookmarkColumns.VISITS)) { row.visits = values.getAsInteger(BookmarkColumns.VISITS); } if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) { row.parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM); } return row; }
Example #8
Source File: ChromeBrowserProviderSuggestionsCursor.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public String getString(int column) { switch (column) { case COLUMN_ID: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns._ID)); case COLUMN_SUGGEST_INTENT_ACTION: return Intent.ACTION_VIEW; case COLUMN_SUGGEST_INTENT_DATA: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL)); case COLUMN_SUGGEST_TEXT_1: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.TITLE)); case COLUMN_SUGGEST_TEXT_2: case COLUMN_SUGGEST_TEXT_2_URL: return mCursor.getString(mCursor.getColumnIndex(BookmarkColumns.URL)); case COLUMN_SUGGEST_ICON_1: // This is the icon displayed to the left of the result in QSB. return Integer.toString(R.mipmap.app_icon); case COLUMN_SUGGEST_LAST_ACCESS_HINT: // 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(); } }
Example #9
Source File: ChromeBrowserProviderSuggestionsCursor.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@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(); } }
Example #10
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Uri insert(Uri uri, ContentValues values) { if (!canHandleContentProviderApiCall()) return null; int match = mUriMatcher.match(uri); Uri res = null; long id; switch (match) { case URI_MATCH_BOOKMARKS: id = addBookmark(values); if (id == INVALID_BOOKMARK_ID) return null; break; case URL_MATCH_API_BOOKMARK_CONTENT: values.put(BookmarkColumns.BOOKMARK, 1); //$FALL-THROUGH$ case URL_MATCH_API_BOOKMARK: case URL_MATCH_API_HISTORY_CONTENT: id = addBookmarkFromAPI(values); if (id == INVALID_CONTENT_PROVIDER_ID) return null; break; case URL_MATCH_API_SEARCHES: id = addSearchTermFromAPI(values); if (id == INVALID_CONTENT_PROVIDER_ID) return null; break; default: throw new IllegalArgumentException(TAG + ": insert - unknown URL " + uri); } res = ContentUris.withAppendedId(uri, id); getContext().getContentResolver().notifyChange(res, null); return res; }
Example #11
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return a SQL where class which is inserted the bookmark condition. */ private static String buildBookmarkWhereClause(String selection, boolean is_bookmark) { StringBuffer sb = new StringBuffer(); sb.append(BookmarkColumns.BOOKMARK); sb.append(is_bookmark ? " = 1 " : " = 0"); if (!TextUtils.isEmpty(selection)) { sb.append(" AND ("); sb.append(selection); sb.append(")"); } return sb.toString(); }
Example #12
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
static BookmarkRow fromContentValues(ContentValues values) { BookmarkRow row = new BookmarkRow(); if (values.containsKey(BookmarkColumns.URL)) { row.url = values.getAsString(BookmarkColumns.URL); } if (values.containsKey(BookmarkColumns.BOOKMARK)) { row.isBookmark = values.getAsInteger(BookmarkColumns.BOOKMARK) != 0; } if (values.containsKey(BookmarkColumns.CREATED)) { row.created = values.getAsLong(BookmarkColumns.CREATED); } if (values.containsKey(BookmarkColumns.DATE)) { row.date = values.getAsLong(BookmarkColumns.DATE); } if (values.containsKey(BookmarkColumns.FAVICON)) { row.favicon = values.getAsByteArray(BookmarkColumns.FAVICON); // We need to know that the caller set the favicon column. if (row.favicon == null) { row.favicon = new byte[0]; } } if (values.containsKey(BookmarkColumns.TITLE)) { row.title = values.getAsString(BookmarkColumns.TITLE); } if (values.containsKey(BookmarkColumns.VISITS)) { row.visits = values.getAsInteger(BookmarkColumns.VISITS); } if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) { row.parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM); } return row; }
Example #13
Source File: BrowserProvider.java From coursera-android with MIT License | 4 votes |
@Override public int delete(Uri url, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int match = URI_MATCHER.match(url); if (match == -1 || match == URI_MATCH_SUGGEST) { throw new IllegalArgumentException("Unknown URL"); } // need to know whether it's the bookmarks table for a couple of reasons boolean isBookmarkTable = (match == URI_MATCH_BOOKMARKS_ID); String id = null; if (isBookmarkTable || match == URI_MATCH_SEARCHES_ID) { StringBuilder sb = new StringBuilder(); if (where != null && where.length() > 0) { sb.append("( "); sb.append(where); sb.append(" ) AND "); } id = url.getPathSegments().get(1); sb.append("_id = "); sb.append(id); where = sb.toString(); } ContentResolver cr = getContext().getContentResolver(); // we'lll need to back up the bookmark set if we are about to delete one if (isBookmarkTable) { Cursor cursor = cr.query(Browser.BOOKMARKS_URI, new String[] { BookmarkColumns.BOOKMARK }, "_id = " + id, null, null); if (cursor.moveToNext()) { if (cursor.getInt(0) != 0) { // yep, this record is a bookmark mBackupManager.dataChanged(); } } cursor.close(); } int count = db.delete(TABLE_NAMES[match % 10], where, whereArgs); cr.notifyChange(url, null); return count; }
Example #14
Source File: BrowserProvider.java From coursera-android with MIT License | 4 votes |
@Override public int update(Uri url, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int match = URI_MATCHER.match(url); if (match == -1 || match == URI_MATCH_SUGGEST) { throw new IllegalArgumentException("Unknown URL"); } if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_SEARCHES_ID) { StringBuilder sb = new StringBuilder(); if (where != null && where.length() > 0) { sb.append("( "); sb.append(where); sb.append(" ) AND "); } String id = url.getPathSegments().get(1); sb.append("_id = "); sb.append(id); where = sb.toString(); } ContentResolver cr = getContext().getContentResolver(); // Not all bookmark-table updates should be backed up. Look to see // whether we changed the title, url, or "is a bookmark" state, and // request a backup if so. if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_BOOKMARKS) { boolean changingBookmarks = false; // Alterations to the bookmark field inherently change the bookmark // set, so we don't need to query the record; we know a priori that // we will need to back up this change. if (values.containsKey(BookmarkColumns.BOOKMARK)) { changingBookmarks = true; } else if ((values.containsKey(BookmarkColumns.TITLE) || values.containsKey(BookmarkColumns.URL)) && values.containsKey(BookmarkColumns._ID)) { // If a title or URL has been changed, check to see if it is to // a bookmark. The ID should have been included in the update, // so use it. Cursor cursor = cr.query(Browser.BOOKMARKS_URI, new String[] { BookmarkColumns.BOOKMARK }, BookmarkColumns._ID + " = " + values.getAsString(BookmarkColumns._ID), null, null); if (cursor.moveToNext()) { changingBookmarks = (cursor.getInt(0) != 0); } cursor.close(); } // if this *is* a bookmark row we're altering, we need to back it up. if (changingBookmarks) { mBackupManager.dataChanged(); } } int ret = db.update(TABLE_NAMES[match % 10], values, where, whereArgs); cr.notifyChange(url, null); return ret; }
Example #15
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { if (!canHandleContentProviderApiCall()) return 0; // Check for invalid id values if provided. // If it represents a bookmark node then it's the root node and not mutable. // Otherwise it represents a SQLite row id, so 0 is invalid. long bookmarkId = INVALID_CONTENT_PROVIDER_ID; try { bookmarkId = ContentUris.parseId(uri); if (bookmarkId == INVALID_CONTENT_PROVIDER_ID) return 0; } catch (Exception e) { } int match = mUriMatcher.match(uri); int result; switch (match) { case URI_MATCH_BOOKMARKS_ID: String url = null; if (values.containsKey(Browser.BookmarkColumns.URL)) { url = values.getAsString(Browser.BookmarkColumns.URL); } String title = values.getAsString(Browser.BookmarkColumns.TITLE); long parentId = INVALID_BOOKMARK_ID; if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) { parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM); } result = nativeUpdateBookmark(mNativeChromeBrowserProvider, bookmarkId, url, title, parentId); updateLastModifiedBookmarkFolder(parentId); break; case URL_MATCH_API_BOOKMARK_ID: result = updateBookmarkFromAPI(values, buildWhereClause(bookmarkId, selection), selectionArgs); break; case URL_MATCH_API_BOOKMARK: result = updateBookmarkFromAPI(values, selection, selectionArgs); break; case URL_MATCH_API_SEARCHES_ID: result = updateSearchTermFromAPI(values, buildWhereClause(bookmarkId, selection), selectionArgs); break; case URL_MATCH_API_SEARCHES: result = updateSearchTermFromAPI(values, selection, selectionArgs); break; case URL_MATCH_API_HISTORY_CONTENT: result = updateBookmarkFromAPI(values, buildHistoryWhereClause(selection), selectionArgs); break; case URL_MATCH_API_HISTORY_CONTENT_ID: result = updateBookmarkFromAPI(values, buildHistoryWhereClause(bookmarkId, selection), selectionArgs); break; case URL_MATCH_API_BOOKMARK_CONTENT: result = updateBookmarkFromAPI(values, buildBookmarkWhereClause(selection), selectionArgs); break; case URL_MATCH_API_BOOKMARK_CONTENT_ID: result = updateBookmarkFromAPI(values, buildBookmarkWhereClause(bookmarkId, selection), selectionArgs); break; default: throw new IllegalArgumentException(TAG + ": update - unknown URL " + uri); } if (result != 0) { getContext().getContentResolver().notifyChange(uri, null); } return result; }
Example #16
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { if (!canHandleContentProviderApiCall()) return 0; // Check for invalid id values if provided. // If it represents a bookmark node then it's the root node and not mutable. // Otherwise it represents a SQLite row id, so 0 is invalid. long bookmarkId = INVALID_CONTENT_PROVIDER_ID; try { bookmarkId = ContentUris.parseId(uri); if (bookmarkId == INVALID_CONTENT_PROVIDER_ID) return 0; } catch (Exception e) { } int match = mUriMatcher.match(uri); int result; switch (match) { case URI_MATCH_BOOKMARKS_ID: String url = null; if (values.containsKey(Browser.BookmarkColumns.URL)) { url = values.getAsString(Browser.BookmarkColumns.URL); } String title = values.getAsString(Browser.BookmarkColumns.TITLE); long parentId = INVALID_BOOKMARK_ID; if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) { parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM); } result = nativeUpdateBookmark(mNativeChromeBrowserProvider, bookmarkId, url, title, parentId); updateLastModifiedBookmarkFolder(parentId); break; case URL_MATCH_API_BOOKMARK_ID: result = updateBookmarkFromAPI(values, buildWhereClause(bookmarkId, selection), selectionArgs); break; case URL_MATCH_API_BOOKMARK: result = updateBookmarkFromAPI(values, selection, selectionArgs); break; case URL_MATCH_API_SEARCHES_ID: result = updateSearchTermFromAPI(values, buildWhereClause(bookmarkId, selection), selectionArgs); break; case URL_MATCH_API_SEARCHES: result = updateSearchTermFromAPI(values, selection, selectionArgs); break; case URL_MATCH_API_HISTORY_CONTENT: result = updateBookmarkFromAPI(values, buildHistoryWhereClause(selection), selectionArgs); break; case URL_MATCH_API_HISTORY_CONTENT_ID: result = updateBookmarkFromAPI(values, buildHistoryWhereClause(bookmarkId, selection), selectionArgs); break; case URL_MATCH_API_BOOKMARK_CONTENT: result = updateBookmarkFromAPI(values, buildBookmarkWhereClause(selection), selectionArgs); break; case URL_MATCH_API_BOOKMARK_CONTENT_ID: result = updateBookmarkFromAPI(values, buildBookmarkWhereClause(bookmarkId, selection), selectionArgs); break; default: throw new IllegalArgumentException(TAG + ": update - unknown URL " + uri); } if (result != 0) { getContext().getContentResolver().notifyChange(uri, null); } return result; }