api33: prefer color-scheme over setForceDark()

This commit is contained in:
B. Petersen
2023-10-01 20:21:17 +02:00
committed by bjoern
parent 922f0dab1e
commit e980793afb
3 changed files with 9 additions and 3 deletions
+4
View File
@@ -1,3 +1,7 @@
html {
color-scheme: dark light;
}
a {
text-decoration: none;
}
@@ -35,7 +35,8 @@ public class ConnectivityActivity extends WebViewActivity implements DcEventCent
}
private void refresh() {
String connectivityHtml = DcHelper.getContext(this).getConnectivityHtml();
final String connectivityHtml = DcHelper.getContext(this).getConnectivityHtml()
.replace("</style>", " html { color-scheme: dark light; }</style>");
webView.loadDataWithBaseURL(null, connectivityHtml, "text/html", "utf-8", null);
}
@@ -133,9 +133,10 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity
}
protected void setForceDark() {
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
if (Build.VERSION.SDK_INT <= 32 && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
// needed for older API (tested on android7) that do not set `color-scheme` without the following hint
WebSettingsCompat.setForceDark(webView.getSettings(),
DynamicTheme.isDarkTheme(this) ? WebSettingsCompat.FORCE_DARK_ON : WebSettingsCompat.FORCE_DARK_OFF);
DynamicTheme.isDarkTheme(this) ? WebSettingsCompat.FORCE_DARK_ON : WebSettingsCompat.FORCE_DARK_OFF);
}
}