mirror of https://github.com/M66B/FairEmail.git
Scale attached images before display to save memory
This commit is contained in:
parent
b40c23b23d
commit
ba81c269fa
|
@ -23,6 +23,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
|
@ -79,8 +81,27 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
|
||||
private void bindTo(EntityAttachment attachment) {
|
||||
if (attachment.available) {
|
||||
Drawable d = BitmapDrawable.createFromPath(
|
||||
EntityAttachment.getFile(context, attachment.id).getAbsolutePath());
|
||||
Drawable d = null;
|
||||
File file = EntityAttachment.getFile(context, attachment.id);
|
||||
|
||||
if ("image/jpeg".equals(attachment.type) || "image/png".equals(attachment.type)) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
||||
|
||||
int scaleTo = context.getResources().getDisplayMetrics().widthPixels / 2;
|
||||
int factor = Math.min(options.outWidth / scaleTo, options.outWidth / scaleTo);
|
||||
if (factor > 1) {
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = factor;
|
||||
Bitmap scaled = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
||||
d = new BitmapDrawable(scaled);
|
||||
}
|
||||
}
|
||||
|
||||
if (d == null)
|
||||
d = BitmapDrawable.createFromPath(file.getAbsolutePath());
|
||||
|
||||
if (d == null)
|
||||
image.setImageResource(R.drawable.baseline_broken_image_24);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue