Ejemplo n.º 1
0
        private static async Task LaunchSafariViewController(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUrl = new NSUrl(uri.AbsoluteUri);

#pragma warning disable CA1416 // TODO: 'SFSafariViewController(NSUrl, bool)' is unsupported on: 'ios' 11.0 and later, there is an overload SFSafariViewController(NSUrl, SFSafariViewControllerConfiguration) supported from ios 11.0+
            var sfViewController = new SFSafariViewController(nativeUrl, false);
#pragma warning restore CA1416 // probably need to call the overloads depending on OS version
            var vc = WindowStateManager.Default.GetCurrentUIViewController(true) !;

            if (options.PreferredToolbarColor != null)
            {
                sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.AsUIColor();
            }

            if (options.PreferredControlColor != null)
            {
                sfViewController.PreferredControlTintColor = options.PreferredControlColor.AsUIColor();
            }

            if (sfViewController.PopoverPresentationController != null)
            {
                sfViewController.PopoverPresentationController.SourceView = vc.View !;
            }

            if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet))
            {
                sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
            }
            else if (options.HasFlag(BrowserLaunchFlags.PresentAsPageSheet))
            {
                sfViewController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
            }

            await vc.PresentViewControllerAsync(sfViewController, true);
        }
Ejemplo n.º 2
0
        private static async Task LaunchSafariViewController(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUrl        = new NSUrl(uri.AbsoluteUri);
            var sfViewController = new SFSafariViewController(nativeUrl, false);
            var vc = WindowStateManager.Default.GetCurrentUIViewController(true) !;

            if (options.PreferredToolbarColor != null)
            {
                sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.AsUIColor();
            }

            if (options.PreferredControlColor != null)
            {
                sfViewController.PreferredControlTintColor = options.PreferredControlColor.AsUIColor();
            }

            if (sfViewController.PopoverPresentationController != null)
            {
                sfViewController.PopoverPresentationController.SourceView = vc.View !;
            }

            if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet))
            {
                sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
            }
            else if (options.HasFlag(BrowserLaunchFlags.PresentAsPageSheet))
            {
                sfViewController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
            }

            await vc.PresentViewControllerAsync(sfViewController, true);
        }
Ejemplo n.º 3
0
        static void LaunchChromeTabs(BrowserLaunchOptions options, AndroidUri?nativeUri)
        {
            var tabsBuilder = new CustomTabsIntent.Builder();

            tabsBuilder.SetShowTitle(true);
#pragma warning disable CS0618 // Type or member is obsolete
            if (options.PreferredToolbarColor != null)
            {
                tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.ToInt());
            }
#pragma warning restore CS0618 // Type or member is obsolete
            if (options.TitleMode != BrowserTitleMode.Default)
            {
                tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show);
            }

            var           tabsIntent = tabsBuilder.Build();
            ActivityFlags?tabsFlags  = null;

            Context?context = ActivityStateManager.Default.GetCurrentActivity(false);

            if (context == null)
            {
                context = Application.Context;

                // If using ApplicationContext we need to set ClearTop/NewTask (See #225)
                tabsFlags = ActivityFlags.ClearTop | ActivityFlags.NewTask;
            }

#if __ANDROID_24__
            if (OperatingSystem.IsAndroidVersionAtLeast(24))
            {
                if (options.HasFlag(BrowserLaunchFlags.LaunchAdjacent))
                {
                    if (tabsFlags.HasValue)
                    {
                        tabsFlags |= ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask;
                    }
                    else
                    {
                        tabsFlags = ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask;
                    }
                }
            }
#endif

            // Check if there's flags specified to use
            if (tabsFlags.HasValue)
            {
                tabsIntent.Intent.SetFlags(tabsFlags.Value);
            }

            if (nativeUri != null)
            {
                tabsIntent.LaunchUrl(context, nativeUri);
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                await LaunchSafariViewController(uri, options);

                break;

            case BrowserLaunchMode.External:
                return(await Launcher.Default.OpenAsync(uri));
            }

            return(true);
        }
Ejemplo n.º 5
0
        public Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUri = AndroidUri.Parse(uri.AbsoluteUri);

            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                LaunchChromeTabs(options, nativeUri);
                break;

            case BrowserLaunchMode.External:
                LaunchExternalBrowser(options, nativeUri);
                break;
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 6
0
        static void LaunchExternalBrowser(BrowserLaunchOptions options, AndroidUri?nativeUri)
        {
            var intent = new Intent(Intent.ActionView, nativeUri);
            var flags  = ActivityFlags.ClearTop | ActivityFlags.NewTask;

#if __ANDROID_24__
            if (OperatingSystem.IsAndroidVersionAtLeast(24))
            {
                if (options.HasFlag(BrowserLaunchFlags.LaunchAdjacent))
                {
                    flags |= ActivityFlags.LaunchAdjacent;
                }
            }
#endif
            intent.SetFlags(flags);

            if (!PlatformUtils.IsIntentSupported(intent))
            {
                throw new FeatureNotSupportedException();
            }

            Application.Context.StartActivity(intent);
        }
Ejemplo n.º 7
0
        public Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions launchMode)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.View,
                Uri       = uri.AbsoluteUri
            };

            var hasMatches = AppControl.GetMatchedApplicationIds(appControl).Any();

            if (hasMatches)
            {
                AppControl.SendLaunchRequest(appControl);
            }

            return(Task.FromResult(hasMatches));
        }
Ejemplo n.º 8
0
 static Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options) =>
 Task.FromResult(NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(uri.AbsoluteUri)));
Ejemplo n.º 9
0
 public Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options) =>
 throw ExceptionUtils.NotSupportedOrImplementedException;
Ejemplo n.º 10
0
 public static Task <bool> OpenAsync(this IBrowser browser, string uri, BrowserLaunchOptions options) =>
 browser.OpenAsync(new Uri(uri), options);
Ejemplo n.º 11
0
 public static Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options) => Default.OpenAsync(uri, options);
Ejemplo n.º 12
0
 public Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options) =>
 global::Windows.System.Launcher.LaunchUriAsync(uri).AsTask();