- } else if ((Build.VERSION.SDK_INT < 33) && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { // The device is running API < 33 and the WebView supports force dark.
- // Set the WebView theme.
- switch (webViewThemeInt) {
- case DomainsDatabaseHelper.SYSTEM_DEFAULT:
- // Set the WebView theme. A switch statement cannot be used because the WebView theme entry values string array is not a compile time constant.
- if (webViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
- // Turn off the WebView dark mode.
- //noinspection deprecation
- WebSettingsCompat.setForceDark(nestedScrollWebView.getSettings(), WebSettingsCompat.FORCE_DARK_OFF);
- } else if (webViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
- // Turn on the WebView dark mode.
- //noinspection deprecation
- WebSettingsCompat.setForceDark(nestedScrollWebView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
- } else { // The system default theme is selected.
- // Get the current system theme status.
- int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
-
- // Set the WebView theme according to the current system theme status.
- if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { // The system is in day mode.
- // Turn off the WebView dark mode.
- //noinspection deprecation
- WebSettingsCompat.setForceDark(nestedScrollWebView.getSettings(), WebSettingsCompat.FORCE_DARK_OFF);
- } else { // The system is in night mode.
- // Turn on the WebView dark mode.
- //noinspection deprecation
- WebSettingsCompat.setForceDark(nestedScrollWebView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
- }
- }
- break;
-
- case DomainsDatabaseHelper.LIGHT_THEME:
- // Turn off the WebView dark mode.
- //noinspection deprecation
- WebSettingsCompat.setForceDark(nestedScrollWebView.getSettings(), WebSettingsCompat.FORCE_DARK_OFF);
- break;
-
- case DomainsDatabaseHelper.DARK_THEME:
- // Turn on the WebView dark mode.
- //noinspection deprecation
- WebSettingsCompat.setForceDark(nestedScrollWebView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
- break;
- }