OSDN Git Service

Deprecate fill_parent and introduce match_parent.
[android-x86/packages-apps-Browser.git] / src / com / android / browser / DownloadTouchIcon.java
index 6662e09..22ed73c 100644 (file)
@@ -22,11 +22,12 @@ import android.content.ContentValues;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.net.http.AndroidHttpClient;
 import android.os.AsyncTask;
 import android.provider.Browser;
 import android.webkit.WebView;
 
+import com.android.common.AndroidHttpClient;
+
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -36,14 +37,16 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> {
+class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
     private final ContentResolver mContentResolver;
     private final Cursor mCursor;
     private final String mOriginalUrl;
     private final String mUrl;
     private final String mUserAgent;
+    /* package */ Tab mTab;
 
-    public DownloadTouchIcon(ContentResolver cr, Cursor c, WebView view) {
+    public DownloadTouchIcon(Tab tab, ContentResolver cr, Cursor c, WebView view) {
+        mTab = tab;
         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) {
+        mTab = null;
         mContentResolver = cr;
         mCursor = c;
         mOriginalUrl = null;
@@ -61,7 +65,7 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> {
     }
 
     @Override
-    public Bitmap doInBackground(String... values) {
+    public Void doInBackground(String... values) {
         String url = values[0];
 
         AndroidHttpClient client = AndroidHttpClient.newInstance(
@@ -81,7 +85,7 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> {
                     if (content != null) {
                         Bitmap icon = BitmapFactory.decodeStream(
                                 content, null, null);
-                        return icon;
+                        storeIcon(icon);
                     }
                 }
             }
@@ -96,10 +100,23 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Bitmap> {
     }
 
     @Override
-    public void onPostExecute(Bitmap icon) {
-        if (icon == null || mCursor == null) {
+    protected void onCancelled() {
+        if (mCursor != null) {
+            mCursor.close();
+        }
+    }
+
+    private void storeIcon(Bitmap icon) {
+        // Do this first in case the download failed.
+        if (mTab != null) {
+            // Remove the touch icon loader from the BrowserActivity.
+            mTab.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();