Esempio n. 1
0
        Task PlatformRequestAsync(ShareTextRequest request)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.ShareText,
            };

            if (!string.IsNullOrEmpty(request.Text))
            {
                appControl.ExtraData.Add(AppControlData.Text, request.Text);
            }
            if (!string.IsNullOrEmpty(request.Uri))
            {
                appControl.ExtraData.Add(AppControlData.Url, request.Uri);
            }
            if (!string.IsNullOrEmpty(request.Subject))
            {
                appControl.ExtraData.Add(AppControlData.Subject, request.Subject);
            }
            if (!string.IsNullOrEmpty(request.Title))
            {
                appControl.ExtraData.Add(AppControlData.Title, request.Title);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        Task PlatformRequestAsync(ShareTextRequest request)
        {
            var hwnd = WindowStateManager.Default.GetActiveWindowHandle(true);
            var dataTransferManager = DataTransferManagerHelper.GetDataTransferManager(hwnd);

            dataTransferManager.DataRequested += ShareTextHandler;

            DataTransferManagerHelper.ShowShare(hwnd);

            void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e)
            {
                var newRequest = e.Request;

                newRequest.Data.Properties.Title = request.Title ?? AppInfo.Current.Name;

                if (!string.IsNullOrWhiteSpace(request.Text))
                {
                    newRequest.Data.SetText(request.Text);
                }

                if (!string.IsNullOrWhiteSpace(request.Uri))
                {
                    newRequest.Data.SetWebLink(new Uri(request.Uri));
                }

                dataTransferManager.DataRequested -= ShareTextHandler;
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        Task PlatformRequestAsync(ShareTextRequest request)
        {
            var items = new List <NSObject>();

            if (!string.IsNullOrWhiteSpace(request.Text))
            {
                items.Add(new ShareActivityItemSource(new NSString(request.Text), request.Title));
            }

            if (!string.IsNullOrWhiteSpace(request.Uri))
            {
                items.Add(new ShareActivityItemSource(NSUrl.FromString(request.Uri), request.Title));
            }

            var activityController = new UIActivityViewController(items.ToArray(), null);

            var vc = WindowStateManager.Default.GetCurrentUIViewController(true);

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

                if (request.PresentationSourceBounds != Rect.Zero || OperatingSystem.IsIOSVersionAtLeast(13, 0))
                {
                    activityController.PopoverPresentationController.SourceRect = request.PresentationSourceBounds.AsCGRect();
                }
            }

            return(vc.PresentViewControllerAsync(activityController, true));
        }
Esempio n. 4
0
        Task PlatformRequestAsync(ShareTextRequest request)
        {
            var items = new List <string>();

            if (!string.IsNullOrWhiteSpace(request.Text))
            {
                items.Add(request.Text);
            }

            if (!string.IsNullOrWhiteSpace(request.Uri))
            {
                items.Add(request.Uri);
            }

            var intent = new Intent(Intent.ActionSend);

            intent.SetType(FileMimeTypes.TextPlain);
            intent.PutExtra(Intent.ExtraText, string.Join(System.Environment.NewLine, items));

            if (!string.IsNullOrWhiteSpace(request.Subject))
            {
                intent.PutExtra(Intent.ExtraSubject, request.Subject);
            }

            var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty);
            var flags         = ActivityFlags.ClearTop | ActivityFlags.NewTask;

            chooserIntent.SetFlags(flags);
            Application.Context.StartActivity(chooserIntent);

            return(Task.CompletedTask);
        }
Esempio n. 5
0
        public Task RequestAsync(ShareTextRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrEmpty(request.Text) && string.IsNullOrEmpty(request.Uri))
            {
                throw new ArgumentException($"Both the {nameof(request.Text)} and {nameof(request.Uri)} are invalid. Make sure to include at least one of them in the request.");
            }

            return(PlatformRequestAsync(request));
        }
Esempio n. 6
0
        Task PlatformRequestAsync(ShareTextRequest request)
        {
            var items = new List <NSObject>();

            if (!string.IsNullOrWhiteSpace(request.Title))
            {
                items.Add(new NSString(request.Title));
            }
            if (!string.IsNullOrWhiteSpace(request.Text))
            {
                items.Add(new NSString(request.Text));
            }
            if (!string.IsNullOrWhiteSpace(request.Uri))
            {
                items.Add(NSUrl.FromString(request.Uri));
            }

            return(PlatformShowRequestAsync(request, items));
        }
Esempio n. 7
0
 public static Task RequestAsync(ShareTextRequest request) =>
 Current.RequestAsync(request);
 Task PlatformRequestAsync(ShareTextRequest request) =>
 throw ExceptionUtils.NotSupportedOrImplementedException;