mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Resize the contact picture bitmaps to the display size
This commit is contained in:
parent
d86dd3a4e7
commit
b25dfb802d
@ -22,6 +22,11 @@ import android.widget.QuickContactBadge;
|
||||
import com.fsck.k9.helper.Contacts;
|
||||
|
||||
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}.
|
||||
*/
|
||||
@ -37,6 +42,7 @@ public class ContactPictureLoader {
|
||||
private Resources mResources;
|
||||
private Contacts mContactsHelper;
|
||||
private Bitmap mDefaultPicture;
|
||||
private int mPictureSizeInPx;
|
||||
|
||||
/**
|
||||
* LRU cache of contact pictures.
|
||||
@ -64,6 +70,9 @@ public class ContactPictureLoader {
|
||||
mContactsHelper = Contacts.getInstance(appContext);
|
||||
mDefaultPicture = BitmapFactory.decodeResource(mResources, defaultPictureResource);
|
||||
|
||||
float scale = mResources.getDisplayMetrics().density;
|
||||
mPictureSizeInPx = (int) (PICTURE_SIZE * scale);
|
||||
|
||||
ActivityManager activityManager =
|
||||
(ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
int memClass = activityManager.getMemoryClass();
|
||||
@ -228,7 +237,12 @@ public class ContactPictureLoader {
|
||||
InputStream stream = mContentResolver.openInputStream(x);
|
||||
if (stream != null) {
|
||||
try {
|
||||
bitmap = BitmapFactory.decodeStream(stream);
|
||||
Bitmap tempBitmap = BitmapFactory.decodeStream(stream);
|
||||
bitmap = Bitmap.createScaledBitmap(tempBitmap, mPictureSizeInPx,
|
||||
mPictureSizeInPx, true);
|
||||
if (tempBitmap != bitmap) {
|
||||
tempBitmap.recycle();
|
||||
}
|
||||
} finally {
|
||||
try { stream.close(); } catch (IOException e) { /* ignore */ }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user