Bug 867627 - Speed up dominant color favicon backgrounds. r=bnicholson

This commit is contained in:
Margaret Leibovic
2013-05-06 16:13:59 -04:00
parent 54e43d94e5
commit c4c6ceffd9
7 changed files with 47 additions and 37 deletions

View File

@@ -5,7 +5,6 @@
package org.mozilla.gecko.widget;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.Favicons;
import org.mozilla.gecko.R;
@@ -29,8 +28,11 @@ public class FaviconView extends ImageView {
setScaleType(ImageView.ScaleType.CENTER);
}
@Override
public void setImageBitmap(final Bitmap bitmap) {
/*
* @param bitmap favicon image
* @param key string used as a key to cache the dominant color of this image
*/
public void updateImage(Bitmap bitmap, String key) {
if (bitmap == null) {
// Call setImageDrawable directly to avoid creating a useless BitmapDrawable.
setImageDrawable(null);
@@ -43,20 +45,11 @@ public class FaviconView extends ImageView {
} else {
super.setImageBitmap(bitmap);
// Otherwise show a dominant color background.
new AsyncTask<Void, Void, Integer>(){
@Override
public Integer doInBackground(Void... params) {
return BitmapUtils.getDominantColor(bitmap);
}
@Override
public void onPostExecute(Integer color) {
// Set an alpha value on the dominant color.
color = Color.argb(70, Color.red(color), Color.green(color), Color.blue(color));
Drawable drawable = getResources().getDrawable(R.drawable.favicon_bg);
drawable.setColorFilter(color, Mode.SRC_ATOP);
setBackgroundDrawable(drawable);
}
}.execute();
int color = Favicons.getInstance().getFaviconColor(bitmap, key);
color = Color.argb(70, Color.red(color), Color.green(color), Color.blue(color));
Drawable drawable = getResources().getDrawable(R.drawable.favicon_bg);
drawable.setColorFilter(color, Mode.SRC_ATOP);
setBackgroundDrawable(drawable);
}
}
}