From 9c9159715c89e30aec11ae7e7a1d7591006e5cbe Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Mon, 21 Jan 2019 17:58:20 -0700 Subject: [PATCH] Improve the night mode WebView text selection color. https://redmine.stoutner.com/issues/194 --- app/src/main/assets/css/dark_theme.css | 5 ++ .../activities/MainWebViewActivity.java | 16 ++-- app/src/main/res/layout/about_tab_version.xml | 73 +++++++++++++------ 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/app/src/main/assets/css/dark_theme.css b/app/src/main/assets/css/dark_theme.css index 95739ba7..9af6c54b 100644 --- a/app/src/main/assets/css/dark_theme.css +++ b/app/src/main/assets/css/dark_theme.css @@ -29,6 +29,11 @@ a { text-decoration: none; } +/* Blue 900 */ +::selection { + background: #0D47A1; +} + /* Blue 600 */ h3 { color: #1E88E5; diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index c1463d92..96098947 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -95,6 +95,7 @@ import android.webkit.ValueCallback; import android.webkit.WebBackForwardList; import android.webkit.WebChromeClient; import android.webkit.WebResourceResponse; +import android.webkit.WebSettings; import android.webkit.WebStorage; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -982,11 +983,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook if (nightMode) { // `background-color: #212121` sets the background to be dark gray. `color: #BDBDBD` sets the text color to be light gray. `box-shadow: none` removes a lower underline on links // used by WordPress. `text-decoration: none` removes all text underlines. `text-shadow: none` removes text shadows, which usually have a hard coded color. - // `border: none` removes all borders, which can also be used to underline text. - // `a {color: #1565C0}` sets links to be a dark blue. `!important` takes precedent over any existing sub-settings. + // `border: none` removes all borders, which can also be used to underline text. `a {color: #1565C0}` sets links to be a dark blue. + // `::selection {background: #0D47A1}' sets the text selection highlight color to be a dark blue. `!important` takes precedent over any existing sub-settings. mainWebView.evaluateJavascript("(function() {var parent = document.getElementsByTagName('head').item(0); var style = document.createElement('style'); style.type = 'text/css'; " + "style.innerHTML = '* {background-color: #212121 !important; color: #BDBDBD !important; box-shadow: none !important; text-decoration: none !important;" + - "text-shadow: none !important; border: none !important;} a {color: #1565C0 !important;}'; parent.appendChild(style)})()", value -> { + "text-shadow: none !important; border: none !important;} a {color: #1565C0 !important;} ::selection {background: #0D47A1 !important;}'; parent.appendChild(style)})()", value -> { // Initialize a handler to display `mainWebView`. Handler displayWebViewHandler = new Handler(); @@ -1221,10 +1222,15 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Hide zoom controls. mainWebView.getSettings().setDisplayZoomControls(false); - // Set `mainWebView` to use a wide viewport. Otherwise, some web pages will be scrunched and some content will render outside the screen. + // Don't allow mixed content (HTTP and HTTPS) on the same website. + if (Build.VERSION.SDK_INT >= 21) { + mainWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW); + } + + // Set the WebView to use a wide viewport. Otherwise, some web pages will be scrunched and some content will render outside the screen. mainWebView.getSettings().setUseWideViewPort(true); - // Set `mainWebView` to load in overview mode (zoomed out to the maximum width). + // Set the WebView to load in overview mode (zoomed out to the maximum width). mainWebView.getSettings().setLoadWithOverviewMode(true); // Explicitly disable geolocation. diff --git a/app/src/main/res/layout/about_tab_version.xml b/app/src/main/res/layout/about_tab_version.xml index 1df1ef0d..31d6bf78 100644 --- a/app/src/main/res/layout/about_tab_version.xml +++ b/app/src/main/res/layout/about_tab_version.xml @@ -65,6 +65,7 @@ android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="?attr/aboutText" + android:textIsSelectable="true" android:layout_below="@id/privacy_browser_textview" android:layout_toEndOf="@id/icon" /> @@ -91,32 +92,38 @@ + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> + android:layout_width="wrap_content" + android:textIsSelectable="true" /> \ No newline at end of file -- 2.43.0