public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            if (indexPath.Section == 0)
            {
                var previewController = UIDocumentInteractionController.FromUrl(
                    NSUrl.FromFilename(source.Documents[indexPath.Row]));

                previewController.Delegate = new MyInteractionDelegate(this);
                previewController.PresentPreview(true);


                // You can present other options for the file instead of a preview
                //
                //previewController.PresentOptionsMenu(TableView.Frame, TableView, true);
                //previewController.PresentOpenInMenu(TableView.Frame, TableView, true);
            }
            else
            {
                var previewController = new QLPreviewController();
                previewController.DataSource = new QuickLookSource(source.Documents);

                previewController.CurrentPreviewItemIndex = indexPath.Row;
                NavigationController.PushViewController(previewController, true);

                // You can present modally instead
                //
                // PresentViewController(previewController, true, null);
            }
        }
 public override void DidEndPreview(UIDocumentInteractionController controller)
 {
     if (null != doneWithPreview)
     {
         doneWithPreview(null, null);
     }
 }
Exemplo n.º 3
0
        Task <bool> PlatformOpenAsync(OpenFileRequest request)
        {
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619
            documentController = new UIDocumentInteractionController()
            {
                Name = request.File.FileName,
                Url  = NSUrl.FromFilename(request.File.FullPath),
                Uti  = request.File.ContentType
            };

            var view = Platform.GetCurrentUIViewController().View;

            CGRect rect;

            if (request.PresentationSourceBounds != Rect.Zero)
            {
                rect = request.PresentationSourceBounds.AsCGRect();
            }
            else
            {
                rect = DeviceInfo.Idiom == DeviceIdiom.Tablet
                                        ? new CGRect(new CGPoint(view.Bounds.Width / 2, view.Bounds.Height), CGRect.Empty.Size)
                                        : view.Bounds;
            }

            documentController.PresentOpenInMenu(rect, view, true);
#pragma warning restore CA1416
            return(Task.FromResult(true));
        }
Exemplo n.º 4
0
    public void open(string filepath)
    {
        var previewController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filepath));

        previewController.Delegate = new FileInteractionDelegate(GetVisibleViewController());
        previewController.PresentPreview(true);
    }
Exemplo n.º 5
0
        private void ShowExtraMenu(object o, EventArgs arg)
        {
            var sheet = CreateActionSheet(Title);
            var vm = ViewModel;
            var openButton = !string.IsNullOrEmpty(ViewModel.FilePath) ? sheet.AddButton("Open In") : -1;
            var shareButton = !string.IsNullOrEmpty(ViewModel.HtmlUrl) ? sheet.AddButton("Share") : -1;
            var showButton = ViewModel.GoToHtmlUrlCommand.CanExecute(null) ? sheet.AddButton("Show in GitHub") : -1;
            var cancelButton = sheet.AddButton("Cancel");
            sheet.CancelButtonIndex = cancelButton;
            sheet.Dismissed += (s, e) => BeginInvokeOnMainThread(() => {
                try
                {
                    if (e.ButtonIndex == openButton)
                    {
                        var ctrl = new UIDocumentInteractionController();
                        ctrl.Url = NSUrl.FromFilename(ViewModel.FilePath);
                        ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
                    }
                    else if (e.ButtonIndex == shareButton)
                    {
                        AlertDialogService.ShareUrl(ViewModel?.HtmlUrl, o as UIBarButtonItem);
                    }
                    else if (e.ButtonIndex == showButton)
                    {
                        vm.GoToHtmlUrlCommand.Execute(null);
                    }
                }
                catch
                {
                }
            });

            sheet.ShowFrom(NavigationItem.RightBarButtonItem, true);
        }
Exemplo n.º 6
0
        public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
        {
            UIViewController value;

            owner.TryGetTarget(out value);
            return(value);
        }
Exemplo n.º 7
0
		private void ShowExtraMenu()
		{
			var sheet = MonoTouch.Utilities.GetSheet();
			var openButton = sheet.AddButton("Open In");
			var shareButton = ViewModel.HtmlUrl != null ? sheet.AddButton("Share") : -1;
			var showButton = ViewModel.HtmlUrl != null ? sheet.AddButton("Show in Bitbucket") : -1;
			var cancelButton = sheet.AddButton("Cancel");
			sheet.CancelButtonIndex = cancelButton;
			sheet.DismissWithClickedButtonIndex(cancelButton, true);
            sheet.Dismissed += (s, e) => {
                BeginInvokeOnMainThread(() =>
                {
				if (e.ButtonIndex == openButton)
				{
					var ctrl = new UIDocumentInteractionController();
					ctrl.Url = NSUrl.FromFilename(ViewModel.FilePath);
					ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
				}
				else if (e.ButtonIndex == shareButton)
				{
                    Mvx.Resolve<IShareService>().ShareUrl(ViewModel.HtmlUrl);
				}
				else if (e.ButtonIndex == showButton)
				{
					ViewModel.GoToHtmlUrlCommand.Execute(null);
				}
                });
			};

			sheet.ShowInView(this.View);
		}
Exemplo n.º 8
0
		private void ShowExtraMenu()
		{
			var sheet = MonoTouch.Utilities.GetSheet(Title);

			var openButton = sheet.AddButton("Open In".t());
			var shareButton = ViewModel.HtmlUrl != null ? sheet.AddButton("Share".t()) : -1;
			var showButton = ViewModel.HtmlUrl != null ? sheet.AddButton("Show in Bitbucket".t()) : -1;
			var cancelButton = sheet.AddButton("Cancel".t());
			sheet.CancelButtonIndex = cancelButton;
			sheet.DismissWithClickedButtonIndex(cancelButton, true);
			sheet.Clicked += (s, e) => {
				if (e.ButtonIndex == openButton)
				{
					var ctrl = new UIDocumentInteractionController();
					ctrl.Url = NSUrl.FromFilename(ViewModel.FilePath);
					ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
				}
				else if (e.ButtonIndex == shareButton)
				{
					var item = UIActivity.FromObject (ViewModel.HtmlUrl);
					var activityItems = new NSObject[] { item };
					UIActivity[] applicationActivities = null;
					var activityController = new UIActivityViewController (activityItems, applicationActivities);
					PresentViewController (activityController, true, null);
				}
				else if (e.ButtonIndex == showButton)
				{
					ViewModel.GoToHtmlUrlCommand.Execute(null);
				}
			};

			sheet.ShowInView(this.View);
		}
Exemplo n.º 9
0
        static Task PlatformOpenAsync(OpenFileRequest request)
        {
            var fileUrl = NSUrl.FromFilename(request.File.FullPath);

            documentController          = UIDocumentInteractionController.FromUrl(fileUrl);
            documentController.Delegate = new DocumentControllerDelegate
            {
                DismissHandler = () =>
                {
                    documentController?.Dispose();
                    documentController = null;
                }
            };
            documentController.Uti = request.File.ContentType;

            var vc = Platform.GetCurrentViewController();

            CoreGraphics.CGRect?rect = null;
            if (DeviceInfo.Idiom == DeviceIdiom.Tablet)
            {
                rect = new CoreGraphics.CGRect(new CoreGraphics.CGPoint(vc.View.Bounds.Width / 2, vc.View.Bounds.Height), CoreGraphics.CGRect.Empty.Size);
            }
            else
            {
                rect = vc.View.Bounds;
            }

            documentController.PresentOpenInMenu(rect.Value, vc.View, true);

            return(Task.CompletedTask);
        }
Exemplo n.º 10
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // set up resource paths
            string fontName = "content-font.ttf";

            SkiaSharp.Demos.CustomFontPath = NSBundle.MainBundle.PathForResource(Path.GetFileNameWithoutExtension(fontName), Path.GetExtension(fontName));
            var dir = Path.Combine(Path.GetTempPath(), "SkiaSharp.Demos", Path.GetRandomFileName());

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            SkiaSharp.Demos.WorkingDirectory = dir;
            SkiaSharp.Demos.OpenFileDelegate = path =>
            {
                var vc             = Xamarin.Forms.Platform.iOS.Platform.GetRenderer(Xamarin.Forms.Application.Current.MainPage) as UIViewController;
                var resourceToOpen = NSUrl.FromFilename(Path.Combine(dir, path));
                var controller     = UIDocumentInteractionController.FromUrl(resourceToOpen);
                if (!controller.PresentOpenInMenu(vc.View.Bounds, vc.View, true))
                {
                    new UIAlertView("SkiaSharp", "Unable to open file.", null, "OK").Show();
                }
            };

            global::Xamarin.Forms.Forms.Init();

            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Exports the configuration. Create a zip file which can be shared
        /// </summary>
        /// <param name="sender">Sender.</param>
        async partial void ExportConfiguration(NSObject sender)
        {
            UIActivityIndicatorView activityIndicator = new UIActivityIndicatorView(ExportConfigBtn.Frame);

            activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
            activityIndicator.StartAnimating();
            this.View.AddSubview(activityIndicator);
            ExportConfigBtn.Hidden = true;
            string zip = await ConfigsEngine.CreateFileForExport(_loadedConfiguration);

            activityIndicator.StopAnimating();
            activityIndicator.RemoveFromSuperview();
            ExportConfigBtn.Hidden = false;

            if (zip == string.Empty)
            {
                UIAlertView alertError = new UIAlertView("Error".Localize(), "Error Creating Zip File".Localize(), null, "Ok".Localize());
                alertError.Show();
                return;
            }

            var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(zip));

            viewer.PresentOpenInMenu(ExportConfigBtn.Frame, this.View, true);
        }
Exemplo n.º 12
0
		public override UIView ViewForPreview (UIDocumentInteractionController controller)
		{
			UIViewController vc = ViewControllerForPreview (controller);
			if (vc == null)
				return null;
			return vc.View;
		}
Exemplo n.º 13
0
        private void ShowExtraMenu(object o, EventArgs arg)
        {
            var sheet        = CreateActionSheet(Title);
            var vm           = ViewModel;
            var openButton   = !string.IsNullOrEmpty(ViewModel.FilePath) ? sheet.AddButton("Open In") : -1;
            var shareButton  = !string.IsNullOrEmpty(ViewModel.HtmlUrl) ? sheet.AddButton("Share") : -1;
            var showButton   = ViewModel.GoToHtmlUrlCommand.CanExecute(null) ? sheet.AddButton("Show in GitHub") : -1;
            var cancelButton = sheet.AddButton("Cancel");

            sheet.CancelButtonIndex = cancelButton;
            sheet.Dismissed        += (s, e) => BeginInvokeOnMainThread(() => {
                try
                {
                    if (e.ButtonIndex == openButton)
                    {
                        var ctrl = new UIDocumentInteractionController();
                        ctrl.Url = NSUrl.FromFilename(ViewModel.FilePath);
                        ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
                    }
                    else if (e.ButtonIndex == shareButton)
                    {
                        AlertDialogService.ShareUrl(ViewModel?.HtmlUrl, o as UIBarButtonItem);
                    }
                    else if (e.ButtonIndex == showButton)
                    {
                        vm.GoToHtmlUrlCommand.Execute(null);
                    }
                }
                catch
                {
                }
            });

            sheet.ShowFrom(NavigationItem.RightBarButtonItem, true);
        }
        private static UPMInboxFile ModelInboxFileFromInboxFile(UPInboxFile inboxFile)
        {
            UPMInboxFile upmInboxFile = new UPMInboxFile(StringIdentifier.IdentifierWithStringId(inboxFile.Path))
            {
                Path = inboxFile.Path,
                URL  = inboxFile.URL
            };

#if PORTING
            upmInboxFile.Name = inboxFile.Path.LastPathComponent();
            Exception    attributesErr;
            NSDictionary fileAttributes = NSFileManager.DefaultManager().AttributesOfItemAtPathError(inboxFile.Path, attributesErr);
            if (attributesErr)
            {
                DDLogError("UPInBoxPageModelController error no fileAttributes: %@", fileAttributes);
            }

            NSNumber fileSizeNumber = fileAttributes.ObjectForKey(NSFileSize);
            upmInboxFile.Size          = fileSizeNumber.LongLongValue();
            upmInboxFile.FormattedSize = NSByteCountFormatter.StringFromByteCountCountStyle(upmInboxFile.Size, NSByteCountFormatterCountStyleFile);
            upmInboxFile.Date          = fileAttributes.ObjectForKey(NSFileCreationDate);
            // Cant use TimeZone here. Called before Login and server independent.
            upmInboxFile.FormattedDate = UPInBoxPageModelController.UpDateFormatter().StringFromDate(upmInboxFile.Date);
            UIDocumentInteractionController interactionController = UIDocumentInteractionController.InteractionControllerWithURL(inboxFile.URL);
            ArrayList icons = interactionController.Icons;
            //upmInboxFile.Icon = icons.LastObject();  // Adding largest Icon available
#endif
            upmInboxFile.MimeTye = UPInboxFileManager.MimeTypeForPath(upmInboxFile.Path);
            upmInboxFile.Color   = UPInBoxPageModelController.ColorForMimeType(upmInboxFile.MimeTye);
            return(upmInboxFile);
        }
Exemplo n.º 15
0
 public override void DidEndSendingToApplication(UIDocumentInteractionController controller, string application)
 {
     //ChallengeModel challenge = InstagramViewController.Challenge;
     //challenge.Status = "Pending";
     //SL.Manager.UpdateChallenge(challenge, challenge.ID);
     InstagramViewController.SendToInstagramComplete();
 }
Exemplo n.º 16
0
        public static void PreviewFile(this UIViewController controller, NSUrl url)
        {
            if (!(controller is IUIDocumentInteractionControllerDelegate @delegate))
            {
                throw new InvalidOperationException($"{controller.GetType().Name} must implement 'UIDocumentInteractionControllerDelegate' protocol.");
            }

            var preview = UIDocumentInteractionController.FromUrl(url);

            preview.Delegate = @delegate;
            if (preview.PresentPreview(true))
            {
                return;
            }

            var alert = UIAlertController.Create(Localize("Global.NoPreview.Short"), Localize("Global.NoPreview.Long"), UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create(Localize("Global.BackAction"), UIAlertActionStyle.Cancel, null));
            var ok = UIAlertAction.Create(Localize("Global.NoPreview.OpenIn"), UIAlertActionStyle.Default, action => {
                var share = new UIActivityViewController(new[] { url }, null);
                controller.PresentViewController(share, true, null);
            });

            alert.AddAction(ok);
            alert.SetPreferredAction(ok);
            controller.PresentViewController(alert, true, null);
        }
Exemplo n.º 17
0
		public override System.Drawing.RectangleF RectangleForPreview (UIDocumentInteractionController controller)
		{
			UIView view = ViewForPreview (controller);
			if (view == null)
				return RectangleF.Empty;
			return view.Frame;
		}
Exemplo n.º 18
0
 /// <summary>
 /// Print preview of the report.
 /// </summary>
 /// <param name="sender">Sender.</param>
 partial void btnPrintPreview_TouchUpInside(UIButton sender)
 {
     //Object inspectionObject=new Object();
     if (reportPhotoSegment.SelectedSegment == 0)
     {
         if (File.Exists(reportPath))
         {
             var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(reportPath));
             UIDocumentInteractionControllerDelegateDerived del = new UIDocumentInteractionControllerDelegateDerived(this);
             del.doneWithPreview += (informer, eventArgs) => { btnFinalizeSave.Hidden = false;
                                                               btnEdit.Hidden         = false; };
             viewer.Delegate = del;
             viewer.PresentPreview(true);
         }
     }
     else
     {
         if (File.Exists(PhotoLogReportPath))
         {
             var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(PhotoLogReportPath));
             UIDocumentInteractionControllerDelegateDerived del = new UIDocumentInteractionControllerDelegateDerived(this);
             del.doneWithPreview += (informer, eventArgs) => { btnFinalizeSave.Hidden = false;
                                                               btnEdit.Hidden         = false; };
             viewer.Delegate = del;
             viewer.PresentPreview(true);
         }
     }
 }
Exemplo n.º 19
0
        static Task PlatformOpenAsync(OpenFileRequest request)
        {
            documentController = new UIDocumentInteractionController()
            {
                Name = request.File.FileName,
                Url  = NSUrl.FromFilename(request.File.FullPath),
                Uti  = request.File.ContentType
            };

            var view = Platform.GetCurrentUIViewController().View;

            CGRect rect;

            if (request.PresentationSourceBounds != Rectangle.Empty)
            {
                rect = request.PresentationSourceBounds.ToPlatformRectangle();
            }
            else
            {
                rect = DeviceInfo.Idiom == DeviceIdiom.Tablet
                    ? new CGRect(new CGPoint(view.Bounds.Width / 2, view.Bounds.Height), CGRect.Empty.Size)
                    : view.Bounds;
            }

            documentController.PresentOpenInMenu(rect, view, true);
            return(Task.CompletedTask);
        }
Exemplo n.º 20
0
        private void OpenFile()
        {
            string filePath = PdfPath();
            var    viewer   = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));

            viewer.PresentOpenInMenu(new RectangleF(0, -260, 320, 320), this.owner.View, true);
        }
Exemplo n.º 21
0
        public void OpenIn(object sender, string file)
        {
            var ctrl = new UIDocumentInteractionController();

            ctrl.Url = NSUrl.FromFilename(file);
            ctrl.PresentOpenInMenu(sender as UIBarButtonItem, true);
        }
        private void ShareDeck(Deck deck)
        {
            UIViewController topCtrl = UIApplication.SharedApplication.KeyWindow.RootViewController;

            //save deck in temp location with name
            var tempdir  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var file     = Path.Combine(tempdir, deck.Name + ".dfd");
            var deckJson = JsonConvert.SerializeObject(deck, Formatting.Indented);

            File.WriteAllText(file, deckJson);

            var navCtrl = topCtrl.ChildViewControllers.OfType <NavigationRenderer>().FirstOrDefault();

            if (navCtrl != null)
            {
                viewCtrl = navCtrl.TopViewController;

                var allButtons = viewCtrl.NavigationItem.RightBarButtonItems;
                var button     = allButtons[0];

                uidic      = UIDocumentInteractionController.FromUrl(new NSUrl(file, true));
                uidic.Name = "Share Deck";
                uidic.Uti  = "com.benreierson.deck";

                result = uidic.PresentOptionsMenu(button, true);
            }
        }
Exemplo n.º 23
0
        private void CreateShareInstagram(string mediaPath)
        {
            NSUrl imageURL     = new NSUrl(mediaPath, false);
            NSUrl instagramURL = NSUrl.FromString(@"instagram://app");

            //check for App is install or not
            if (UIApplication.SharedApplication.CanOpenUrl(instagramURL))
            {
                documentController     = UIDocumentInteractionController.FromUrl(imageURL);
                documentController.Uti = "com.instagram.exclusivegram";
                UIView presentingView = GetVisibleViewController().View;
                documentController.PresentOpenInMenu(new CGRect(x: 1, y: 1, width: 1, height: 1), presentingView, true);
                ShareInsTaskCompletion.SetResult(true);
            }
            else
            {
                bool  isSimulator = Runtime.Arch == Arch.SIMULATOR;
                NSUrl itunesLink;
                if (isSimulator)
                {
                    itunesLink = new NSUrl("https://itunes.apple.com/us/app/instagram/id389801252?mt=8");
                }
                else
                {
                    itunesLink = new NSUrl("itms://itunes.apple.com/us/app/instagram/id389801252?mt=8");
                }
                UIApplication.SharedApplication.OpenUrl(itunesLink, new NSDictionary()
                {
                }, null);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Open Instagram with the specified image and caption.
        /// </summary>
        /// <returns><c>true</c> if Instagram is installed, <c>false</c> otherwise.</returns>
        /// <param name="image">Image.</param>
        /// <param name="caption">Caption.</param>
        public static bool Instagram(UIImage image, string caption = null)
        {
            if (!UIApplication.SharedApplication().CanOpenURL(new NSURL("instagram://app")))
            {
                return(false);
            }

            // write image to tmp folder
            NSData data     = image.JPEGRepresentation(1f);
            string filePath = Application.temporaryCachePath + "/" + UUID.Generate() + ".igo";

            data.WriteToFile(filePath, true);

            _documentIC     = UIDocumentInteractionController.InteractionController(new NSURL(filePath, false));
            _documentIC.UTI = "com.instagram.exclusivegram";
            if (caption != null)
            {
                var annotation = new Dictionary <object, object>();
                annotation["InstagramCaption"] = caption;
                _documentIC.annotation         = annotation;
            }

            var rootView = UIApplication.deviceRootViewController.view;

            _documentIC.PresentOpenInMenu(new Rect(0, 0, 1, 1), rootView, true);
            return(true);
        }
Exemplo n.º 25
0
		private void ShowExtraMenu()
		{
			var sheet = CreateActionSheet(Title);
			var openButton = !string.IsNullOrEmpty(ViewModel.FilePath) ? sheet.AddButton("Open In".t()) : -1;
			var shareButton = !string.IsNullOrEmpty(ViewModel.HtmlUrl) ? sheet.AddButton("Share".t()) : -1;
			var showButton = ViewModel.GoToHtmlUrlCommand.CanExecute(null) ? sheet.AddButton("Show in GitHub".t()) : -1;
			var cancelButton = sheet.AddButton("Cancel".t());
			sheet.CancelButtonIndex = cancelButton;
			sheet.DismissWithClickedButtonIndex(cancelButton, true);
			sheet.Clicked += (s, e) => 
			{
				try
				{
					if (e.ButtonIndex == openButton)
					{
						var ctrl = new UIDocumentInteractionController();
						ctrl.Url = NSUrl.FromFilename(ViewModel.FilePath);
						ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
					}
					else if (e.ButtonIndex == shareButton)
					{
						ViewModel.ShareCommand.Execute(null);
					}
					else if (e.ButtonIndex == showButton)
					{
						ViewModel.GoToHtmlUrlCommand.Execute(null);
					}
				}
				catch (Exception ex)
				{
				}
			};

			sheet.ShowInView(this.View);
		}
Exemplo n.º 26
0
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            NSUrl url = new NSUrl(TableItems[indexPath.Row].longdesc, true);
            UIDocumentInteractionController udoc = UIDocumentInteractionController.FromUrl(url);

            udoc.PresentOpenInMenu(CGRect.Empty, owner.View, true);
            tableView.DeselectRow(indexPath, true);
        }
Exemplo n.º 27
0
        void IPDFHelper.OpenPDF(string pdfFilepath)
        {
            var viewer   = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(pdfFilepath));
            var rootVC   = UIApplication.SharedApplication.KeyWindow.RootViewController;
            var rootView = rootVC.View;
            var temp     = viewer.PresentOpenInMenu(new CoreGraphics.CGRect(0, -200, 100, 100), rootView, true);

            System.Diagnostics.Debug.WriteLine(temp);
        }
Exemplo n.º 28
0
        public override System.Drawing.RectangleF RectangleForPreview(UIDocumentInteractionController controller)
        {
            UIView view = ViewForPreview(controller);

            if (view == null)
            {
                return(RectangleF.Empty);
            }
            return(view.Frame);
        }
Exemplo n.º 29
0
        public void OpenFile(string filePath)
        {
            var PreviewController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));

            PreviewController.Delegate = new UIDocumentInteractionControllerDelegateClass(UIApplication.SharedApplication.KeyWindow.RootViewController);
            Device.BeginInvokeOnMainThread(() =>
            {
                PreviewController.PresentPreview(true);
            });
        }
Exemplo n.º 30
0
        public override UIView ViewForPreview(UIDocumentInteractionController controller)
        {
            UIViewController vc = ViewControllerForPreview(controller);

            if (vc == null)
            {
                return(null);
            }
            return(vc.View);
        }
Exemplo n.º 31
0
        public void OpenFile(NSUrl fileUrl)
        {
            var docControl = UIDocumentInteractionController.FromUrl(fileUrl);

            var window   = UIApplication.SharedApplication.KeyWindow;
            var subViews = window.Subviews;
            var lastView = subViews.Last();
            var frame    = lastView.Frame;

            docControl.PresentOpenInMenu(frame, lastView, true);
        }
Exemplo n.º 32
0
        public bool OpenFile(byte[] fileData, string id, string fileName)
        {
            var filePath = Path.Combine(GetTempPath(), fileName);

            File.WriteAllBytes(filePath, fileData);
            var url        = NSUrl.FromFilename(filePath);
            var viewer     = UIDocumentInteractionController.FromUrl(url);
            var controller = GetVisibleViewController();

            return(viewer.PresentOpenInMenu(controller.View.Frame, controller.View, true));
        }
Exemplo n.º 33
0
        public override void ViewDidUnload()
        {
            base.ViewDidUnload();

            this.SaveButton  = null;
            this.LoadButton  = null;
            this.RotateLeft  = null;
            this.RotateRight = null;
            this.ImageView   = null;
            this.dic         = null;
        }
Exemplo n.º 34
0
        private static async void OnOpenSampleFile(string path)
        {
#if WINDOWS_UWP
            var file = await StorageFile.GetFileFromPathAsync(path);

            await Launcher.LaunchFileAsync(file);
#elif __MACOS__
            if (!NSWorkspace.SharedWorkspace.OpenFile(path))
            {
                var alert = new NSAlert();
                alert.AddButton("OK");
                alert.MessageText     = "SkiaSharp";
                alert.InformativeText = "Unable to open file.";
                alert.RunSheetModal(NSApplication.SharedApplication.MainWindow);
            }
#elif __TVOS__
#elif __IOS__
            // the external / shared location
            var external = Path.Combine(Path.GetTempPath(), "SkiaSharpSample");
            if (!Directory.Exists(external))
            {
                Directory.CreateDirectory(external);
            }
            // copy file to external
            var newPath = Path.Combine(external, Path.GetFileName(path));
            File.Copy(path, newPath);
            // open the file
            var vc             = Xamarin.Forms.Platform.iOS.Platform.GetRenderer(Xamarin.Forms.Application.Current.MainPage) as UIViewController;
            var resourceToOpen = NSUrl.FromFilename(newPath);
            var controller     = UIDocumentInteractionController.FromUrl(resourceToOpen);
            if (!controller.PresentOpenInMenu(vc.View.Bounds, vc.View, true))
            {
                new UIAlertView("SkiaSharp", "Unable to open file.", (IUIAlertViewDelegate)null, "OK").Show();
            }
#elif __ANDROID__
            // the external / shared location
            var external = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "SkiaSharpSample");
            if (!Directory.Exists(external))
            {
                Directory.CreateDirectory(external);
            }
            // copy file to external
            var newPath = Path.Combine(external, Path.GetFileName(path));
            File.Copy(path, newPath);
            // open the file
            var uri    = Android.Net.Uri.FromFile(new Java.IO.File(newPath));
            var intent = new Intent(Intent.ActionView, uri);
            intent.AddFlags(ActivityFlags.NewTask);
            Application.Context.StartActivity(intent);
#elif __DESKTOP__
            Process.Start(path);
#endif
        }
Exemplo n.º 35
0
        private void PresentOpenIn(UIBarButtonItem barButtonItem)
        {
            if (ContentSavePath == null)
            {
                return;
            }

            var ctrl = new UIDocumentInteractionController();

            ctrl.Url = NSUrl.FromFilename(ContentSavePath);
            ctrl.PresentOpenInMenu(barButtonItem, true);
        }
Exemplo n.º 36
0
        public void OpenActionSheet(string path)
        {
            var window   = UIApplication.SharedApplication.KeyWindow;
            var subviews = window.Subviews;
            var view     = subviews.Last();

            NSUrl videoUrl = NSUrl.CreateFileUrl(path, null);
            UIDocumentInteractionController openInWindow = UIDocumentInteractionController.FromUrl(videoUrl);

            openInWindow.PresentOptionsMenu(CGRect.Empty, view, true);
            //openInWindow.PresentOpenInMenu(CGRect.Empty, view, true);
        }
Exemplo n.º 37
0
		public FilePresenter ()
		{
			this.documentInteractionController = new UIDocumentInteractionController ();
			this.documentInteractionController.Delegate = this;
		}
Exemplo n.º 38
0
        /// <summary>
        /// Open Instagram with the specified image and caption.
        /// </summary>
        /// <returns><c>true</c> if Instagram is installed, <c>false</c> otherwise.</returns>
        /// <param name="image">Image.</param>
        /// <param name="caption">Caption.</param>
        public static bool Instagram(UIImage image, string caption = null)
        {
            if (!UIApplication.SharedApplication().CanOpenURL(new NSURL("instagram://app")))
                return false;

            // write image to tmp folder
            NSData data = image.JPEGRepresentation(1f);
            string filePath = Application.temporaryCachePath + "/" + UUID.Generate() + ".igo";
            data.WriteToFile(filePath, true);

            _documentIC = UIDocumentInteractionController.InteractionController(new NSURL(filePath, false));
            _documentIC.UTI = "com.instagram.exclusivegram";
            if (caption != null) {
                var annotation = new Dictionary<object, object>();
                annotation["InstagramCaption"] = caption;
                _documentIC.annotation = annotation;
            }

            var rootView = UIApplication.deviceRootViewController.view;
            _documentIC.PresentOpenInMenu(new Rect(0, 0, 1, 1), rootView, true);
            return true;
        }
Exemplo n.º 39
0
 private static UIViewController ViewControllerForPreview(UIDocumentInteractionController c)
 {
     return UIApplication.SharedApplication.KeyWindow.RootViewController;
 }
Exemplo n.º 40
0
        private void OpenFile(string filePath, DataItem item)
        {
            var sbounds = UIScreen.MainScreen.Bounds;
            string ext = UrlHelper.GetExtension(filePath);

            if (ext.ToUpper () == ".MOV" || ext.ToUpper () == ".M4V") {
                var movieController = new AdvancedUIViewController ();
                moviePlayer = new MPMoviePlayerController (NSUrl.FromFilename (filePath));
                moviePlayer.View.Frame = new RectangleF (
                    sbounds.X,
                    sbounds.Y - 20,
                    sbounds.Width,
                    sbounds.Height - 30
                    );
                moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen;
                moviePlayer.View.AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight);
                moviePlayer.ShouldAutoplay = true;
                moviePlayer.PrepareToPlay ();
                moviePlayer.Play ();

                var btnClose = UIButton.FromType (UIButtonType.RoundedRect);
                btnClose.Frame = new RectangleF (3, 7, 60, 30);
                btnClose.SetTitle ("Close", UIControlState.Normal);
                btnClose.SetTitleColor (UIColor.Black, UIControlState.Normal);
                btnClose.TouchDown += delegate {
                    movieController.DismissModalViewControllerAnimated (true);
                };

                var btnShare = UIButton.FromType (UIButtonType.RoundedRect);
                btnShare.Frame = new RectangleF (
                    (sbounds.Width / 2) - 50,
                    sbounds.Height - 50,
                    100,
                    30
                    );
                btnShare.SetTitle ("Share", UIControlState.Normal);
                btnShare.SetTitleColor (UIColor.Black, UIControlState.Normal);
                btnShare.TouchDown += delegate {
                    ResharedItem = item;
                    ResharedItemType = FileType.Video;
                    ShowSecretsView();
                };

                movieController.View.AddSubview (moviePlayer.View);
                movieController.View.AddSubview (btnClose);
                movieController.View.AddSubview (btnShare);
                navigation.PresentModalViewController (movieController, true);
            }  else if (ext.ToUpper () == ".JPEG" || ext.ToUpper () == ".JPG" || ext.ToUpper () == ".PNG") {
                ALAssetsLibrary library = new ALAssetsLibrary ();
                library.AssetForUrl (new NSUrl (filePath),
                  (asset) => {
                    if (asset != null) {
                        var imageController = new AdvancedUIViewController ();
                        var image = UIImage.FromImage (asset.DefaultRepresentation.GetFullScreenImage ());
                        var imageView = new UIImageView (image);
                        imageView.Frame = sbounds;
                        imageView.UserInteractionEnabled = true;
                        imageView.ClipsToBounds = true;
                        imageView.ContentMode = UIViewContentMode.ScaleAspectFit;

                        var btnClose = UIButton.FromType (UIButtonType.RoundedRect);
                        btnClose.Frame = new RectangleF (
                            (sbounds.Width / 2) - 50,
                            20,
                            100,
                            30
                            );
                        btnClose.SetTitle ("Close", UIControlState.Normal);
                        btnClose.SetTitleColor (UIColor.Black, UIControlState.Normal);
                        btnClose.TouchDown += delegate {
                            imageController.DismissModalViewControllerAnimated (true);
                        };

                        var btnShare = UIButton.FromType (UIButtonType.RoundedRect);
                        btnShare.Frame = new RectangleF (
                            (sbounds.Width / 2) - 50,
                            sbounds.Height - 60,
                            100,
                            30
                            );
                        btnShare.SetTitle ("Share", UIControlState.Normal);
                        btnShare.SetTitleColor (UIColor.Black, UIControlState.Normal);
                        btnShare.TouchDown += delegate {
                            ResharedItem = item;
                            ResharedItemType = FileType.Photo;
                            ShowSecretsView();
                        };

                        var scrollView = new UIScrollView (sbounds);
                        scrollView.ClipsToBounds = true;
                        scrollView.ContentSize = sbounds.Size;
                        scrollView.BackgroundColor = UIColor.Gray;
                        scrollView.MinimumZoomScale = 1.0f;
                        scrollView.MaximumZoomScale = 3.0f;
                        scrollView.MultipleTouchEnabled = true;
                        scrollView.AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight);
                        scrollView.ViewForZoomingInScrollView = delegate(UIScrollView sv) {
                            return imageView;
                        };

                        scrollView.AddSubview (imageView);
                        imageController.View.AddSubview (scrollView);
                        imageController.View.AddSubview (btnClose);
                        imageController.View.AddSubview (btnShare);
                        navigation.PresentModalViewController (imageController, true);
                    } else {
                        Console.Out.WriteLine ("Asset is null.");
                    }
                },
                (error) => {
                    if (error != null) {
                        Console.Out.WriteLine ("Error: " + error.LocalizedDescription);
                    }
                }
                );
            }  else {
                var btnShare = UIButton.FromType (UIButtonType.RoundedRect);
                btnShare.Frame = new RectangleF (
                    (sbounds.Width / 2) - 50,
                    sbounds.Height - 50,
                    100,
                    30
                    );
                btnShare.SetTitle ("Share", UIControlState.Normal);
                btnShare.SetTitleColor (UIColor.Black, UIControlState.Normal);
                btnShare.Tag = SHARE_BUTTON_TAG;
                btnShare.TouchDown += delegate {
                    ResharedItem = item;
                    ResharedItemType = FileType.Other;
                    ShowSecretsView();
                };

                navigation.Add(btnShare);
                interactionControllerDelegate = new  UIDocumentInteractionControllerDelegateClass(navigation);
                interactionController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
                interactionController.Delegate = interactionControllerDelegate;
                InvokeOnMainThread(delegate {
                    interactionController.PresentPreview(true);
                });
            }
        }
 public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
 {
     return this.controller;
 }
Exemplo n.º 42
0
		public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
		{
			UIViewController value;
			owner.TryGetTarget(out value);
			return value;
		}
Exemplo n.º 43
0
		public override void WillBeginPreview (UIDocumentInteractionController controller)
		{
			ReadyToPresent (controller, EventArgs.Empty);
		}
Exemplo n.º 44
0
		public override void DidEndPreview (UIDocumentInteractionController controller)
		{
			Done (controller, EventArgs.Empty);
		}
Exemplo n.º 45
0
		protected override void Dispose (bool disposing)
		{
			base.Dispose (disposing);
			documentInteractionController.Dispose ();
			documentInteractionController = null;
		}
Exemplo n.º 46
0
 public override RectangleF RectangleForPreview(UIDocumentInteractionController controller)
 {
     return viewC.View.Frame;
 }
Exemplo n.º 47
0
 public override UIView ViewForPreview(UIDocumentInteractionController controller)
 {
     return viewC.View;
 }
			public TableSource (DocumentViewModel documentViewModel)
			{
				this.documentViewModel = documentViewModel;
				documentController = new UIDocumentInteractionController();
			}