Solving bug where labels were uneven

- Ensuring all icons, even those that are pulled from our database cache, are always the correct size
- Solves bug where loading icon for shortcuts with missing activities on a GB->ICS upgrade caused uneven labels (Bug 5111191)

Change-Id: I4b8a97c3b0fa02fd189f82d0c01444f47fee2205
This commit is contained in:
Michael Jurka committed 2011-08-05 15:43:18 -07:00
1 parent 02765c9426
commit 931dc9779d
5 files changed
+44 -19

No files matched your search

+27 -3
View File
@@ -76,8 +76,32 @@ final class Utilities {
}
/**
* Returns a bitmap suitable for the all apps view. The bitmap will be a power
* of two sized ARGB_8888 bitmap that can be used as a gl texture.
* Returns a bitmap suitable for the all apps view. Used to convert pre-ICS
* icon bitmaps that are stored in the database (which were 74x74 pixels at hdpi size)
* to the proper size (48dp)
*/
static Bitmap createIconBitmap(Bitmap icon, Context context) {
int textureWidth = sIconTextureWidth;
int textureHeight = sIconTextureHeight;
int sourceWidth = icon.getWidth();
int sourceHeight = icon.getHeight();
if (sourceWidth > textureWidth && sourceHeight > textureHeight) {
// Icon is bigger than it should be; clip it (solves the GB->ICS migration case)
return Bitmap.createBitmap(icon,
(sourceWidth - textureWidth) / 2,
(sourceHeight - textureHeight) / 2,
textureWidth, textureHeight);
} else if (sourceWidth == textureWidth && sourceHeight == textureHeight) {
// Icon is the right size, no need to change it
return icon;
} else {
// Icon is too small, render to a larger bitmap
return createIconBitmap(new BitmapDrawable(icon), context);
}
}
/**
* Returns a bitmap suitable for the all apps view.
*/
static Bitmap createIconBitmap(Drawable icon, Context context) {
synchronized (sCanvas) { // we share the statics :-(
@@ -103,7 +127,7 @@ final class Utilities {
int sourceWidth = icon.getIntrinsicWidth();
int sourceHeight = icon.getIntrinsicHeight();
if (sourceWidth > 0 && sourceWidth > 0) {
if (sourceWidth > 0 && sourceHeight > 0) {
// There are intrinsic sizes.
if (width < sourceWidth || height < sourceHeight) {
// It's too big, scale it down.