mirror of https://github.com/M66B/FairEmail.git
Flow images
This commit is contained in:
parent
73a2b149e8
commit
b454409c10
|
@ -1835,18 +1835,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
return HtmlHelper.fromHtml(html, new Html.ImageGetter() {
|
||||
@Override
|
||||
public Drawable getDrawable(String source) {
|
||||
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;
|
||||
return HtmlHelper.decodeImage(source, message.id, show_images, tvBody);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
|
|
@ -2760,18 +2760,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
new Html.ImageGetter() {
|
||||
@Override
|
||||
public Drawable getDrawable(String source) {
|
||||
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;
|
||||
return HtmlHelper.decodeImage(source, id, show_images, tvReference);
|
||||
}
|
||||
},
|
||||
null);
|
||||
|
|
|
@ -161,50 +161,17 @@ public class HtmlHelper {
|
|||
// Abbreviations
|
||||
document.select("abbr").tagName("u");
|
||||
|
||||
// Images
|
||||
for (Element img : document.select("img")) {
|
||||
// Get image attributes
|
||||
String src = img.attr("src");
|
||||
String alt = img.attr("alt");
|
||||
String title = img.attr("title");
|
||||
boolean tracking = (paranoid && isTrackingPixel(img));
|
||||
|
||||
// Remove link tracking pixel
|
||||
if (tracking)
|
||||
img.removeAttr("src");
|
||||
|
||||
// Create image container
|
||||
Element span = document.createElement("span");
|
||||
span.appendElement("br");
|
||||
span.appendChild(img.clone());
|
||||
span.appendElement("br");
|
||||
|
||||
// Show image title
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
span.appendElement("br");
|
||||
span.appendElement("em").text(title);
|
||||
}
|
||||
if (!TextUtils.isEmpty(alt)) {
|
||||
span.appendElement("br");
|
||||
span.appendElement("em").text(alt);
|
||||
}
|
||||
|
||||
if (tracking) {
|
||||
// Tracking pixel link
|
||||
span.appendElement("br");
|
||||
Element a = document.createElement("a");
|
||||
a.attr("href", src);
|
||||
a.appendText(context.getString(R.string.title_hint_tracking_image,
|
||||
img.attr("width"), img.attr("height")));
|
||||
span.appendChild(a);
|
||||
}
|
||||
|
||||
// Replace img by span containing img
|
||||
img.tagName("span");
|
||||
for (Attribute attr : img.attributes().asList())
|
||||
img.attributes().remove(attr.getKey());
|
||||
img.html(span.html());
|
||||
}
|
||||
// Remove link tracking pixels
|
||||
if (paranoid)
|
||||
for (Element img : document.select("img"))
|
||||
if (isTrackingPixel(img)) {
|
||||
String src = img.attr("src");
|
||||
img.removeAttr("src");
|
||||
img.tagName("a");
|
||||
img.attr("href", src);
|
||||
img.appendText(context.getString(R.string.title_hint_tracking_image,
|
||||
img.attr("width"), img.attr("height")));
|
||||
}
|
||||
|
||||
// Tables
|
||||
for (Element col : document.select("th,td")) {
|
||||
|
@ -424,7 +391,7 @@ public class HtmlHelper {
|
|||
Log.i("Download " + source);
|
||||
Bitmap bm;
|
||||
try (InputStream is = new URL(source).openStream()) {
|
||||
int scaleTo = res.getDisplayMetrics().widthPixels;
|
||||
int scaleTo = res.getDisplayMetrics().widthPixels * 2;
|
||||
int factor = 1;
|
||||
while (options.outWidth / factor > scaleTo)
|
||||
factor *= 2;
|
||||
|
@ -439,9 +406,9 @@ public class HtmlHelper {
|
|||
}
|
||||
|
||||
if (bm == null)
|
||||
throw new FileNotFoundException("Download image failed");
|
||||
throw new FileNotFoundException("Download image failed source=" + source);
|
||||
|
||||
Log.i("Downloaded image");
|
||||
Log.i("Downloaded image source=" + source);
|
||||
|
||||
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 90, os);
|
||||
|
|
Loading…
Reference in New Issue