diff options
| -rw-r--r-- | res/values/cm_dimens.xml | 2 | ||||
| -rw-r--r-- | src/com/android/dialer/callerinfo/CallerInfoProviderPicker.java | 10 | ||||
| -rw-r--r-- | src/com/android/dialer/util/ImageUtils.java | 29 |
3 files changed, 21 insertions, 20 deletions
diff --git a/res/values/cm_dimens.xml b/res/values/cm_dimens.xml index 8567c88a8..0a6ee19e2 100644 --- a/res/values/cm_dimens.xml +++ b/res/values/cm_dimens.xml @@ -15,4 +15,6 @@ <dimen name="coachmark_hint_text">14sp</dimen> <dimen name="coachmark_touch_padding">14sp</dimen> + <dimen name="callerinfo_provider_picker_logo_width">98dp</dimen> + <dimen name="callerinfo_provider_picker_logo_height">20dp</dimen> </resources>
\ No newline at end of file diff --git a/src/com/android/dialer/callerinfo/CallerInfoProviderPicker.java b/src/com/android/dialer/callerinfo/CallerInfoProviderPicker.java index 918c67f22..d3c9e4f4f 100644 --- a/src/com/android/dialer/callerinfo/CallerInfoProviderPicker.java +++ b/src/com/android/dialer/callerinfo/CallerInfoProviderPicker.java @@ -144,8 +144,12 @@ public class CallerInfoProviderPicker { subText = Html.fromHtml(text); } + int logoWidth = context.getResources().getDimensionPixelSize( + R.dimen.callerinfo_provider_picker_logo_width); + int logoHeight = context.getResources().getDimensionPixelSize( + R.dimen.callerinfo_provider_picker_logo_height); Bitmap logo = ImageUtils.drawableToBitmap(info.getBrandLogo()); - + Bitmap scaledLogo = ImageUtils.scaleBitmapToTarget(logo, logoHeight, logoWidth); int resId = info.hasProperty(ProviderInfo.PROPERTY_SUPPORTS_SPAM) ? R.string.callerinfo_provider_auth_desc : R.string.callerinfo_provider_auth_desc_no_spam; @@ -158,8 +162,8 @@ public class CallerInfoProviderPicker { nudge.setSubhead(subText.toString()); } - if (logo != null) { - nudge.setTitleImage(logo); + if (scaledLogo != null) { + nudge.setTitleImage(scaledLogo); } Intent enableIntent = buildEnableIntent(context, component, info, metricsReason); diff --git a/src/com/android/dialer/util/ImageUtils.java b/src/com/android/dialer/util/ImageUtils.java index e57e85265..46fc02aa1 100644 --- a/src/com/android/dialer/util/ImageUtils.java +++ b/src/com/android/dialer/util/ImageUtils.java @@ -77,10 +77,9 @@ public class ImageUtils { /** * Scale bitmap to the defined bounds. The bitmap will be scaled while maintaining the - * aspect ratio and center-cropped(vertically and horizontally) if it exceeds the - * defined bounds. + * aspect ratio */ - public static Bitmap scaleAndCropBitmapToTarget(Bitmap bitmap, int targetHeight, + public static Bitmap scaleBitmapToTarget(Bitmap bitmap, int targetHeight, int targetWidth) { if (bitmap == null) { return bitmap; @@ -89,25 +88,23 @@ public class ImageUtils { int bitmapHeight = bitmap.getHeight(); int bitmapWidth = bitmap.getWidth(); - int deltaWidth = targetWidth - bitmapWidth; - int deltaHeight = targetHeight - bitmapHeight; + int deltaWidth = Math.abs(targetWidth - bitmapWidth); + int deltaHeight = Math.abs(targetHeight - bitmapHeight); - // nothing to do if src bitmap is bigger than or equal to the target - if (deltaWidth <= 0 && deltaHeight <= 0) + // nothing to do if one of the dimensions doesn't change as the aspect ratio + // needs to be preserved + if (deltaWidth == 0 || deltaHeight == 0) return bitmap; - // scale bitmap along the dimension that is lacking the greatest - float scale = Math.max( ((float)targetWidth) / bitmapWidth, + // scale bitmap to fit target bounds + float scale = Math.min( ((float)targetWidth) / bitmapWidth, ((float)targetHeight) / bitmapHeight); // calculate the new bitmap dimensions - int newHeight = (int) Math.ceil(bitmapHeight * scale); - int newWidth = (int) Math.ceil(bitmapWidth * scale); + int newHeight = (int) Math.floor(bitmapHeight * scale); + int newWidth = (int) Math.floor(bitmapWidth * scale); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); - // center the bitmap vertically and horizontally - int startX = Math.max(0, (newWidth - targetWidth) / 2); - int startY = Math.max(0, (newHeight - targetHeight) / 2); if (DEBUG) { Log.i(TAG, "bitmapWidth : " + bitmapWidth); Log.i(TAG, "bitmapHeight : " + bitmapHeight); @@ -115,11 +112,9 @@ public class ImageUtils { Log.i(TAG, "deltaHeight : " + deltaHeight); Log.i(TAG, "newWidth : " + newWidth); Log.i(TAG, "newHeight : " + newHeight); - Log.i(TAG, "startX : " + startX); - Log.i(TAG, "startY : " + startY); } - return Bitmap.createBitmap(scaledBitmap, startX, startY, targetWidth, targetHeight); + return scaledBitmap; } /** |
