summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Scott <phanna@android.com>2010-04-06 16:36:12 -0400
committerPatrick Scott <phanna@android.com>2010-04-06 16:36:12 -0400
commit63a45b8ff2254ca9309abd1c1880f6af5a6712ce (patch)
tree2230f057557725a04ca243621b78542d74684b89
parent65190702c53f2d3ceb8e3c88d707bd6ff874034c (diff)
downloadpackages_apps_Browser-63a45b8ff2254ca9309abd1c1880f6af5a6712ce.zip
packages_apps_Browser-63a45b8ff2254ca9309abd1c1880f6af5a6712ce.tar.gz
packages_apps_Browser-63a45b8ff2254ca9309abd1c1880f6af5a6712ce.tar.bz2
Update bookmark favicons in the background.
Bug: 2573890 Change-Id: I7c9ebfd1b561c40d806988e65f7e89d5cd283f89
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index 4442c7f..03e3e5d 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -25,6 +25,7 @@ import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Browser;
@@ -250,26 +251,32 @@ class BrowserBookmarksAdapter extends BaseAdapter {
* @param url The current url.
* @param favicon The favicon bitmap to write to the db.
*/
- /* package */ static void updateBookmarkFavicon(ContentResolver cr,
- String originalUrl, String url, Bitmap favicon) {
- final Cursor c = queryBookmarksForUrl(cr, originalUrl, url, true);
- if (c == null) {
- return;
- }
- boolean succeed = c.moveToFirst();
- ContentValues values = null;
- while (succeed) {
- if (values == null) {
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
- favicon.compress(Bitmap.CompressFormat.PNG, 100, os);
- values = new ContentValues();
- values.put(Browser.BookmarkColumns.FAVICON, os.toByteArray());
+ /* package */ static void updateBookmarkFavicon(final ContentResolver cr,
+ final String originalUrl, final String url, final Bitmap favicon) {
+ new AsyncTask<Void, Void, Void>() {
+ protected Void doInBackground(Void... unused) {
+ final Cursor c =
+ queryBookmarksForUrl(cr, originalUrl, url, true);
+ if (c == null) {
+ return null;
+ }
+ if (c.moveToFirst()) {
+ ContentValues values = new ContentValues();
+ final ByteArrayOutputStream os =
+ new ByteArrayOutputStream();
+ favicon.compress(Bitmap.CompressFormat.PNG, 100, os);
+ values.put(Browser.BookmarkColumns.FAVICON,
+ os.toByteArray());
+ do {
+ cr.update(ContentUris.withAppendedId(
+ Browser.BOOKMARKS_URI, c.getInt(0)),
+ values, null, null);
+ } while (c.moveToNext());
+ }
+ c.close();
+ return null;
}
- cr.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, c
- .getInt(0)), values, null, null);
- succeed = c.moveToNext();
- }
- c.close();
+ }.execute();
}
/* package */ static Cursor queryBookmarksForUrl(ContentResolver cr,