Fit html message to width

pull/162/head
M66B 5 years ago
parent d0b02d85ed
commit 0881c3f9d1

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

@ -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());
if (viewport.size() == 0)
meta.attr("content", "");
else
meta.attr("content", TextUtils.join(" ;", viewport) + ";");
}
}
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();
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) {

Loading…
Cancel
Save