summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/Utilities.java
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-09-28 18:48:49 -0700
committerRomain Guy <romainguy@android.com>2009-09-28 18:48:49 -0700
commit89911d2450f5db92d79e3bcefa9d324e9e8c4900 (patch)
treeabd626e4cf19d8d6a01e9f9b1b42b721ab3f3de6 /src/com/android/launcher2/Utilities.java
parent360d0353fdc8ecfcb7131ca0976c9a126b8a0d18 (diff)
downloadandroid_packages_apps_Trebuchet-89911d2450f5db92d79e3bcefa9d324e9e8c4900.tar.gz
android_packages_apps_Trebuchet-89911d2450f5db92d79e3bcefa9d324e9e8c4900.tar.bz2
android_packages_apps_Trebuchet-89911d2450f5db92d79e3bcefa9d324e9e8c4900.zip
Fix icons resizing.
Change-Id: I006191e27af19a95992050eb352a0489abbe6c58
Diffstat (limited to 'src/com/android/launcher2/Utilities.java')
-rw-r--r--src/com/android/launcher2/Utilities.java70
1 files changed, 39 insertions, 31 deletions
diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java
index dbb5ac663..a7eabe39a 100644
--- a/src/com/android/launcher2/Utilities.java
+++ b/src/com/android/launcher2/Utilities.java
@@ -56,7 +56,7 @@ final class Utilities {
private static final Paint sEmptyPaint = new Paint();
private static final Rect sBounds = new Rect();
private static final Rect sOldBounds = new Rect();
- private static Canvas sCanvas = new Canvas();
+ private static final Canvas sCanvas = new Canvas();
static {
sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
@@ -104,7 +104,6 @@ final class Utilities {
int width = sIconWidth;
int height = sIconHeight;
- float scale = 1.0f;
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
@@ -120,8 +119,8 @@ final class Utilities {
int iconWidth = icon.getIntrinsicWidth();
int iconHeight = icon.getIntrinsicHeight();
- if (iconWidth > 0 && iconWidth > 0) {
- if (width < iconWidth || height < iconHeight || scale != 1.0f) {
+ if (iconWidth > 0 && iconHeight > 0) {
+ if (width < iconWidth || height < iconHeight) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {
@@ -182,7 +181,6 @@ final class Utilities {
int width = sIconWidth;
int height = sIconHeight;
- float scale = 1.0f;
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
@@ -200,7 +198,7 @@ final class Utilities {
if (sourceWidth > 0 && sourceWidth > 0) {
// There are intrinsic sizes.
- if (width < sourceWidth || height < sourceHeight || scale != 1.0f) {
+ if (width < sourceWidth || height < sourceHeight) {
// It's too big, scale it down.
final float ratio = (float) sourceWidth / sourceHeight;
if (sourceWidth > sourceHeight) {
@@ -211,7 +209,7 @@ final class Utilities {
} else if (sourceWidth < width && sourceHeight < height) {
// It's small, use the size they gave us.
width = sourceWidth;
- height = sourceWidth;
+ height = sourceHeight;
}
}
@@ -295,27 +293,40 @@ final class Utilities {
final int bitmapWidth = bitmap.getWidth();
final int bitmapHeight = bitmap.getHeight();
- if (width > 0 && height > 0 && (width < bitmapWidth || height < bitmapHeight)) {
- final float ratio = (float) bitmapWidth / bitmapHeight;
-
- if (bitmapWidth > bitmapHeight) {
- height = (int) (width / ratio);
- } else if (bitmapHeight > bitmapWidth) {
- width = (int) (height * ratio);
+ if (width > 0 && height > 0) {
+ if (width < bitmapWidth || height < bitmapHeight) {
+ final float ratio = (float) bitmapWidth / bitmapHeight;
+
+ if (bitmapWidth > bitmapHeight) {
+ height = (int) (width / ratio);
+ } else if (bitmapHeight > bitmapWidth) {
+ width = (int) (height * ratio);
+ }
+
+ final Bitmap.Config c = (width == sIconWidth && height == sIconHeight) ?
+ bitmap.getConfig() : Bitmap.Config.ARGB_8888;
+ final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
+ final Canvas canvas = sCanvas;
+ final Paint paint = sPaint;
+ canvas.setBitmap(thumb);
+ paint.setDither(false);
+ paint.setFilterBitmap(true);
+ sBounds.set((sIconWidth - width) / 2, (sIconHeight - height) / 2, width, height);
+ sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
+ canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
+ return thumb;
+ } else if (bitmapWidth < width || bitmapHeight < height) {
+ final Bitmap.Config c = Bitmap.Config.ARGB_8888;
+ final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
+ final Canvas canvas = sCanvas;
+ final Paint paint = sPaint;
+ canvas.setBitmap(thumb);
+ paint.setDither(false);
+ paint.setFilterBitmap(true);
+ canvas.drawBitmap(bitmap, (sIconWidth - bitmapWidth) / 2,
+ (sIconHeight - bitmapHeight) / 2, paint);
+ return thumb;
}
-
- final Bitmap.Config c = (width == sIconWidth && height == sIconHeight) ?
- bitmap.getConfig() : Bitmap.Config.ARGB_8888;
- final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
- final Canvas canvas = sCanvas;
- final Paint paint = sPaint;
- canvas.setBitmap(thumb);
- paint.setDither(false);
- paint.setFilterBitmap(true);
- sBounds.set((sIconWidth - width) / 2, (sIconHeight - height) / 2, width, height);
- sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
- canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
- return thumb;
}
return bitmap;
@@ -337,10 +348,8 @@ final class Utilities {
static class BubbleText {
private static final int MAX_LINES = 2;
private TextPaint mTextPaint;
- private Paint mRectPaint;
private float mBubblePadding;
- private float mCornerRadius;
private RectF mBubbleRect = new RectF();
private float mTextWidth;
@@ -367,10 +376,9 @@ final class Utilities {
bubbleRect.top = 0;
bubbleRect.right = (int)(bubbleWidth+0.5f);
- mCornerRadius = BubbleTextView.CORNER_RADIUS * scale;
mTextWidth = bubbleWidth - mBubblePadding - mBubblePadding;
- Paint rectPaint = mRectPaint = new Paint();
+ Paint rectPaint = new Paint();
rectPaint.setColor(0xff000000);
rectPaint.setAntiAlias(true);