diff options
| author | Jeff Hamilton <jham@android.com> | 2010-09-07 12:36:30 -0700 |
|---|---|---|
| committer | Jeff Hamilton <jham@android.com> | 2010-09-15 22:15:59 -0500 |
| commit | 1a805652e389d9404ee0fda7c993a6202332e92b (patch) | |
| tree | 5c545f48bca2fbf18c08db79babb38e1fa914919 /src/com/android/browser/Bookmarks.java | |
| parent | 28beae80725eace55fd018dd7431d1fedeb10e25 (diff) | |
| download | packages_apps_Browser-1a805652e389d9404ee0fda7c993a6202332e92b.tar.gz packages_apps_Browser-1a805652e389d9404ee0fda7c993a6202332e92b.tar.bz2 packages_apps_Browser-1a805652e389d9404ee0fda7c993a6202332e92b.zip | |
A bunch of updates to BrowserProvider2.
The images are now shared between the history
and bookmarks tables so updates to one are
reflected in the other.
Added a parameter for specifying a limit when
calling query().
Added a combined view of history and bookmarks.
Added a way to get a distinct list of the
accounts providing bookmarks.
Added the ability to find the server unique
IDs for parent and insert_after when doing
a query for a row.
Change-Id: I9afa15bcf7ca68468793c49fbec701e516e4540e
Diffstat (limited to 'src/com/android/browser/Bookmarks.java')
| -rw-r--r-- | src/com/android/browser/Bookmarks.java | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/src/com/android/browser/Bookmarks.java b/src/com/android/browser/Bookmarks.java index 3ead2034e..532d7c0e9 100644 --- a/src/com/android/browser/Bookmarks.java +++ b/src/com/android/browser/Bookmarks.java @@ -25,6 +25,8 @@ import android.graphics.Bitmap; import android.net.Uri; import android.os.AsyncTask; import android.provider.BrowserContract; +import android.provider.BrowserContract.Combined; +import android.provider.BrowserContract.Images; import android.util.Log; import android.webkit.WebIconDatabase; import android.widget.Toast; @@ -153,13 +155,12 @@ import java.io.ByteArrayOutputStream; } static final String QUERY_BOOKMARKS_WHERE = - BrowserContract.Bookmarks.IS_FOLDER + " == 0 AND (" + - BrowserContract.Bookmarks.URL + " == ? OR " + - BrowserContract.Bookmarks.URL + " == ? OR " + - BrowserContract.Bookmarks.URL + " LIKE ? || '%' OR " + - BrowserContract.Bookmarks.URL + " LIKE ? || '%')"; + Combined.URL + " == ? OR " + + Combined.URL + " == ? OR " + + Combined.URL + " LIKE ? || '%' OR " + + Combined.URL + " LIKE ? || '%'"; - /* package */ static Cursor queryBookmarksForUrl(ContentResolver cr, + /* package */ static Cursor queryCombinedForUrl(ContentResolver cr, String originalUrl, String url) { if (cr == null || url == null) { return null; @@ -172,8 +173,8 @@ import java.io.ByteArrayOutputStream; // Look for both the original url and the actual url. This takes in to // account redirects. - String originalUrlNoQuery = Bookmarks.removeQuery(originalUrl); - String urlNoQuery = Bookmarks.removeQuery(url); + String originalUrlNoQuery = removeQuery(originalUrl); + String urlNoQuery = removeQuery(url); originalUrl = originalUrlNoQuery + '?'; url = urlNoQuery + '?'; @@ -182,11 +183,9 @@ import java.io.ByteArrayOutputStream; // Use url to match the base url with other queries (i.e. if the url is // http://www.google.com/m, search for // http://www.google.com/m?some_query) - final String[] selArgs = new String[] { - originalUrlNoQuery, urlNoQuery, originalUrl, url }; - final String[] projection = new String[] { BrowserContract.Bookmarks._ID }; - return cr.query(BrowserContract.Bookmarks.CONTENT_URI, projection, QUERY_BOOKMARKS_WHERE, - selArgs, null); + final String[] selArgs = new String[] { originalUrlNoQuery, urlNoQuery, originalUrl, url }; + final String[] projection = new String[] { Combined.URL }; + return cr.query(Combined.CONTENT_URI, projection, QUERY_BOOKMARKS_WHERE, selArgs, null); } // Strip the query from the given url. @@ -210,30 +209,28 @@ import java.io.ByteArrayOutputStream; * @param url The current url. * @param favicon The favicon bitmap to write to the db. */ - /* package */ static void updateBookmarkFavicon(final ContentResolver cr, + /* package */ static void updateFavicon(final ContentResolver cr, final String originalUrl, final String url, final Bitmap favicon) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... unused) { - final Cursor c = - Bookmarks.queryBookmarksForUrl(cr, originalUrl, url); - if (c == null) { - return null; + Cursor cursor = queryCombinedForUrl(cr, originalUrl, url); + try { + if (cursor.moveToFirst()) { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + favicon.compress(Bitmap.CompressFormat.PNG, 100, os); + + ContentValues values = new ContentValues(); + values.put(Images.FAVICON, os.toByteArray()); + values.put(Images.URL, cursor.getString(0)); + + do { + cr.update(Images.CONTENT_URI, values, null, null); + } while (cursor.moveToNext()); + } + } finally { + if (cursor != null) cursor.close(); } - if (c.moveToFirst()) { - ContentValues values = new ContentValues(); - final ByteArrayOutputStream os = - new ByteArrayOutputStream(); - favicon.compress(Bitmap.CompressFormat.PNG, 100, os); - values.put(BrowserContract.Bookmarks.FAVICON, - os.toByteArray()); - do { - cr.update(ContentUris.withAppendedId( - BrowserContract.Bookmarks.CONTENT_URI, c.getLong(0)), - values, null, null); - } while (c.moveToNext()); - } - c.close(); return null; } }.execute(); |
