From 934313102f9cae5e845ceae738685848a1d272cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 18 Apr 2020 13:33:24 +0200 Subject: [PATCH] Apply theme and font selection also to HTML for web view. --- src/com/hughes/android/dictionary/DictionaryActivity.java | 8 +++++++- src/com/hughes/android/dictionary/MyWebView.java | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 77454f9..8d1f6fc 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -1454,10 +1454,16 @@ public class DictionaryActivity extends AppCompatActivity { private void showHtml(final List htmlEntries, final String htmlTextToHighlight) { String html = HtmlEntry.htmlBody(htmlEntries, index.shortName); + String style = ""; + if (typeface == Typeface.SERIF) { style = "font-family: serif;"; } + else if (typeface == Typeface.SANS_SERIF) { style = "font-family: sans-serif;"; } + else if (typeface == Typeface.MONOSPACE) { style = "font-family: monospace;"; } + if (application.getSelectedTheme() == DictionaryApplication.Theme.DEFAULT) + style += "background-color: black; color: white;"; // Log.d(LOG, "html=" + html); startActivityForResult( HtmlDisplayActivity.getHtmlIntent(getApplicationContext(), String.format( - "%s", html), + "%s", style, html), htmlTextToHighlight, false), 0); } diff --git a/src/com/hughes/android/dictionary/MyWebView.java b/src/com/hughes/android/dictionary/MyWebView.java index 950b8ab..d57ad0b 100644 --- a/src/com/hughes/android/dictionary/MyWebView.java +++ b/src/com/hughes/android/dictionary/MyWebView.java @@ -37,6 +37,8 @@ public class MyWebView extends WebView { super(context, attrs); getSettings().setSupportZoom(true); getSettings().setBuiltInZoomControls(true); + // TODO: check why AUTO does not work and consider using it (API 29/Android 10 only) + //getSettings().setForceDark(WebSettings.FORCE_DARK_ON); final WebViewClient webViewClient = new WebViewClient() { @Override -- 2.43.0