1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-27 02:07:12 +00:00

Fit html message to width

This commit is contained in:
M66B 2019-10-08 19:54:52 +02:00
parent d0b02d85ed
commit 0881c3f9d1
2 changed files with 11 additions and 20 deletions

View file

@ -1377,7 +1377,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(false);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
@ -1399,8 +1399,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
settings.setBlockNetworkImage(!show_images);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (size != 0)
webView.setInitialScale(Math.round(size * 100));
webView.setInitialScale(size == 0 ? 1 : Math.round(size * 100));
wvBody.setMinimumHeight(height);
if (position != null) {
wvBody.setScrollX(position.first);
@ -1469,7 +1468,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
args.putBoolean("has_images", has_images);
if (show_full) {
HtmlHelper.removeViewportLimitations(document);
HtmlHelper.setViewport(document);
if (inline || show_images)
HtmlHelper.embedInlineImages(context, message.id, document);

View file

@ -565,23 +565,15 @@ public class HtmlHelper {
}
}
static void removeViewportLimitations(Document document) {
for (Element meta : document.select("meta").select("[name=viewport]")) {
String content = meta.attr("content");
String[] params = content.split(";");
if (params.length > 0) {
List<String> viewport = new ArrayList<>();
for (String param : params)
if (!param.toLowerCase(Locale.ROOT).contains("maximum-scale") &&
!param.toLowerCase(Locale.ROOT).contains("user-scalable"))
viewport.add(param.trim());
static void setViewport(Document document) {
// https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
document.head().select("meta").select("[name=viewport]").remove();
if (viewport.size() == 0)
meta.attr("content", "");
else
meta.attr("content", TextUtils.join(" ;", viewport) + ";");
}
}
document.head().prependChild(document.createElement("meta")
.attr("name", "viewport")
.attr("content", "width=device-width, initial-scale=1.0"));
Log.i(document.head().html());
}
static String getPreview(String body) {