diff --git a/CHANGELOG.md b/CHANGELOG.md index 417c2e11..d26f5722 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Updated Flutter environment: sdk to `>=2.14.0 <3.0.0` and flutter version to `>=2.5.0` - Added `singleInstance` option for Android `ChromeSafariBrowser` implementation - Added `onDownloadStartRequest` event and deprecated old `onDownloadStart` event +- Added `shareState` Android option for `ChromeSafariBrowser` class - Fixed missing `onZoomScaleChanged` call for `InAppBrowser` class - Fixed `requestImageRef` method always `null` on iOS - Fixed "applicationNameForUserAgent is not work in ios" [#525](https://github.com/pichillilorenzo/flutter_inappwebview/issues/525) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java index 80302c65..c2d6addc 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.os.Bundle; import android.util.Log; +import androidx.browser.customtabs.CustomTabColorSchemeParams; import androidx.browser.customtabs.CustomTabsCallback; import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsService; @@ -149,17 +150,22 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel. } private void prepareCustomTabs(List> menuItemList) { - if (options.addDefaultShareMenuItem) - builder.addDefaultShareMenuItem(); + if (options.addDefaultShareMenuItem != null) { + builder.setShareState(options.addDefaultShareMenuItem ? + CustomTabsIntent.SHARE_STATE_ON : CustomTabsIntent.SHARE_STATE_OFF); + } else { + builder.setShareState(options.shareState); + } - if (options.toolbarBackgroundColor != null && !options.toolbarBackgroundColor.isEmpty()) - builder.setToolbarColor(Color.parseColor(options.toolbarBackgroundColor)); + if (options.toolbarBackgroundColor != null && !options.toolbarBackgroundColor.isEmpty()) { + CustomTabColorSchemeParams.Builder defaultColorSchemeBuilder = new CustomTabColorSchemeParams.Builder(); + builder.setDefaultColorSchemeParams(defaultColorSchemeBuilder + .setToolbarColor(Color.parseColor(options.toolbarBackgroundColor)) + .build()); + } builder.setShowTitle(options.showTitle); - - if (options.enableUrlBarHiding) - builder.enableUrlBarHiding(); - + builder.setUrlBarHidingEnabled(options.enableUrlBarHiding); builder.setInstantAppsEnabled(options.instantAppsEnabled); for (HashMap menuItem : menuItemList) { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java index 7e04628b..1ba09751 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java @@ -3,6 +3,7 @@ package com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs; import android.content.Intent; import androidx.annotation.Nullable; +import androidx.browser.customtabs.CustomTabsIntent; import com.pichillilorenzo.flutter_inappwebview.Options; @@ -13,7 +14,9 @@ public class ChromeCustomTabsOptions implements Options options) { @@ -33,25 +38,34 @@ public class ChromeCustomTabsOptions implements Options toMap() { return { + // ignore: deprecated_member_use_from_same_package "addDefaultShareMenuItem": addDefaultShareMenuItem, + "shareState": shareState.toValue(), "showTitle": showTitle, "toolbarBackgroundColor": toolbarBackgroundColor?.toHex(), "enableUrlBarHiding": enableUrlBarHiding, @@ -70,7 +78,9 @@ class AndroidChromeCustomTabsOptions static AndroidChromeCustomTabsOptions fromMap(Map map) { AndroidChromeCustomTabsOptions options = new AndroidChromeCustomTabsOptions(); + // ignore: deprecated_member_use_from_same_package options.addDefaultShareMenuItem = map["addDefaultShareMenuItem"]; + options.shareState = map["shareState"]; options.showTitle = map["showTitle"]; options.toolbarBackgroundColor = UtilColor.fromHex(map["toolbarBackgroundColor"]); diff --git a/lib/src/types.dart b/lib/src/types.dart index 0c66dcd1..d8ccc7d7 100755 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -6960,4 +6960,58 @@ class DownloadStartRequest { String toString() { return toMap().toString(); } +} + +///Android-specific class representing the share state that should be applied to the custom tab. +class CustomTabsShareState { + final int _value; + + const CustomTabsShareState._internal(this._value); + + static final Set values = [ + CustomTabsShareState.SHARE_STATE_DEFAULT, + CustomTabsShareState.SHARE_STATE_ON, + CustomTabsShareState.SHARE_STATE_OFF, + ].toSet(); + + static CustomTabsShareState? fromValue(int? value) { + if (value != null) { + try { + return CustomTabsShareState.values + .firstWhere((element) => element.toValue() == value); + } catch (e) { + return null; + } + } + return null; + } + + int toValue() => _value; + + @override + String toString() { + switch (_value) { + case 1: + return "SHARE_STATE_ON"; + case 2: + return "SHARE_STATE_OFF"; + case 0: + default: + return "SHARE_STATE_DEFAULT"; + } + } + + ///Applies the default share settings depending on the browser. + static const SHARE_STATE_DEFAULT = const CustomTabsShareState._internal(0); + + ///Shows a share option in the tab. + static const SHARE_STATE_ON = const CustomTabsShareState._internal(1); + + ///Explicitly does not show a share option in the tab. + static const SHARE_STATE_OFF = const CustomTabsShareState._internal(2); + + bool operator ==(value) => value == _value; + + @override + int get hashCode => _value.hashCode; } \ No newline at end of file