|
|
@ -23,6 +23,8 @@ import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
@ -79,8 +81,27 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|
|
|
|
|
|
|
|
|
|
|
private void bindTo(EntityAttachment attachment) {
|
|
|
|
private void bindTo(EntityAttachment attachment) {
|
|
|
|
if (attachment.available) {
|
|
|
|
if (attachment.available) {
|
|
|
|
Drawable d = BitmapDrawable.createFromPath(
|
|
|
|
Drawable d = null;
|
|
|
|
EntityAttachment.getFile(context, attachment.id).getAbsolutePath());
|
|
|
|
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)
|
|
|
|
if (d == null)
|
|
|
|
image.setImageResource(R.drawable.baseline_broken_image_24);
|
|
|
|
image.setImageResource(R.drawable.baseline_broken_image_24);
|
|
|
|
else
|
|
|
|
else
|
|
|
|