Don't scale non-square QC photos while scrolling QC
To avoid re-scaling the non-square QC photo when resizing the QuickContact
ImageView, crop the contact photo into a square contact photo.
It is possible to use scaleType="matrix" with a custom matrix to avoid
needing to copy & crop the bitmap. However, it isn't worth the effort
given how rare non-square contact photos are. I have only seen non-square contact
photos for bussinesses.
Bug: 17135898
Change-Id: Idaa955d65c9fde74e104237908edf87e4c8cc1da
diff --git a/src/com/android/contacts/util/ImageViewDrawableSetter.java b/src/com/android/contacts/util/ImageViewDrawableSetter.java
index 226909e..e926e54 100644
--- a/src/com/android/contacts/util/ImageViewDrawableSetter.java
+++ b/src/com/android/contacts/util/ImageViewDrawableSetter.java
@@ -17,15 +17,13 @@
package com.android.contacts.util;
import android.content.res.Resources;
-import android.content.res.Resources.NotFoundException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
-import android.provider.ContactsContract.DisplayNameSources;
+import android.media.ThumbnailUtils;
import android.text.TextUtils;
-import android.util.Log;
import android.widget.ImageView;
import com.android.contacts.common.ContactPhotoManager;
@@ -161,8 +159,13 @@
}
private BitmapDrawable decodedBitmapDrawable(byte[] compressed) {
- Resources rsrc = mTarget.getResources();
+ final Resources rsrc = mTarget.getResources();
Bitmap bitmap = BitmapFactory.decodeByteArray(compressed, 0, compressed.length);
+ if (bitmap.getHeight() != bitmap.getWidth()) {
+ // Crop the bitmap into a square.
+ final int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
+ bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);
+ }
return new BitmapDrawable(rsrc, bitmap);
}
}