Limit image width to screen width

pull/156/head
M66B 6 years ago
parent c0ed1c6e38
commit 13c16bb7ac

@ -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);

@ -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);

Loading…
Cancel
Save