Bookmarks.java revision de353621650d17a412b6ffe2cbf0366db5f11c40
1e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins/* 2e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Copyright (C) 2009 The Android Open Source Project 3e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * 4e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Licensed under the Apache License, Version 2.0 (the "License"); 5e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * you may not use this file except in compliance with the License. 6e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * You may obtain a copy of the License at 7e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * 8e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * http://www.apache.org/licenses/LICENSE-2.0 9e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * 10e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Unless required by applicable law or agreed to in writing, software 11e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * distributed under the License is distributed on an "AS IS" BASIS, 12e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * See the License for the specific language governing permissions and 14e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * limitations under the License. 15e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins */ 16e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 17e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginspackage com.android.browser; 18e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 19e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.content.ContentResolver; 20e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.content.ContentUris; 21e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.content.ContentValues; 22e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.content.Context; 23e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.database.Cursor; 24aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdochimport android.graphics.Bitmap; 25e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.net.Uri; 26e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.provider.Browser; 27e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.util.Log; 28e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.webkit.WebIconDatabase; 29e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport android.widget.Toast; 30e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 31aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdochimport java.io.ByteArrayOutputStream; 32e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scrogginsimport java.util.Date; 33e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 34e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins/** 35e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * This class is purely to have a common place for adding/deleting bookmarks. 36e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins */ 37e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins/* package */ class Bookmarks { 38e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins private static final String WHERE_CLAUSE 39e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins = "url = ? OR url = ? OR url = ? OR url = ?"; 40e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins private static final String WHERE_CLAUSE_SECURE = "url = ? OR url = ?"; 41e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 42e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins private static String[] SELECTION_ARGS; 43e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 44de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch // We only want the user to be able to bookmark content that 45de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch // the browser can handle directly. 46de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch private static final String acceptableBookmarkSchemes[] = { 47de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "http:", 48de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "https:", 49de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "about:", 50de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "data:", 51de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "javascript:", 52de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "file:", 53de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch "content:" 54de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch }; 55de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch 56e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins /** 57e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Add a bookmark to the database. 58e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param context Context of the calling Activity. This is used to make 59e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Toast confirming that the bookmark has been added. If the 60e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * caller provides null, the Toast will not be shown. 61e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param cr The ContentResolver being used to add the bookmark to the db. 62e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param url URL of the website to be bookmarked. 63e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param name Provided name for the bookmark. 64aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch * @param thumbnail A thumbnail for the bookmark. 659c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate * @param retainIcon Whether to retain the page's icon in the icon database. 669c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate * This will usually be <code>true</code> except when bookmarks are 679c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate * added by a settings restore agent. 68e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins */ 69e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins /* package */ static void addBookmark(Context context, 709c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate ContentResolver cr, String url, String name, 71aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch Bitmap thumbnail, boolean retainIcon) { 72e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Want to append to the beginning of the list 73e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins long creationTime = new Date().getTime(); 74e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // First we check to see if the user has already visited this 75e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // site. They may have bookmarked it in a different way from 76e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // how it's stored in the database, so allow different combos 77e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // to map to the same url. 78e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins boolean secure = false; 79e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins String compareString = url; 80e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (compareString.startsWith("http://")) { 81e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins compareString = compareString.substring(7); 82e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } else if (compareString.startsWith("https://")) { 83e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins compareString = compareString.substring(8); 84e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins secure = true; 85e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 86e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (compareString.startsWith("www.")) { 87e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins compareString = compareString.substring(4); 88e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 89e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (secure) { 90e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS = new String[2]; 91e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS[0] = "https://" + compareString; 92e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS[1] = "https://www." + compareString; 93e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } else { 94e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS = new String[4]; 95e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS[0] = compareString; 96e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS[1] = "www." + compareString; 97e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS[2] = "http://" + compareString; 98e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS[3] = "http://" + SELECTION_ARGS[1]; 99e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 100e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Cursor cursor = cr.query(Browser.BOOKMARKS_URI, 101e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Browser.HISTORY_PROJECTION, 102e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins secure ? WHERE_CLAUSE_SECURE : WHERE_CLAUSE, 103e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins SELECTION_ARGS, 104e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins null); 105e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins ContentValues map = new ContentValues(); 106e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (cursor.moveToFirst() && cursor.getInt( 107e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Browser.HISTORY_PROJECTION_BOOKMARK_INDEX) == 0) { 108e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // This means we have been to this site but not bookmarked 109e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // it, so convert the history item to a bookmark 110e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.CREATED, creationTime); 111e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.TITLE, name); 112e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.BOOKMARK, 1); 113aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch map.put(Browser.BookmarkColumns.THUMBNAIL, bitmapToBytes(thumbnail)); 114e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cr.update(Browser.BOOKMARKS_URI, map, 115e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins "_id = " + cursor.getInt(0), null); 116e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } else { 117e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins int count = cursor.getCount(); 118e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins boolean matchedTitle = false; 119e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins for (int i = 0; i < count; i++) { 120e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // One or more bookmarks already exist for this site. 121e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Check the names of each 122e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cursor.moveToPosition(i); 123e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (cursor.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX) 124e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins .equals(name)) { 125e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // The old bookmark has the same name. 126e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Update its creation time. 127e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.CREATED, 128e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins creationTime); 129e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cr.update(Browser.BOOKMARKS_URI, map, 130e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins "_id = " + cursor.getInt(0), null); 131e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins matchedTitle = true; 132e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins break; 133e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 134e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 135e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (!matchedTitle) { 136e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Adding a bookmark for a site the user has visited, 137e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // or a new bookmark (with a different name) for a site 138e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // the user has visited 139e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.TITLE, name); 140e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.URL, url); 141e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.CREATED, creationTime); 142e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.BOOKMARK, 1); 143e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.DATE, 0); 144aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch map.put(Browser.BookmarkColumns.THUMBNAIL, bitmapToBytes(thumbnail)); 145e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins int visits = 0; 146e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (count > 0) { 147e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // The user has already bookmarked, and possibly 148e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // visited this site. However, they are creating 149e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // a new bookmark with the same url but a different 150e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // name. The new bookmark should have the same 151e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // number of visits as the already created bookmark. 152e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins visits = cursor.getInt( 153e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Browser.HISTORY_PROJECTION_VISITS_INDEX); 154e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 155e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Bookmark starts with 3 extra visits so that it will 156e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // bubble up in the most visited and goto search box 157e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins map.put(Browser.BookmarkColumns.VISITS, visits + 3); 158e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cr.insert(Browser.BOOKMARKS_URI, map); 159e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 160e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 1619c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate if (retainIcon) { 1629c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate WebIconDatabase.getInstance().retainIconForPageUrl(url); 1639c0dd8caacff99ba76bbb9dc2cab156cded505a8Christopher Tate } 164e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cursor.deactivate(); 165e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (context != null) { 166e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Toast.makeText(context, R.string.added_to_bookmarks, 167e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Toast.LENGTH_LONG).show(); 168e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 169e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 170e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins 171e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins /** 172e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Remove a bookmark from the database. If the url is a visited site, it 173e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * will remain in the database, but only as a history item, and not as a 174e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * bookmarked site. 175e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param context Context of the calling Activity. This is used to make 176e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * Toast confirming that the bookmark has been removed. If the 177e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * caller provides null, the Toast will not be shown. 178e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param cr The ContentResolver being used to remove the bookmark. 179e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins * @param url URL of the website to be removed. 180e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins */ 181e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins /* package */ static void removeFromBookmarks(Context context, 182c95261955cf08f30b484b6a229c4bcff42c645ceAndrei Popescu ContentResolver cr, String url, String title) { 183e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Cursor cursor = cr.query( 184e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Browser.BOOKMARKS_URI, 185e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Browser.HISTORY_PROJECTION, 186c95261955cf08f30b484b6a229c4bcff42c645ceAndrei Popescu "url = ? AND title = ?", 187c95261955cf08f30b484b6a229c4bcff42c645ceAndrei Popescu new String[] { url, title }, 188e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins null); 189e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins boolean first = cursor.moveToFirst(); 190e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Should be in the database no matter what 191e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (!first) { 192c95261955cf08f30b484b6a229c4bcff42c645ceAndrei Popescu throw new AssertionError("URL is not in the database! " + url + " " + title); 193e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 194e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // Remove from bookmarks 195e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins WebIconDatabase.getInstance().releaseIconForPageUrl(url); 196e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Uri uri = ContentUris.withAppendedId(Browser.BOOKMARKS_URI, 197e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cursor.getInt(Browser.HISTORY_PROJECTION_ID_INDEX)); 198e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins int numVisits = cursor.getInt( 199e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Browser.HISTORY_PROJECTION_VISITS_INDEX); 200e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (0 == numVisits) { 201e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cr.delete(uri, null, null); 202e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } else { 203e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // It is no longer a bookmark, but it is still a visited 204e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins // site. 205e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins ContentValues values = new ContentValues(); 206e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins values.put(Browser.BookmarkColumns.BOOKMARK, 0); 207e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins try { 208e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cr.update(uri, values, null, null); 209e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } catch (IllegalStateException e) { 210e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Log.e("removeFromBookmarks", "no database!"); 211e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 212e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 213e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins if (context != null) { 214e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Toast.makeText(context, R.string.removed_from_bookmarks, 215e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Toast.LENGTH_LONG).show(); 216e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 217e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins cursor.deactivate(); 218e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins } 219aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch 220aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch private static byte[] bitmapToBytes(Bitmap bm) { 221aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch if (bm == null) { 222aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch return null; 223aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch } 224aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch 225aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch final ByteArrayOutputStream os = new ByteArrayOutputStream(); 226aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch bm.compress(Bitmap.CompressFormat.PNG, 100, os); 227aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch return os.toByteArray(); 228aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch } 229de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch 230de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch /* package */ static boolean urlHasAcceptableScheme(String url) { 231de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch if (url == null) { 232de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch return false; 233de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch } 234de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch 235de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch for (int i = 0; i < acceptableBookmarkSchemes.length; i++) { 236de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch if (url.startsWith(acceptableBookmarkSchemes[i])) { 237de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch return true; 238de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch } 239de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch } 240de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch return false; 241de353621650d17a412b6ffe2cbf0366db5f11c40Ben Murdoch } 242aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch} 243