示例#1
0
        static async Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUrl = new NSUrl(uri.AbsoluteUri);

            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                var sfViewController = new SFSafariViewController(nativeUrl, false);
                var vc = Platform.GetCurrentViewController();

                if (options.PreferredToolbarColor.HasValue)
                {
                    sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.Value.ToPlatformColor();
                }

                if (options.PreferredControlColor.HasValue)
                {
                    sfViewController.PreferredControlTintColor = options.PreferredControlColor.Value.ToPlatformColor();
                }

                if (sfViewController.PopoverPresentationController != null)
                {
                    sfViewController.PopoverPresentationController.SourceView = vc.View;
                }
                await vc.PresentViewControllerAsync(sfViewController, true);

                break;

            case BrowserLaunchMode.External:
                return(await UIApplication.SharedApplication.OpenUrlAsync(nativeUrl, new UIApplicationOpenUrlOptions()));
            }

            return(true);
        }
示例#2
0
        public static Task OpenAsync(string uri, BrowserLaunchOptions options)
        {
            if (string.IsNullOrWhiteSpace(uri))
            {
                throw new ArgumentNullException(nameof(uri), $"Uri cannot be empty.");
            }

            return(OpenAsync(new Uri(uri), options));
        }
示例#3
0
        static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUri = AndroidUri.Parse(uri.AbsoluteUri);

            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                var tabsBuilder = new CustomTabsIntent.Builder();
                tabsBuilder.SetShowTitle(true);
                if (options.PreferredToolbarColor.HasValue)
                {
                    tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.Value.ToInt());
                }
                if (options.TitleMode != BrowserTitleMode.Default)
                {
                    tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show);
                }

                var tabsIntent = tabsBuilder.Build();
                var flags      = ActivityFlags.ClearTop | ActivityFlags.NewTask;
#if __ANDROID_24__
                if (Platform.HasApiLevelN)
                {
                    flags |= ActivityFlags.LaunchAdjacent;
                }
#endif
                tabsIntent.Intent.SetFlags(flags);

#if __ANDROID_25__
                tabsIntent.LaunchUrl(Platform.AppContext, nativeUri);
#else
                tabsIntent.LaunchUrl(Platform.GetCurrentActivity(true), nativeUri);
#endif
                break;

            case BrowserLaunchMode.External:
                var intent = new Intent(Intent.ActionView, nativeUri);
                flags = ActivityFlags.ClearTop | ActivityFlags.NewTask;
#if __ANDROID_24__
                if (Platform.HasApiLevelN)
                {
                    flags |= ActivityFlags.LaunchAdjacent;
                }
#endif
                intent.SetFlags(flags);

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

                Platform.AppContext.StartActivity(intent);
                break;
            }

            return(Task.FromResult(true));
        }
示例#4
0
        static async Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                var nativeUrl        = new NSUrl(uri.AbsoluteUri);
                var sfViewController = new SFSafariViewController(nativeUrl, false);
                var vc = Platform.GetCurrentViewController();

                if (options.PreferredToolbarColor.HasValue)
                {
                    sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.Value.ToPlatformColor();
                }

                if (options.PreferredControlColor.HasValue)
                {
                    sfViewController.PreferredControlTintColor = options.PreferredControlColor.Value.ToPlatformColor();
                }

                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);

                break;

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

            return(true);
        }
示例#5
0
        static Task <bool> PlatformOpenAsync(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));
        }
 static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) =>
 throw new NotImplementedInReferenceAssemblyException();
示例#7
0
        static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUri = AndroidUri.Parse(uri.AbsoluteUri);

            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                var tabsBuilder = new CustomTabsIntent.Builder();
                tabsBuilder.SetShowTitle(true);
                if (options.PreferredToolbarColor.HasValue)
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.Value.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 = Platform.GetCurrentActivity(false);

                if (context == null)
                {
                    context = Platform.AppContext;

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

#if __ANDROID_24__
                if (Platform.HasApiLevelN && 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);
                }

                tabsIntent.LaunchUrl(context, nativeUri);

                break;

            case BrowserLaunchMode.External:
                var intent = new Intent(Intent.ActionView, nativeUri);
                var flags  = ActivityFlags.ClearTop | ActivityFlags.NewTask;
#if __ANDROID_24__
                if (Platform.HasApiLevelN && options.HasFlag(BrowserLaunchFlags.LaunchAdjacent))
                {
                    flags |= ActivityFlags.LaunchAdjacent;
                }
#endif
                intent.SetFlags(flags);

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

                Platform.AppContext.StartActivity(intent);
                break;
            }

            return(Task.FromResult(true));
        }
示例#8
0
 public static Task <bool> OpenAsync(Uri uri, BrowserLaunchOptions options) =>
 PlatformOpenAsync(EscapeUri(uri), options);
示例#9
0
 static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) =>
 Task.FromResult(NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(uri.AbsoluteUri)));
示例#10
0
 static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) =>
 Windows.System.Launcher.LaunchUriAsync(uri).AsTask();
 static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) =>
 throw ExceptionUtils.NotSupportedOrImplementedException;
示例#12
0
        static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            var p = Process.Start(uri.ToString());

            return(Task.FromResult(p != null));
        }
示例#13
0
 public ConnectToGitHubButton(CancellationToken cancellationToken, Xamarin.Essentials.BrowserLaunchOptions browserLaunchOptions) : base(WelcomePageAutomationIds.ConnectToGitHubButton, cancellationToken, browserLaunchOptions)
 {
     HorizontalOptions = LayoutOptions.Center;
     VerticalOptions   = LayoutOptions.End;
 }