From 1fd8a062f30509b54e84097312cf8ceeb8fdbf09 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 7 Oct 2022 01:50:51 +0200 Subject: [PATCH] updated algorithmicDarkeningAllowed --- .../webview/in_app_webview/InAppWebView.java | 8 ++++---- .../webview/in_app_webview/InAppWebViewSettings.java | 4 ++-- lib/src/android/webview_feature.dart | 8 ++++++++ lib/src/android/webview_feature.g.dart | 10 ++++++++++ lib/src/in_app_webview/in_app_webview_settings.dart | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java index f33d73b2..672504ac 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java @@ -385,8 +385,8 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie WebSettingsCompat.setWillSuppressErrorPage(settings, customSettings.willSuppressErrorPage); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - settings.setAlgorithmicDarkeningAllowed(customSettings.algorithmicDarkeningAllowed); + if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, customSettings.algorithmicDarkeningAllowed); } contentBlockerHandler.getRuleList().clear(); @@ -1032,8 +1032,8 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie if (newSettingsMap.get("algorithmicDarkeningAllowed") != null && !Util.objEquals(customSettings.algorithmicDarkeningAllowed, newCustomSettings.algorithmicDarkeningAllowed) && - Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - settings.setAlgorithmicDarkeningAllowed(newCustomSettings.algorithmicDarkeningAllowed); + WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, newCustomSettings.algorithmicDarkeningAllowed); } customSettings = newCustomSettings; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewSettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewSettings.java index 88f510da..4a92ef17 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewSettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewSettings.java @@ -561,8 +561,8 @@ public class InAppWebViewSettings implements ISettings { if (WebViewFeature.isFeatureSupported(WebViewFeature.SUPPRESS_ERROR_PAGE)) { realSettings.put("willSuppressErrorPage", WebSettingsCompat.willSuppressErrorPage(settings)); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - realSettings.put("algorithmicDarkeningAllowed", settings.isAlgorithmicDarkeningAllowed()); + if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + realSettings.put("algorithmicDarkeningAllowed", WebSettingsCompat.isAlgorithmicDarkeningAllowed(settings)); } } return realSettings; diff --git a/lib/src/android/webview_feature.dart b/lib/src/android/webview_feature.dart index 423454fa..7826a93a 100644 --- a/lib/src/android/webview_feature.dart +++ b/lib/src/android/webview_feature.dart @@ -196,6 +196,10 @@ class WebViewFeature_ { static const SUPPRESS_ERROR_PAGE = const WebViewFeature_._internal("SUPPRESS_ERROR_PAGE"); + ///This feature covers [InAppWebViewSettings.algorithmicDarkeningAllowed]. + static const ALGORITHMIC_DARKENING = + const WebViewFeature_._internal("ALGORITHMIC_DARKENING"); + ///Return whether a feature is supported at run-time. On devices running Android version `Build.VERSION_CODES.LOLLIPOP` and higher, ///this will check whether a feature is supported, depending on the combination of the desired feature, the Android version of device, ///and the WebView APK on the device. If running on a device with a lower API level, this will always return `false`. @@ -403,6 +407,10 @@ class AndroidWebViewFeature_ { static const SUPPRESS_ERROR_PAGE = const AndroidWebViewFeature_._internal("SUPPRESS_ERROR_PAGE"); + ///This feature covers [InAppWebViewSettings.algorithmicDarkeningAllowed]. + static const ALGORITHMIC_DARKENING = + const AndroidWebViewFeature_._internal("ALGORITHMIC_DARKENING"); + ///Return whether a feature is supported at run-time. On devices running Android version `Build.VERSION_CODES.LOLLIPOP` and higher, ///this will check whether a feature is supported, depending on the combination of the desired feature, the Android version of device, ///and the WebView APK on the device. If running on a device with a lower API level, this will always return `false`. diff --git a/lib/src/android/webview_feature.g.dart b/lib/src/android/webview_feature.g.dart index d227a530..81c65b10 100644 --- a/lib/src/android/webview_feature.g.dart +++ b/lib/src/android/webview_feature.g.dart @@ -197,6 +197,10 @@ class WebViewFeature { static const SUPPRESS_ERROR_PAGE = WebViewFeature._internal('SUPPRESS_ERROR_PAGE', 'SUPPRESS_ERROR_PAGE'); + ///This feature covers [InAppWebViewSettings.algorithmicDarkeningAllowed]. + static const ALGORITHMIC_DARKENING = WebViewFeature._internal( + 'ALGORITHMIC_DARKENING', 'ALGORITHMIC_DARKENING'); + ///Set of all values of [WebViewFeature]. static final Set values = [ WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL, @@ -242,6 +246,7 @@ class WebViewFeature { WebViewFeature.WEB_VIEW_RENDERER_TERMINATE, WebViewFeature.DOCUMENT_START_SCRIPT, WebViewFeature.SUPPRESS_ERROR_PAGE, + WebViewFeature.ALGORITHMIC_DARKENING, ].toSet(); ///Gets a possible [WebViewFeature] instance from [String] value. @@ -497,6 +502,10 @@ class AndroidWebViewFeature { static const SUPPRESS_ERROR_PAGE = AndroidWebViewFeature._internal( 'SUPPRESS_ERROR_PAGE', 'SUPPRESS_ERROR_PAGE'); + ///This feature covers [InAppWebViewSettings.algorithmicDarkeningAllowed]. + static const ALGORITHMIC_DARKENING = AndroidWebViewFeature._internal( + 'ALGORITHMIC_DARKENING', 'ALGORITHMIC_DARKENING'); + ///Set of all values of [AndroidWebViewFeature]. static final Set values = [ AndroidWebViewFeature.CREATE_WEB_MESSAGE_CHANNEL, @@ -542,6 +551,7 @@ class AndroidWebViewFeature { AndroidWebViewFeature.WEB_VIEW_RENDERER_TERMINATE, AndroidWebViewFeature.DOCUMENT_START_SCRIPT, AndroidWebViewFeature.SUPPRESS_ERROR_PAGE, + AndroidWebViewFeature.ALGORITHMIC_DARKENING, ].toSet(); ///Gets a possible [AndroidWebViewFeature] instance from [String] value. diff --git a/lib/src/in_app_webview/in_app_webview_settings.dart b/lib/src/in_app_webview/in_app_webview_settings.dart index 38c2d95e..821a91f8 100755 --- a/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/lib/src/in_app_webview/in_app_webview_settings.dart @@ -672,7 +672,7 @@ class InAppWebViewSettings { /// ///If Android is applying Force Dark to WebView then WebView will ignore the value of this setting and behave as if it were set to true. /// - ///**NOTE**: available on Android 33+ + ///**NOTE**: available on Android 29+. bool algorithmicDarkeningAllowed; ///Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.