summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2016-05-16 11:28:02 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-05-16 14:19:13 -0700
commit9fb1a7b0e02751d0b08be888ef9f9f42d10e9de7 (patch)
tree6df29640e9b9734bfc93cbccc59493ddf6b961a7 /src
parent4b717656918860843938a41cf61b6f8a8afe9e42 (diff)
downloadandroid_packages_apps_Dialer-9fb1a7b0e02751d0b08be888ef9f9f42d10e9de7.tar.gz
android_packages_apps_Dialer-9fb1a7b0e02751d0b08be888ef9f9f42d10e9de7.tar.bz2
android_packages_apps_Dialer-9fb1a7b0e02751d0b08be888ef9f9f42d10e9de7.zip
Constrain logo bounds within the picker for caller-info provider
Change-Id: I9017f6bd9a3b28e4c60d67acd030960e61f9be89 Issue-Id: CYNGNOS-2844
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/callerinfo/CallerInfoProviderPicker.java10
-rw-r--r--src/com/android/dialer/util/ImageUtils.java29
2 files changed, 19 insertions, 20 deletions
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;
}
/**