コード例 #1
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);
        }
コード例 #2
0
ファイル: FileSourceView.cs プロジェクト: nghialv/CodeHub
		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);
		}
コード例 #3
0
ファイル: Launcher.ios.tvos.cs プロジェクト: sung-su/maui
        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));
        }
コード例 #4
0
        public void OpenIn(object sender, string file)
        {
            var ctrl = new UIDocumentInteractionController();

            ctrl.Url = NSUrl.FromFilename(file);
            ctrl.PresentOpenInMenu(sender as UIBarButtonItem, true);
        }
コード例 #5
0
ファイル: FileSourceView.cs プロジェクト: vbassini/CodeBucket
		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);
		}
コード例 #6
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);
            }
        }
コード例 #7
0
ファイル: FileSourceView.cs プロジェクト: zhiyuanjia/CodeHub
        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);
        }
コード例 #8
0
ファイル: FileSourceView.cs プロジェクト: GitWatcher/CodeHub
        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);
        }
コード例 #9
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);
		}
コード例 #10
0
ファイル: SocialXT.cs プロジェクト: zhengyudian/u3dxt
        /// <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);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
0
        private void PresentOpenIn(UIBarButtonItem barButtonItem)
        {
            if (ContentSavePath == null)
            {
                return;
            }

            var ctrl = new UIDocumentInteractionController();

            ctrl.Url = NSUrl.FromFilename(ContentSavePath);
            ctrl.PresentOpenInMenu(barButtonItem, true);
        }
コード例 #14
0
        public void OpenFile(NSUrl fileUrl)
        {
            UIDocumentInteractionController docControl = UIDocumentInteractionController.FromUrl(fileUrl);

            UIWindow window = UIApplication.SharedApplication.KeyWindow;

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

            docControl.PresentOpenInMenu(frame, lastView, true);
        }
コード例 #15
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");
     }
 }
コード例 #16
0
ファイル: GistFileView.cs プロジェクト: hnney/CodeHub
        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);
            });
        }
コード例 #17
0
        protected FileSourceView(IAlertDialogFactory alertDialogFactory)
        {
            _alertDialogFactory = alertDialogFactory;

            this.WhenViewModel(x => x.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            this.WhenViewModel(x => x.OpenWithCommand)
            .Switch()
            .Subscribe(_ =>
            {
                UIDocumentInteractionController ctrl = UIDocumentInteractionController.FromUrl(new NSUrl(ViewModel.SourceItem.FileUri.AbsoluteUri));
                ctrl.Delegate = new UIDocumentInteractionControllerDelegate();
                var couldOpen = ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
                if (!couldOpen)
                {
                    alertDialogFactory.ShowError("Nothing to open with");
                }
            });
        }
コード例 #18
0
        void SendToInstagram(UIImage image)
        {
            NSUrl instagramURL = new NSUrl("instagram://");

            if (UIApplication.SharedApplication.CanOpenUrl(instagramURL))
            {
                UIImage  imageToUse        = PhotoService.Rotate(image, image.Orientation);
                NSString documentDirectory = (new NSString(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
                string   saveImagePath     = documentDirectory.AppendPathComponent(new NSString(@"Image.ig"));
                NSData   imageData         = PhotoService.ResizeImage(imageToUse).AsPNG();
                imageData.Save(saveImagePath, true);
                NSUrl imageURL = NSUrl.FromFilename(saveImagePath);

                DocumentController            = new UIDocumentInteractionController();
                DocumentController.Url        = imageURL;
                DocumentController.Delegate   = new DocumentInteractionControllerDelegate(this);
                DocumentController.Uti        = "com.instagram.photo";
                DocumentController.Annotation = new NSMutableDictionary <NSString, NSString> {
                    { new NSString("InstagramCaption"), new NSString(Challenge.InstaCaption ?? "") }
                };
                DocumentController.PresentOpenInMenu(new RectangleF(1, 1, 1, 1), View, true);
            }
        }
コード例 #19
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.WhenViewModel(x => x.GistFile).Select(x => x != null).Subscribe(isValid =>
            {
                if (isValid)
                {
                    NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => CreateActionSheet());
                    NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.WhenAnyValue(x => x.SourceItem).Select(x => x != null));
                }
                else
                {
                    NavigationItem.RightBarButtonItem = null;
                }
            });

            ViewModel.OpenWithCommand.Subscribe(x =>
            {
                UIDocumentInteractionController ctrl = UIDocumentInteractionController.FromUrl(new NSUrl(ViewModel.SourceItem.FileUri.AbsoluteUri));
                ctrl.Delegate = new UIDocumentInteractionControllerDelegate();
                ctrl.PresentOpenInMenu(this.View.Frame, this.View, true);
            });
        }
コード例 #20
0
        private void ShowExtraMenu()
        {
            var sheet       = new UIActionSheet();
            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.Dispose();
            };

            sheet.ShowFrom(NavigationItem.RightBarButtonItem, true);
        }
コード例 #21
0
ファイル: FileSourceView.cs プロジェクト: zhongyin/CodeHub
        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
                {
                }
            };

            sheet.ShowInView(this.View);
        }
コード例 #22
0
ファイル: FileSourceView.cs プロジェクト: wyrover/CodeBucket
        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);
        }
コード例 #23
0
        private void ShowExtraMenu()
        {
            var sheet = MonoTouch.Utilities.GetSheet(Title);

            var openButton = _downloadResult != null?sheet.AddButton("Open In".t()) : -1;

            var shareButton = sheet.AddButton("Share".t());
            var showButton  = _githubUrl != 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) => {
                if (e.ButtonIndex == openButton)
                {
                    var ctrl = new UIDocumentInteractionController();
                    ctrl.Url = NSUrl.FromFilename(_downloadResult.File);
                    ctrl.PresentOpenInMenu(NavigationItem.RightBarButtonItem, true);
                }
                else if (e.ButtonIndex == shareButton)
                {
                    var          item                  = UIActivity.FromObject(_githubUrl);
                    var          activityItems         = new NSObject[] { item };
                    UIActivity[] applicationActivities = null;
                    var          activityController    = new UIActivityViewController(activityItems, applicationActivities);
                    PresentViewController(activityController, true, null);
                }
                else if (e.ButtonIndex == showButton)
                {
                    try { UIApplication.SharedApplication.OpenUrl(new NSUrl(_githubUrl)); } catch { }
                }
            };

            sheet.ShowInView(this.View);
        }
コード例 #24
0
ファイル: SocialXT.cs プロジェクト: BiDuc/u3dxt
        /// <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;
        }
コード例 #25
0
        partial void SaveAction(UIBarButtonItem sender)
        {
            if (this.outImage == null)
            {
                return;
            }

            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

            PxImageWriter_Type img_writer_type = PxImageWriter_Type.Jpeg;

            string file_ext = "jpg";

            string uti = "public.jpeg";

            uint save_format = (uint)defaults.IntForKey("selectedSaveFormat");

            switch (save_format)
            {
            case 0:
            {
                img_writer_type = PxImageWriter_Type.Pdf;
                file_ext        = "pdf";
                uti             = "com.adobe.pdf";
                break;
            }

            case 1:
            {
                img_writer_type = PxImageWriter_Type.PngExt;
                file_ext        = "pdf";
                uti             = "com.adobe.pdf";
                break;
            }

            case 2:
            {
                img_writer_type = PxImageWriter_Type.Tiff;
                file_ext        = "tiff";
                uti             = "public.tiff";
                break;
            }

            case 3:
            {
                img_writer_type = PxImageWriter_Type.PngExt;
                file_ext        = "png";
                uti             = "public.png";
                break;
            }

                //case 4:
                //    {
                //        img_writer_type = PxImageWriter_Type.Jpeg;
                //        break;
                //    }
            }

            PxImageWriter img_writer = PxImageWriter.CreateWithType(img_writer_type);

            string file_name = "image." + file_ext;

            string dir_path = System.IO.Path.GetTempPath();

            string file_local_path = dir_path + file_name;

            string file_local_path2 = file_local_path;

            if (save_format == 1)
            {
                // PDF from PNG => build PNG file first
                file_local_path2 = file_local_path + ".png";
            }

            if (!img_writer.Open(file_local_path2))
            {
                SysUtils.ShowAlert(this, "Error", "failed to start sequence '{0}'!", file_local_path2);
                return;
            }

            bool simulate_multi_page_file = defaults.BoolForKey("simulateMultipageFile");

            if (save_format > 2)
            {
                simulate_multi_page_file = false;
            }

            int c = 1;

            if (simulate_multi_page_file && save_format != 1)
            {
                c += 2;
            }

            string s;

            // Pick original orientation
            PxMetaImage_Orientation original_orientation = this.outImage.Orientation;

            if (save_format == 1)
            {
                this.outImage.Orientation = PxMetaImage_Orientation.Normal;
            }

            try {
                do
                {
                    if ((s = img_writer.Write(this.outImage)) == null)
                    {
                        SysUtils.ShowAlert(this, "Error", "failed to write '{0}'!", file_local_path2);
                        break;
                    }
                } while(--c > 0);
            } catch (MonoTouchException) {
                // License error
                s = null;
            }

            img_writer.Close();

            if (s == null)
            {
                return;
            }

            if (save_format == 1)
            {
                this.outImage.Orientation = original_orientation;

                img_writer = PxImageWriter.CreateWithType(PxImageWriter_Type.Pdf);

                if (!img_writer.Open(file_local_path))
                {
                    SysUtils.ShowAlert(this, "Error", "failed to start sequence '{0}'!", file_local_path);
                    return;
                }

                c = 1;
                if (simulate_multi_page_file)
                {
                    c += 2;
                }

                try {
                    do
                    {
                        if ((s = img_writer.WriteFile(file_local_path2, PxImageWriter_FileType.Png, original_orientation)) == null)
                        {
                            SysUtils.ShowAlert(this, "Error", "failed to write '{0}'!", file_local_path);
                            break;
                        }
                    } while(--c > 0);
                } catch (MonoTouchException) {
                    // License error
                    s = null;
                }

                img_writer.Close();

                if (s == null)
                {
                    return;
                }
            }

            NSUrl file_url = new NSUrl(file_local_path, false);

            dic     = UIDocumentInteractionController.FromUrl(file_url);
            dic.Uti = uti;

            if (!dic.PresentOpenInMenu(CGRect.Empty, this.View, true))
            {
                SysUtils.ShowAlert(this, "Error", "failure opening the file sharing dialog");
                return;
            }

            //self.saveButton.enabled = false;
        }