diff options
| author | Patrick Scott <phanna@android.com> | 2009-08-04 13:22:29 -0400 |
|---|---|---|
| committer | Patrick Scott <phanna@android.com> | 2009-08-05 10:52:30 -0400 |
| commit | 3918d4443ff38ef1870e02aa51a8b29f8352bb1a (patch) | |
| tree | 72751daaca11780acba4f57c73619f4f37f6964c /src/com/android/browser/BrowserBookmarksAdapter.java | |
| parent | 13feaed9ab1b9a3b8cc5ac1b33e36005802b9fc3 (diff) | |
| download | packages_apps_Browser-3918d4443ff38ef1870e02aa51a8b29f8352bb1a.tar.gz packages_apps_Browser-3918d4443ff38ef1870e02aa51a8b29f8352bb1a.tar.bz2 packages_apps_Browser-3918d4443ff38ef1870e02aa51a8b29f8352bb1a.zip | |
Implement onReceivedTouchIconUrl.
Add DownloadTouchIcon, an AsyncTask that downloads the apple-touch-icon for urls
that are marked as bookmarks. The touch icon is stored in the bookmark database
similar to favicons and thumbnails. If a shortcut is created for a bookmark
containing a touch icon, the touch icon is used (with rounded corners).
Refactor the bookmarks query to be a static function. The function uses the
original url and new url to look for matching bookmarks. This takes care of
redirects as well as bookmarks containing queries.
Diffstat (limited to 'src/com/android/browser/BrowserBookmarksAdapter.java')
| -rw-r--r-- | src/com/android/browser/BrowserBookmarksAdapter.java | 99 |
1 files changed, 74 insertions, 25 deletions
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java index 764daea5d..c3ccdfd3f 100644 --- a/src/com/android/browser/BrowserBookmarksAdapter.java +++ b/src/com/android/browser/BrowserBookmarksAdapter.java @@ -35,6 +35,7 @@ import android.view.View; import android.view.ViewGroup; import android.webkit.WebIconDatabase; import android.webkit.WebIconDatabase.IconListener; +import android.webkit.WebView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; @@ -59,7 +60,7 @@ class BrowserBookmarksAdapter extends BaseAdapter { // Implementation of WebIconDatabase.IconListener private class IconReceiver implements IconListener { public void onReceivedIcon(String url, Bitmap icon) { - updateBookmarkFavicon(mContentResolver, url, icon); + updateBookmarkFavicon(mContentResolver, null, url, icon); } } @@ -247,35 +248,26 @@ class BrowserBookmarksAdapter extends BaseAdapter { } /** - * Update the bookmark's favicon. + * Update the bookmark's favicon. This is a convenience method for updating + * a bookmark favicon for the originalUrl and url of the passed in WebView. * @param cr The ContentResolver to use. - * @param url The url of the bookmark to update. + * @param WebView The WebView containing the url to update. * @param favicon The favicon bitmap to write to the db. */ /* package */ static void updateBookmarkFavicon(ContentResolver cr, - String url, Bitmap favicon) { - if (url == null || favicon == null) { - return; + WebView view, Bitmap favicon) { + if (view != null) { + updateBookmarkFavicon(cr, view.getOriginalUrl(), view.getUrl(), + favicon); } - // Strip the query. - int query = url.indexOf('?'); - String noQuery = url; - if (query != -1) { - noQuery = url.substring(0, query); + } + + private static void updateBookmarkFavicon(ContentResolver cr, + String originalUrl, String url, Bitmap favicon) { + final Cursor c = queryBookmarksForUrl(cr, originalUrl, url); + if (c == null) { + return; } - url = noQuery + '?'; - // Use noQuery to search for the base url (i.e. if the url is - // http://www.yahoo.com/?rs=1, search for http://www.yahoo.com) - // 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[] { noQuery, url }; - final String where = "(" + Browser.BookmarkColumns.URL + " == ? OR " - + Browser.BookmarkColumns.URL + " GLOB ? || '*') AND " - + Browser.BookmarkColumns.BOOKMARK + " == 1"; - final String[] projection = new String[] { Browser.BookmarkColumns._ID }; - final Cursor c = cr.query(Browser.BOOKMARKS_URI, projection, where, - selArgs, null); boolean succeed = c.moveToFirst(); ContentValues values = null; while (succeed) { @@ -292,6 +284,55 @@ class BrowserBookmarksAdapter extends BaseAdapter { c.close(); } + /* package */ static Cursor queryBookmarksForUrl(ContentResolver cr, + String originalUrl, String url) { + if (cr == null || url == null) { + return null; + } + + // If originalUrl is null, just set it to url. + if (originalUrl == null) { + originalUrl = url; + } + + // Look for both the original url and the actual url. This takes in to + // account redirects. + String originalUrlNoQuery = removeQuery(originalUrl); + String urlNoQuery = removeQuery(url); + originalUrl = originalUrlNoQuery + '?'; + url = urlNoQuery + '?'; + + // Use NoQuery to search for the base url (i.e. if the url is + // http://www.yahoo.com/?rs=1, search for http://www.yahoo.com) + // 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 where = "(" + BookmarkColumns.URL + " == ? OR " + + BookmarkColumns.URL + " == ? OR " + + BookmarkColumns.URL + " GLOB ? || '*' OR " + + BookmarkColumns.URL + " GLOB ? || '*') AND " + + BookmarkColumns.BOOKMARK + " == 1"; + final String[] projection = + new String[] { Browser.BookmarkColumns._ID }; + return cr.query(Browser.BOOKMARKS_URI, projection, where, selArgs, + null); + } + + // Strip the query from the given url. + private static String removeQuery(String url) { + if (url == null) { + return null; + } + int query = url.indexOf('?'); + String noQuery = url; + if (query != -1) { + noQuery = url.substring(0, query); + } + return noQuery; + } + /** * How many items should be displayed in the list. * @return Count of items. @@ -430,11 +471,19 @@ class BrowserBookmarksAdapter extends BaseAdapter { * Return the favicon for this item in the list. */ public Bitmap getFavicon(int position) { + return getBitmap(Browser.HISTORY_PROJECTION_FAVICON_INDEX, position); + } + + public Bitmap getTouchIcon(int position) { + return getBitmap(Browser.HISTORY_PROJECTION_TOUCH_ICON_INDEX, position); + } + + private Bitmap getBitmap(int cursorIndex, int position) { if (position < mExtraOffset || position > mCount) { return null; } mCursor.moveToPosition(position - mExtraOffset); - byte[] data = mCursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX); + byte[] data = mCursor.getBlob(cursorIndex); if (data == null) { return null; } |
