コード例 #1
0
ファイル: Launcher.iOS.cs プロジェクト: baskren/Pontoon
        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;
            }));
        }
コード例 #2
0
ファイル: AppDelegate.cs プロジェクト: bshehera/cross-copy
        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);
                });
            }
        }
コード例 #3
0
ファイル: AppDelegate.cs プロジェクト: bshehera/cross-copy
        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);
                });
            }
        }