mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
Bug 819973 - Scale favicons before storing them in the cache. r=mfinkle
--HG-- extra : rebase_source : 8d9417c071b3a49fed84e78930c868273d70363a
This commit is contained in:
parent
ceaabf359f
commit
101db76fad
@ -39,6 +39,9 @@ public class Favicons {
|
||||
|
||||
public static final long NOT_LOADING = 0;
|
||||
|
||||
private static int sFaviconSmallSize = -1;
|
||||
private static int sFaviconLargeSize = -1;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private Map<Long,LoadFaviconTask> mLoadTasks;
|
||||
@ -170,8 +173,29 @@ public class Favicons {
|
||||
return Favicons.FaviconsInstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public boolean isLargeFavicon(Bitmap image) {
|
||||
return image.getWidth() > sFaviconSmallSize || image.getHeight() > sFaviconSmallSize;
|
||||
}
|
||||
|
||||
public Bitmap scaleImage(Bitmap image) {
|
||||
// If the icon is larger than 16px, scale it to sFaviconLargeSize.
|
||||
// Otherwise, scale it to sFaviconSmallSize.
|
||||
if (isLargeFavicon(image)) {
|
||||
image = Bitmap.createScaledBitmap(image, sFaviconLargeSize, sFaviconLargeSize, false);
|
||||
} else {
|
||||
image = Bitmap.createScaledBitmap(image, sFaviconSmallSize, sFaviconSmallSize, false);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public void attachToContext(Context context) {
|
||||
mContext = context;
|
||||
if (sFaviconSmallSize < 0) {
|
||||
sFaviconSmallSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_small));
|
||||
}
|
||||
if (sFaviconLargeSize < 0) {
|
||||
sFaviconLargeSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_large));
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadFaviconTask extends AsyncTask<Void, Void, Bitmap> {
|
||||
@ -286,7 +310,7 @@ public class Favicons {
|
||||
if (storedFaviconUrl != null && storedFaviconUrl.equals(mFaviconUrl)) {
|
||||
image = loadFaviconFromDb();
|
||||
if (image != null)
|
||||
return image;
|
||||
return scaleImage(image);
|
||||
}
|
||||
|
||||
if (isCancelled())
|
||||
@ -296,6 +320,7 @@ public class Favicons {
|
||||
|
||||
if (image != null && image.getWidth() > 0 && image.getHeight() > 0) {
|
||||
saveFaviconToDb(image);
|
||||
image = scaleImage(image);
|
||||
} else {
|
||||
image = null;
|
||||
}
|
||||
|
@ -807,6 +807,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
|
||||
if (favicon == null)
|
||||
continue;
|
||||
|
||||
favicon = Favicons.getInstance().scaleImage(favicon);
|
||||
Favicons.getInstance().putFaviconInMemCache(url, favicon);
|
||||
} while (c.moveToNext());
|
||||
} finally {
|
||||
|
@ -40,17 +40,9 @@ abstract public class AwesomeBarTab {
|
||||
// FIXME: This value should probably come from a prefs key
|
||||
public static final int MAX_RESULTS = 100;
|
||||
protected Context mContext = null;
|
||||
private static int sFaviconSmallSize = -1;
|
||||
private static int sFaviconLargeSize = -1;
|
||||
|
||||
public AwesomeBarTab(Context context) {
|
||||
mContext = context;
|
||||
if (sFaviconSmallSize < 0) {
|
||||
sFaviconSmallSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_small));
|
||||
}
|
||||
if (sFaviconLargeSize < 0) {
|
||||
sFaviconLargeSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_large));
|
||||
}
|
||||
}
|
||||
|
||||
public void setListTouchListener(View.OnTouchListener listener) {
|
||||
@ -101,6 +93,7 @@ abstract public class AwesomeBarTab {
|
||||
faviconView.setImageDrawable(null);
|
||||
} else {
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
|
||||
bitmap = Favicons.getInstance().scaleImage(bitmap);
|
||||
updateFavicon(faviconView, bitmap);
|
||||
}
|
||||
}
|
||||
@ -108,14 +101,11 @@ abstract public class AwesomeBarTab {
|
||||
protected void updateFavicon(ImageView faviconView, Bitmap bitmap) {
|
||||
if (bitmap == null) {
|
||||
faviconView.setImageDrawable(null);
|
||||
} else if (bitmap.getWidth() > 16 || bitmap.getHeight() > 16) {
|
||||
// If the icon is larger than 16px, scale it to sFaviconLargeSize and hide the background
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconLargeSize, sFaviconLargeSize, false);
|
||||
} else if (Favicons.getInstance().isLargeFavicon(bitmap)) {
|
||||
// If the icon is large, hide the background
|
||||
faviconView.setImageBitmap(bitmap);
|
||||
faviconView.setBackgroundResource(0);
|
||||
} else {
|
||||
// If the icon is 16px or smaller, don't scale it up to full size
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconSmallSize, sFaviconSmallSize, false);
|
||||
faviconView.setImageBitmap(bitmap);
|
||||
faviconView.setBackgroundResource(R.drawable.awesomebar_row_favicon_bg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user