bug 705402 - Save thumbnails in the history DB r=dougt

This commit is contained in:
Brad Lassey 2011-11-29 22:54:07 -05:00
parent 0c921c8bd6
commit 7fb2044ef6

View File

@ -47,10 +47,12 @@ import android.graphics.Bitmap;
import android.provider.Browser; import android.provider.Browser;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.graphics.Bitmap;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -144,7 +146,9 @@ public class Tab {
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics); GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
sMinDim = Math.min(metrics.widthPixels, metrics.heightPixels); sMinDim = Math.min(metrics.widthPixels, metrics.heightPixels);
} }
mThumbnail = new BitmapDrawable(Bitmap.createBitmap(b, 0, 0, sMinDim, sMinDim)); Bitmap bitmap = Bitmap.createBitmap(b, 0, 0, sMinDim, sMinDim);
mThumbnail = new BitmapDrawable(bitmap);
saveThumbnailToDB(bitmap);
} }
}); });
} }
@ -409,6 +413,35 @@ public class Tab {
} }
} }
private void saveThumbnailToDB(Bitmap bitmap) {
ContentResolver resolver = Tabs.getInstance().getContentResolver();
Cursor cursor = resolver.query(Browser.BOOKMARKS_URI,
null,
Browser.BookmarkColumns.URL + " = ?",
new String[] { getURL() },
Browser.BookmarkColumns.URL);
ContentValues values = new ContentValues();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
values.put("thumbnail", bos.toByteArray());
if (cursor.getCount() == 1) {
//entry exists, update the bookmark flag
resolver.update(Browser.BOOKMARKS_URI,
values,
Browser.BookmarkColumns.URL + " = ?",
new String[] { getURL() });
} else {
//add a new entry
values.put(Browser.BookmarkColumns.URL, mUrl);
resolver.insert(Browser.BOOKMARKS_URI,
values);
}
cursor.close();
}
private class RemoveBookmarkTask extends GeckoAsyncTask<Void, Void, Void> { private class RemoveBookmarkTask extends GeckoAsyncTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... unused) { protected Void doInBackground(Void... unused) {