Adding view port to fit the webview images in the screen size

This commit is contained in:
Shinokuni 2019-02-08 20:15:06 +00:00
parent 4d05174ce2
commit 8fcd5fc3ad
1 changed files with 4 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import org.jsoup.nodes.Document;
public class ReadropsWebView extends WebView { public class ReadropsWebView extends WebView {
private ItemWithFeed itemWithFeed; private ItemWithFeed itemWithFeed;
private int width;
public ReadropsWebView(Context context, AttributeSet attrs) { public ReadropsWebView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@ -24,8 +25,9 @@ public class ReadropsWebView extends WebView {
init(); init();
} }
public void setItem(ItemWithFeed itemWithFeed) { public void setItem(ItemWithFeed itemWithFeed, int width) {
this.itemWithFeed = itemWithFeed; this.itemWithFeed = itemWithFeed;
this.width = width;
loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "utf-8"); loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "utf-8");
} }
@ -40,6 +42,7 @@ public class ReadropsWebView extends WebView {
private String getText() { private String getText() {
Document document = Jsoup.parse(itemWithFeed.getItem().getText()); Document document = Jsoup.parse(itemWithFeed.getItem().getText());
document.head().append("<meta name=\"viewport\" content=\"width=" + width +", initial-scale=1\">");
document.head().append("<style>img{display: inline;height: auto;max-width: 100%;}</style>"); document.head().append("<style>img{display: inline;height: auto;max-width: 100%;}</style>");
return document.toString(); return document.toString();