]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Apply theme and font selection also to HTML for web view.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sat, 18 Apr 2020 11:33:24 +0000 (13:33 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sat, 18 Apr 2020 11:33:24 +0000 (13:33 +0200)
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/MyWebView.java

index 77454f9a3e0032af41d5b056de722c577747fdc2..8d1f6fc03b3f347b33ea6c80c5521eb7df4246b5 100644 (file)
@@ -1454,10 +1454,16 @@ public class DictionaryActivity extends AppCompatActivity {
 
     private void showHtml(final List<HtmlEntry> 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(
-                    "<html><head><meta name=\"viewport\" content=\"width=device-width\"></head><body>%s</body></html>", html),
+                    "<html><head><meta name=\"viewport\" content=\"width=device-width\"></head><body style=\"%s\">%s</body></html>", style, html),
                                               htmlTextToHighlight, false),
             0);
     }
index 950b8abf76ad1a99b0acac7f73d1f8045c9162cf..d57ad0bc80cd621a82addb20d739a706317fb7e8 100644 (file)
@@ -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