public void Show() { var alert = UIAlertController.Create(Title, Message, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create(TouchFactory.Instance.GetResourceString(Buttons == AlertButtons.YesNo ? "Yes" : "OK"), UIAlertActionStyle.Default, (o) => { var handler = Dismissed; if (handler != null) { handler(this, new AlertResultEventArgs(Buttons == AlertButtons.YesNo ? AlertResult.Yes : AlertResult.OK)); } else { iApp.Navigate(OKLink); } })); if (Buttons != AlertButtons.OK) { alert.AddAction(UIAlertAction.Create(TouchFactory.Instance.GetResourceString(Buttons == AlertButtons.YesNo ? "No" : "Cancel"), UIAlertActionStyle.Cancel, (o) => { var handler = Dismissed; if (handler != null) { handler(this, new AlertResultEventArgs(Buttons == AlertButtons.YesNo ? AlertResult.No : AlertResult.Cancel)); } else { iApp.Navigate(CancelLink); } })); } ModalManager.EnqueueModalTransition(ModalManager.GetTopmostViewController(null), alert, true); }
public static void Print(string url) { if (!UIPrintInteractionController.PrintingAvailable) { new UIAlertView(TouchFactory.Instance.GetResourceString("PrintErrorTitle"), TouchFactory.Instance.GetResourceString("PrintError"), null, TouchFactory.Instance.GetResourceString("Dismiss"), null).Show(); return; } string printUrl = null; int index = url.IndexOf('?'); if (index >= 0) { HttpUtility.ParseQueryString(url.Substring(index)).TryGetValue("url", out printUrl); } UIPrintInfo printInfo = UIPrintInfo.PrintInfo; printInfo.OutputType = UIPrintInfoOutputType.General; printInfo.Duplex = UIPrintInfoDuplex.LongEdge; if (!string.IsNullOrEmpty(printUrl) && !PrintUrl(printUrl)) { new UIAlertView(TouchFactory.Instance.GetResourceString("PrintErrorTitle"), string.Format(TouchFactory.Instance.GetResourceString("PrintUrlError"), printUrl), null, TouchFactory.Instance.GetResourceString("Dismiss"), null).Show(); return; } var navContext = iApp.CurrentNavContext.ActiveLayer.NavContext; var stack = PaneManager.Instance.FromNavContext(navContext.NavigatedActivePane, navContext.NavigatedActiveTab) as BaseNavigationController; if (stack == null || stack.CurrentView == null) { return; } UIViewController controller = TouchFactory.GetNativeObject <UIViewController>(stack.CurrentView, "view"); UIView view = controller.View; if (controller is IBrowserView) { view = view.Subviews.FirstOrDefault(sv => sv is UIWebView); } if (!(view is UIWebView) || !PrintUrl(((UIWebView)view).Request.Url.AbsoluteString)) { printInfo.JobName = controller.NavigationItem.Title; UIPrintInteractionController.SharedPrintController.PrintInfo = printInfo; view.ViewPrintFormatter.StartPage = 0; UIPrintInteractionController.SharedPrintController.PrintFormatter = view.ViewPrintFormatter; } UIPrintInteractionCompletionHandler completionHandler = FinishPrinting; if (TouchFactory.Instance.LargeFormFactor) { UIViewController top = ModalManager.GetTopmostViewController(null); nfloat barHeight = TouchFactory.Instance.IsLandscape ? UIApplication.SharedApplication.StatusBarFrame.Width : UIApplication.SharedApplication.StatusBarFrame.Height; nfloat centerX = TouchFactory.Instance.IsLandscape ? top.View.Center.Y : top.View.Center.X; UIPrintInteractionController.SharedPrintController.PresentFromRectInView( new CoreGraphics.CGRect(centerX, stack.NavigationBar.Frame.Height + barHeight, 1, 1), top.View, true, completionHandler); } else { UIPrintInteractionController.SharedPrintController.Present(true, completionHandler); } }
public static void GetMedia(string url) { bool cameraEnabled = true; bool galleryEnabled = true; var parameters = HttpUtility.ParseQueryString(url.Substring(url.IndexOf('?'))); if (parameters != null) { if (parameters.ContainsKey(CallbackUri)) { callback = parameters[CallbackUri]; } else { throw new ArgumentException("Image capture requires a callback URI."); } if (parameters.ContainsKey(Camera)) { bool.TryParse(parameters[Camera], out cameraEnabled); } if (parameters.ContainsKey(Gallery)) { bool.TryParse(parameters[Gallery], out galleryEnabled); } } if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { // this must be set to camera before capture mode can be set picker.SourceType = UIImagePickerControllerSourceType.Camera; } else { cameraEnabled = false; } if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)) { galleryEnabled = false; } picker.Delegate = new ImagePickerDelegate(); string[] buttons = null; if (url.StartsWith("videorecording")) { buttons = new string[] { TouchFactory.Instance.GetResourceString("RecordVideo"), TouchFactory.Instance.GetResourceString("ChooseVideo"), }; picker.MediaTypes = new string[] { MobileCoreServices.UTType.Movie }; if (cameraEnabled) { picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; } } else { buttons = new string[] { TouchFactory.Instance.GetResourceString("TakePhoto"), TouchFactory.Instance.GetResourceString("ChoosePhoto"), }; picker.MediaTypes = new string[] { MobileCoreServices.UTType.Image }; if (cameraEnabled) { picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } } if (cameraEnabled) { if (galleryEnabled) { var alert = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet); if (alert == null) { var actionSheet = new UIActionSheet(string.Empty) { buttons[0], buttons[1], TouchFactory.Instance.GetResourceString("Cancel"), }; actionSheet.CancelButtonIndex = actionSheet.ButtonCount - 1; actionSheet.Style = UIActionSheetStyle.BlackTranslucent; actionSheet.ShowInView(TouchFactory.Instance.TopViewController.View); actionSheet.Clicked += delegate(object sender, UIButtonEventArgs args) { switch (args.ButtonIndex) { case 0: StartCamera(); break; case 1: StartGallery(); break; } }; } else { if (alert.PopoverPresentationController != null) { alert.PopoverPresentationController.PermittedArrowDirections = 0; alert.PopoverPresentationController.SourceView = TouchFactory.Instance.TopViewController.View; alert.PopoverPresentationController.SourceRect = new CGRect(TouchFactory.Instance.TopViewController.View.Center, CGSize.Empty); } alert.AddAction(UIAlertAction.Create(buttons[0], UIAlertActionStyle.Default, (o) => StartCamera())); alert.AddAction(UIAlertAction.Create(buttons[1], UIAlertActionStyle.Default, (o) => StartGallery())); alert.AddAction(UIAlertAction.Create(TouchFactory.Instance.GetResourceString("Cancel"), UIAlertActionStyle.Cancel, null)); ModalManager.EnqueueModalTransition(ModalManager.GetTopmostViewController(null), alert, true); } } else { StartCamera(); } } else if (galleryEnabled) { StartGallery(); } }
public static void SetMenu(this UIViewController controller, IMenu menu) { if (menu != null && menu.ButtonCount > 0) { if (menu.ButtonCount > 1) { bool isNew = false; if (menu.ImagePath != null) { try { controller.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIImage.FromBundle(menu.ImagePath), UIBarButtonItemStyle.Plain, null); isNew = true; } catch { } } else if (!string.IsNullOrEmpty(menu.Title)) { controller.NavigationItem.RightBarButtonItem = new UIBarButtonItem(menu.Title, UIBarButtonItemStyle.Plain, null); isNew = true; } if (controller.NavigationItem.RightBarButtonItem == null) { controller.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action); isNew = true; } if (isNew) { controller.NavigationItem.RightBarButtonItem.Clicked += (o, e) => { var alert = (menu as UIAlertController) ?? (menu.Pair as UIAlertController); if (alert != null) { if (alert.PopoverPresentationController != null) { alert.PopoverPresentationController.BarButtonItem = controller.NavigationItem.RightBarButtonItem; } ModalManager.EnqueueModalTransition(ModalManager.GetTopmostViewController(null), alert, true); } else { var action = (menu as UIActionSheet) ?? (menu.Pair as UIActionSheet); if (action != null) { action.ShowFrom(controller.NavigationItem.RightBarButtonItem, true); } } }; } var sheet = (menu as UIActionSheet) ?? (menu.Pair as UIActionSheet); if (sheet != null) { if (sheet.CancelButtonIndex <= 0) { sheet.Add(TouchFactory.Instance.GetResourceString("Cancel")); sheet.CancelButtonIndex = sheet.ButtonCount - 1; } } } else { controller.NavigationItem.RightBarButtonItem = TouchFactory.GetNativeObject <UIBarButtonItem>(menu.GetButton(0), "menuButton"); } } else { controller.NavigationItem.RightBarButtonItem = null; } }