diff options
Diffstat (limited to 'src/com/android')
| -rw-r--r-- | src/com/android/browser/AddBookmarkPage.java | 3 | ||||
| -rw-r--r-- | src/com/android/browser/BrowserActivity.java | 27 | ||||
| -rw-r--r-- | src/com/android/browser/BrowserBookmarksPage.java | 6 | ||||
| -rw-r--r-- | src/com/android/browser/DownloadTouchIcon.java | 22 |
4 files changed, 50 insertions, 8 deletions
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index a54a59a1d..2a92dce0c 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -159,8 +159,7 @@ public class AddBookmarkPage extends Activity { final Cursor c = BrowserBookmarksAdapter.queryBookmarksForUrl( cr, null, url, true); - new DownloadTouchIcon(cr, c, url) - .execute(mTouchIconUrl); + new DownloadTouchIcon(cr, c, url).execute(mTouchIconUrl); } setResult(RESULT_OK); } diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index b93c55451..448d33221 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -2381,6 +2381,14 @@ public class BrowserActivity extends Activity resetLockIcon(url); setUrlTitle(url, null); + // If we start a touch icon load and then load a new page, we don't + // want to cancel the current touch icon loader. But, we do want to + // create a new one when the touch icon url is known. + if (mTouchIconLoader != null) { + mTouchIconLoader.mActivity = null; + mTouchIconLoader = null; + } + ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(false); if (errorConsole != null) { errorConsole.clearErrorMessages(); @@ -3148,14 +3156,26 @@ public class BrowserActivity extends Activity } @Override - public void onReceivedTouchIconUrl(WebView view, String url) { + public void onReceivedTouchIconUrl(WebView view, String url, + boolean precomposed) { final ContentResolver cr = getContentResolver(); final Cursor c = BrowserBookmarksAdapter.queryBookmarksForUrl(cr, view.getOriginalUrl(), view.getUrl(), true); if (c != null) { if (c.getCount() > 0) { - new DownloadTouchIcon(cr, c, view).execute(url); + // Let precomposed icons take precedence over non-composed + // icons. + if (precomposed && mTouchIconLoader != null) { + mTouchIconLoader.cancel(false); + mTouchIconLoader = null; + } + // Have only one async task at a time. + if (mTouchIconLoader == null) { + mTouchIconLoader = new DownloadTouchIcon( + BrowserActivity.this, cr, c, view); + mTouchIconLoader.execute(url); + } } else { c.close(); } @@ -4369,6 +4389,9 @@ public class BrowserActivity extends Activity private BroadcastReceiver mPackageInstallationReceiver; + // AsyncTask for downloading touch icons + /* package */ DownloadTouchIcon mTouchIconLoader; + // activity requestCode final static int COMBO_PAGE = 1; final static int DOWNLOAD_PAGE = 2; diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java index f8c80d847..23fcc5add 100644 --- a/src/com/android/browser/BrowserBookmarksPage.java +++ b/src/com/android/browser/BrowserBookmarksPage.java @@ -401,8 +401,10 @@ public class BrowserBookmarksPage extends Activity implements // an inverse fill so we can punch a hole using the round rect. Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); - path.addRoundRect(new RectF(0, 0, touchIcon.getWidth(), - touchIcon.getHeight()), 8f, 8f, Path.Direction.CW); + RectF rect = new RectF(0, 0, touchIcon.getWidth(), + touchIcon.getHeight()); + rect.inset(1, 1); + path.addRoundRect(rect, 8f, 8f, Path.Direction.CW); // Construct a paint that clears the outside of the rectangle and // draw. diff --git a/src/com/android/browser/DownloadTouchIcon.java b/src/com/android/browser/DownloadTouchIcon.java index 6662e0905..07d2d3ae6 100644 --- a/src/com/android/browser/DownloadTouchIcon.java +++ b/src/com/android/browser/DownloadTouchIcon.java @@ -42,8 +42,11 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> { private final String mOriginalUrl; private final String mUrl; private final String mUserAgent; + /* package */ BrowserActivity mActivity; - public DownloadTouchIcon(ContentResolver cr, Cursor c, WebView view) { + public DownloadTouchIcon(BrowserActivity activity, ContentResolver cr, + Cursor c, WebView view) { + mActivity = activity; mContentResolver = cr; mCursor = c; // Store these in case they change. @@ -53,6 +56,7 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> { } public DownloadTouchIcon(ContentResolver cr, Cursor c, String url) { + mActivity = null; mContentResolver = cr; mCursor = c; mOriginalUrl = null; @@ -96,10 +100,24 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> { } @Override + protected void onCancelled() { + if (mCursor != null) { + mCursor.close(); + } + } + + @Override public void onPostExecute(Bitmap icon) { - if (icon == null || mCursor == null) { + // Do this first in case the download failed. + if (mActivity != null) { + // Remove the touch icon loader from the BrowserActivity. + mActivity.mTouchIconLoader = null; + } + + if (icon == null || mCursor == null || isCancelled()) { return; } + final ByteArrayOutputStream os = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.PNG, 100, os); ContentValues values = new ContentValues(); |
