From aac7aa6fcfcb519755987ec126be066323f589c8 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Thu, 17 Sep 2009 16:57:40 +0100 Subject: In the case of a page load error, save a second screenshot in onProgressChanged(100) to ensure that we save the substituted error page rather than the previous page that loaded. Also save the thumbnail for the page if the user creates the bookmark through the add bookmark menu or clicking the add bookmark icon on the bookmarks page. Change-Id: Ib2b7692a45290f9ce372968e05cde8f6903e4572 --- src/com/android/browser/Bookmarks.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/com/android/browser/Bookmarks.java') diff --git a/src/com/android/browser/Bookmarks.java b/src/com/android/browser/Bookmarks.java index 40aaa63dc..c8aaee700 100644 --- a/src/com/android/browser/Bookmarks.java +++ b/src/com/android/browser/Bookmarks.java @@ -21,12 +21,14 @@ import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; +import android.graphics.Bitmap; import android.net.Uri; import android.provider.Browser; import android.util.Log; import android.webkit.WebIconDatabase; import android.widget.Toast; +import java.io.ByteArrayOutputStream; import java.util.Date; /** @@ -47,13 +49,14 @@ import java.util.Date; * @param cr The ContentResolver being used to add the bookmark to the db. * @param url URL of the website to be bookmarked. * @param name Provided name for the bookmark. + * @param thumbnail A thumbnail for the bookmark. * @param retainIcon Whether to retain the page's icon in the icon database. * This will usually be true except when bookmarks are * added by a settings restore agent. */ /* package */ static void addBookmark(Context context, ContentResolver cr, String url, String name, - boolean retainIcon) { + Bitmap thumbnail, boolean retainIcon) { // Want to append to the beginning of the list long creationTime = new Date().getTime(); // First we check to see if the user has already visited this @@ -95,6 +98,7 @@ import java.util.Date; map.put(Browser.BookmarkColumns.CREATED, creationTime); map.put(Browser.BookmarkColumns.TITLE, name); map.put(Browser.BookmarkColumns.BOOKMARK, 1); + map.put(Browser.BookmarkColumns.THUMBNAIL, bitmapToBytes(thumbnail)); cr.update(Browser.BOOKMARKS_URI, map, "_id = " + cursor.getInt(0), null); } else { @@ -125,6 +129,7 @@ import java.util.Date; map.put(Browser.BookmarkColumns.CREATED, creationTime); map.put(Browser.BookmarkColumns.BOOKMARK, 1); map.put(Browser.BookmarkColumns.DATE, 0); + map.put(Browser.BookmarkColumns.THUMBNAIL, bitmapToBytes(thumbnail)); int visits = 0; if (count > 0) { // The user has already bookmarked, and possibly @@ -199,4 +204,14 @@ import java.util.Date; } cursor.deactivate(); } -} \ No newline at end of file + + private static byte[] bitmapToBytes(Bitmap bm) { + if (bm == null) { + return null; + } + + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + bm.compress(Bitmap.CompressFormat.PNG, 100, os); + return os.toByteArray(); + } +} -- cgit v1.2.3