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);
            }
        }
Exemplo n.º 2
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.º 3
0
    public void open(string filepath)
    {
        var previewController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filepath));

        previewController.Delegate = new FileInteractionDelegate(GetVisibleViewController());
        previewController.PresentPreview(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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
0
        /// <summary>
        /// iOS implementation of opening a file by using a UIDocumentInteractionController.
        /// </summary>
        /// <param name="fileUrl">file Url to open in viewer</param>
        public void OpenFile(NSUrl fileUrl)
        {
            UIDocumentInteractionController docController = UIDocumentInteractionController.FromUrl(fileUrl);

            UIWindow window = UIApplication.SharedApplication.KeyWindow;

            UIView[] subViews = window.Subviews;
            UIView   lastView = subViews.Last();

            CoreGraphics.CGRect frame = lastView.Frame;
            _ = docController.PresentOpenInMenu(frame, lastView, true);
        }
Exemplo n.º 18
0
 private void Completed(object sender, AsyncCompletedEventArgs e)
 {
     if (e.Error != null)
     {
     }
     else
     {
         var previewController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(pathToNewFile));
         previewController.Delegate = new MyInteractionDelegate(UIApplication.SharedApplication.KeyWindow.RootViewController);
         previewController.PresentPreview(true);
     }
 }
Exemplo n.º 19
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.º 20
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();
            var rect       = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ?
                             new CGRect(100, 5, 320, 320) : controller.View.Frame;

            return(viewer.PresentOpenInMenu(rect, controller.View, true));
        }
Exemplo n.º 21
0
 public void openDocumentFromUrl(NSUrl fileUrl, UIView view)
 {
     if (fileUrl != null && view != null)
     {
         CGRect frame = new CGRect(0, 0, 0, 0);
         uIDocumentInteractionController = UIDocumentInteractionController.FromUrl(fileUrl);
         uIDocumentInteractionController.PresentOpenInMenu(frame, view, true);
     }
     else
     {
         Console.WriteLine("AWXamarin file opening URL or View is null");
     }
 }
Exemplo n.º 22
0
        static Task PlatformOpenAsync(OpenFileRequest request)
        {
            var fileUrl = NSUrl.FromFilename(request.File.FullPath);

            var documentController = UIDocumentInteractionController.FromUrl(fileUrl);

            documentController.Uti = request.File.ContentType;

            var vc = Platform.GetCurrentViewController();

            documentController.PresentOpenInMenu(vc.View.Frame, vc.View, true);
            return(Task.CompletedTask);
        }
Exemplo n.º 23
0
        public void Open(string fileName)
        {
            var documents         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var path              = Path.Combine(documents, fileName);
            var previewController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(path));

            previewController.Delegate = new MyInteractionDelegate(UIApplication.SharedApplication.KeyWindow.RootViewController);

            Device.BeginInvokeOnMainThread(() =>
            {
                previewController.PresentPreview(true);
            });
        }
Exemplo n.º 24
0
        partial void OpenSelectedDoc_TouchUpInside(UIButton sender)
        {
            if (string.IsNullOrEmpty(DocPath.Text) || Equals(DocPath.Text, "Document path"))
            {
                return;
            }
            var url        = NSUrl.FromString(DocPath.Text);
            var docPreview = UIDocumentInteractionController.FromUrl(url);

            docPreview.Name = DocName.Text;
            docPreview.ViewControllerForPreview = (controller) => this;
            docPreview.PresentPreview(true);
        }
Exemplo n.º 25
0
        public bool Open(IFile file)
        {
            var opened = false;

            using (var url = NSUrl.FromFilename(file.FullName)) {
                using (var controller = UIDocumentInteractionController.FromUrl(url)) {
                    UIApplication.SharedApplication.InvokeOnMainThread(() => {
                        controller.Delegate = new FileViewerInterationDelegate();
                        opened = controller.PresentPreview(true);
                    });
                }
            }
            return(opened);
        }
Exemplo n.º 26
0
        public override async void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            DocViewService service = new DocViewService(AppDelegate.DatabaseContext);

            this.InvokeOnMainThread(delegate {
                LoadOverLayPopup();
            });

            Model.Document doc = await Task.Run(() => service.GetDocument(documentsList [indexPath.Row].ID, token));

            if (doc != null)
            {
                if (doc.documentArray == null)
                {
                    UIAlertView alert = new UIAlertView(@"Alert", @"The document is not available", null, NSBundle.MainBundle.LocalizedString("OK", "OK"));
                    alert.Show();
                }
                string documentPath = string.Empty;
                if (string.IsNullOrEmpty(doc.DocumentPath))
                {
                    documentPath     = this.GenerateReport(doc);
                    doc.DocumentPath = documentPath;
                    service.UpdateDocumentItems(doc);
                }
                else
                {
                    documentPath = doc.DocumentPath;
                }



                if (File.Exists(documentPath))
                {
                    var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(documentPath));
                    UIDocumentInteractionControllerDelegateDerived del = new UIDocumentInteractionControllerDelegateDerived(this);
                    //del.doneWithPreview+=(informer, eventArgs)=>{btnFinalizeSave.Hidden = false;
                    //	btnEdit.Hidden = false;};
                    viewer.Delegate = del;
                    viewer.PresentPreview(true);
                }
                this.InvokeOnMainThread(delegate {
                    HideOverLay();
                });
            }
            else
            {
                UIAlertView alert = new UIAlertView(@"Alert", @"Entire pdf not available", null, NSBundle.MainBundle.LocalizedString("OK", "OK"));
                alert.Show();
            }
        }
Exemplo n.º 27
0
 public void Share(string filePath)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(() =>
     {
         _controller      = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
         _controller.Name = Path.GetFileName(filePath);
         var window       = UIApplication.SharedApplication.KeyWindow;
         var subviews     = window.Subviews;
         var view         = subviews.Last();
         var frame        = view.Frame;
         frame            = new CGRect((float)Math.Min(10, frame.Width), (float)frame.Bottom, 0, 0);
         _controller.PresentOptionsMenu(frame, view, true);
     });
 }
Exemplo n.º 28
0
        public GistFileView(INetworkActivityService networkActivityService)
            : base(networkActivityService)
        {
            this.WhenViewModel(x => x.GistFile).IsNotNull().Subscribe(x =>
                                                                      NavigationItem.RightBarButtonItem = ViewModel.ShowMenuCommand.ToBarButtonItem(UIBarButtonSystemItem.Action));

            this.WhenViewModel(x => x.OpenWithCommand)
            .Switch()
            .Subscribe(_ =>
            {
                UIDocumentInteractionController ctrl = UIDocumentInteractionController.FromUrl(new NSUrl(ViewModel.SourceItem.FileUri.AbsoluteUri));
                ctrl.Delegate = new UIDocumentInteractionControllerDelegate();
                ctrl.PresentOpenInMenu(this.View.Frame, this.View, true);
            });
        }
Exemplo n.º 29
0
        private static Task <bool> LaunchFileAsyncImpl(IStorageFile file)
        {
            return(Task.Run <bool>(() =>
            {
                bool success = false;
                UIApplication.SharedApplication.InvokeOnMainThread(() =>
                {
                    UIDocumentInteractionController c = UIDocumentInteractionController.FromUrl(global::Foundation.NSUrl.FromFilename(file.Path));
                    c.ViewControllerForPreview = ViewControllerForPreview;
                    success = c.PresentPreview(true);
                });

                return success;
            }));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Shows the file from local.
        /// </summary>
        /// <param name="filepath">Filepath.</param>
        public void ShowFileFromLocal(string filepath)
        {
            NSUrl url = NSUrl.FromFilename(filepath);

            var topController = GetVisibleViewController();

            while (topController.PresentedViewController != null)
            {
                topController = topController.PresentedViewController;
            }

            var viewer = UIDocumentInteractionController.FromUrl(url);

            viewer.PresentOpenInMenu(new RectangleF(0, -260, 320, 320), topController.View, true);
        }