1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 11:15:51 +00:00

Limit image width to screen width

This commit is contained in:
M66B 2019-05-03 17:20:24 +02:00
parent c0ed1c6e38
commit 13c16bb7ac
2 changed files with 24 additions and 2 deletions

View file

@ -1760,7 +1760,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, message.id, show_images, tvBody);
Drawable image = HtmlHelper.decodeImage(source, message.id, show_images, tvBody);
float width = context.getResources().getDisplayMetrics().widthPixels -
Helper.dp2pixels(context, 12); // margins
if (image.getIntrinsicWidth() > width) {
float scale = width / image.getIntrinsicWidth();
image.setBounds(0, 0,
Math.round(image.getIntrinsicWidth() * scale),
Math.round(image.getIntrinsicHeight() * scale));
}
return image;
}
}, null);

View file

@ -2760,7 +2760,18 @@ public class FragmentCompose extends FragmentBase {
new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, id, show_images, tvReference);
Drawable image = HtmlHelper.decodeImage(source, id, show_images, tvReference);
float width = context.getResources().getDisplayMetrics().widthPixels -
Helper.dp2pixels(context, 12); // margins;
if (image.getIntrinsicWidth() > width) {
float scale = width / image.getIntrinsicWidth();
image.setBounds(0, 0,
Math.round(image.getIntrinsicWidth() * scale),
Math.round(image.getIntrinsicHeight() * scale));
}
return image;
}
},
null);