1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-02-25 07:01:50 -05:00

Resize the contact picture bitmaps to the display size

This commit is contained in:
cketti 2013-02-08 18:04:38 +01:00
parent d86dd3a4e7
commit b25dfb802d

View File

@ -22,6 +22,11 @@ import android.widget.QuickContactBadge;
import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.Contacts;
public class ContactPictureLoader { public class ContactPictureLoader {
/**
* Resize the pictures to the following value (device-independent pixels).
*/
private static final int PICTURE_SIZE = 48;
/** /**
* Maximum number of email addresses to store in {@link #mUnknownContactsCache}. * Maximum number of email addresses to store in {@link #mUnknownContactsCache}.
*/ */
@ -37,6 +42,7 @@ public class ContactPictureLoader {
private Resources mResources; private Resources mResources;
private Contacts mContactsHelper; private Contacts mContactsHelper;
private Bitmap mDefaultPicture; private Bitmap mDefaultPicture;
private int mPictureSizeInPx;
/** /**
* LRU cache of contact pictures. * LRU cache of contact pictures.
@ -64,6 +70,9 @@ public class ContactPictureLoader {
mContactsHelper = Contacts.getInstance(appContext); mContactsHelper = Contacts.getInstance(appContext);
mDefaultPicture = BitmapFactory.decodeResource(mResources, defaultPictureResource); mDefaultPicture = BitmapFactory.decodeResource(mResources, defaultPictureResource);
float scale = mResources.getDisplayMetrics().density;
mPictureSizeInPx = (int) (PICTURE_SIZE * scale);
ActivityManager activityManager = ActivityManager activityManager =
(ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
int memClass = activityManager.getMemoryClass(); int memClass = activityManager.getMemoryClass();
@ -228,7 +237,12 @@ public class ContactPictureLoader {
InputStream stream = mContentResolver.openInputStream(x); InputStream stream = mContentResolver.openInputStream(x);
if (stream != null) { if (stream != null) {
try { try {
bitmap = BitmapFactory.decodeStream(stream); Bitmap tempBitmap = BitmapFactory.decodeStream(stream);
bitmap = Bitmap.createScaledBitmap(tempBitmap, mPictureSizeInPx,
mPictureSizeInPx, true);
if (tempBitmap != bitmap) {
tempBitmap.recycle();
}
} finally { } finally {
try { stream.close(); } catch (IOException e) { /* ignore */ } try { stream.close(); } catch (IOException e) { /* ignore */ }
} }