mirror of https://github.com/readrops/Readrops.git
Use template for better html/css formatting
This commit is contained in:
parent
897f8d058d
commit
64cc134d68
|
@ -44,11 +44,11 @@ public class ReadropsWebView extends WebView {
|
|||
if (itemWithFeed.getItem().getText() != null) {
|
||||
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%;} " +
|
||||
"body { margin-left: 0px; margin-right: 0px; }</style>");
|
||||
return getContext().getString(R.string.webview_html_template, String.valueOf(width),
|
||||
Utils.getCssColor(itemWithFeed.getBgColor() != 0 ? itemWithFeed.getBgColor() :
|
||||
(itemWithFeed.getColor() != 0 ? itemWithFeed.getColor() : getResources().getColor(R.color.colorPrimary))),
|
||||
document.body().html());
|
||||
|
||||
return document.toString();
|
||||
} else
|
||||
return null;
|
||||
|
||||
|
|
|
@ -5,13 +5,16 @@ import android.app.Application;
|
|||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
@ -64,4 +67,12 @@ public final class Utils {
|
|||
return minutes;
|
||||
}
|
||||
|
||||
public static String getCssColor(@ColorInt int color) {
|
||||
return String.format(Locale.US, "rgba(%d,%d,%d,%.2f)",
|
||||
Color.red(color),
|
||||
Color.green(color),
|
||||
Color.blue(color),
|
||||
Color.alpha(color) / 255.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="webview_html_template" translatable="false"><![CDATA[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=\"UTF-8\">
|
||||
<meta name=\"viewport\" content=\"width=%1$s, initial-scale=1\">
|
||||
<style type=\"text/css\">
|
||||
a:link, a:active, a:hover { color: %2$s }
|
||||
|
||||
img, video {
|
||||
display: inline;
|
||||
height: auto;
|
||||
max-width: 100%%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
%3$s
|
||||
</body>
|
||||
</html>]]></string>
|
||||
</resources>
|
Loading…
Reference in New Issue