public static void Scan(CameraScanLayer scanLayer) { var callback = scanLayer.Callback; var ctrl = new CameraScanController(scanLayer, callback, ScanLayer.BarcodeKey) { ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal }; var navCtrl = new PopoverNavigationController(ctrl); navCtrl.SetCloseButton(ctrl); if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { if (!TouchFactory.TheApp.Style.HeaderColor.IsDefaultColor) { navCtrl.NavigationBar.BarTintColor = scanLayer.LayerStyle.HeaderColor.ToUIColor(); } if (!TouchFactory.TheApp.Style.HeaderTextColor.IsDefaultColor) { navCtrl.NavigationBar.TintColor = scanLayer.LayerStyle.HeaderTextColor.ToUIColor(); navCtrl.NavigationBar.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = scanLayer.LayerStyle.HeaderTextColor.ToUIColor() }; } } else { navCtrl.NavigationBar.TintColor = scanLayer.LayerStyle.HeaderColor.ToUIColor(); } ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, navCtrl, true); }
public static void Scan(ScanLayer scanLayer) { ScanController controller = new ScanController(scanLayer); var navController = new PopoverNavigationController(controller) { ModalPresentationStyle = UIModalPresentationStyle.FormSheet }; navController.SetCloseButton(controller); if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { if (!TouchFactory.TheApp.Style.HeaderColor.IsDefaultColor) { navController.NavigationBar.BarTintColor = TouchFactory.TheApp.Style.HeaderColor.ToUIColor(); } if (!TouchFactory.TheApp.Style.HeaderTextColor.IsDefaultColor) { navController.NavigationBar.TintColor = TouchFactory.TheApp.Style.HeaderTextColor.ToUIColor(); navController.NavigationBar.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = TouchFactory.TheApp.Style.HeaderTextColor.ToUIColor() }; } } else { navController.NavigationBar.TintColor = TouchFactory.TheApp.Style.HeaderColor.ToUIColor(); } ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, navController, true); }
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 Compose(string url) { if (!MFMailComposeViewController.CanSendMail) { return; } MailTo mailTo = MailTo.ParseUrl(url); var mailComposer = new MFMailComposeViewController(); mailComposer.MailComposeDelegate = new MailComposeDelegate(); mailComposer.SetToRecipients(mailTo.EmailTo.ToArray()); mailComposer.SetSubject(mailTo.EmailSubject); mailComposer.SetMessageBody(mailTo.EmailBody, true); foreach (var attachment in mailTo.EmailAttachments) { string path = attachment.Filename; if (!File.Exists(path)) { path = Path.Combine(TouchFactory.Instance.DataPath, attachment.Filename); } NSData data = NSData.FromFile(path); if (data != null) { mailComposer.AddAttachmentData(data, attachment.MimeType, attachment.Filename); } } ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, mailComposer, true); }
public override IMXView[] PopToRoot() { var views = Views.Skip(1).ToArray(); if (PresentingViewController != null) { ModalManager.EnqueueModalTransition(PresentingViewController, null, true); } else { views = base.PopToRoot(); } return(views); }
public override void PushView(IMXView view) { base.PushView(view); if (this.PresentingViewController == null) { var entry = view as IHistoryEntry; if (entry != null) { ModalPresentationStyle = entry.PopoverPresentationStyle == PopoverPresentationStyle.FullScreen ? UIModalPresentationStyle.FullScreen : UIModalPresentationStyle.FormSheet; } ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, this, true); } }
private static void Submit(LoginLayer layer, UIViewController controller, UIView container, List <UITextField> textFields) { foreach (UITextField textField in textFields) { textField.ResignFirstResponder(); } string username = textFields.Count > 0 ? textFields[0].Text ?? string.Empty : string.Empty; string password = textFields.Count > 1 ? textFields[1].Text ?? string.Empty : string.Empty; iApp.Thread.Start(delegate { using (new Foundation.NSAutoreleasePool()) { if (layer.LogIn(username, password)) { controller.InvokeOnMainThread(() => { ModalManager.EnqueueModalTransition(controller.PresentingViewController, null, true); if (layer.LoginLink != null) { layer.LoginLink.LoadIndicatorDelay = -1; iApp.Navigate(layer.LoginLink); } }); } else { controller.InvokeOnMainThread(() => { TouchFactory.Instance.StopBlockingUserInput(); var alert = new UIAlertView(layer.ErrorText, string.Empty, null, TouchFactory.Instance.GetResourceString("OK"), null); alert.WillDismiss += (sender, e) => AnimateTransparency(container, false); alert.Show(); }); } authActivity.InvokeOnMainThread(() => authActivity.StopAnimating()); } }); authActivity.StartAnimating(); AnimateTransparency(container, true); }
public override IMXView PopView() { if (ViewControllers.Count(vc => !(vc is VanityView)) < 2 && PresentingViewController != null) { var view = base.PopViewController(false); ModalManager.EnqueueModalTransition(PresentingViewController, null, true); var pair = view as IPairable; if (pair == null) { return(view as IMXView); } return((pair.Pair as IMXView) ?? pair as IMXView); } else { return(base.PopView()); } }
public override void ViewDidLoad() { base.ViewDidLoad(); textView = new UITextView() { AutocapitalizationType = UITextAutocapitalizationType.None, AutocorrectionType = UITextAutocorrectionType.No, InputView = new UIView(), }; textView.Changed += TextViewChanged; View.AddSubview(textView); NavigationItem.RightBarButtonItem = new UIBarButtonItem(completeButtonText, UIBarButtonItemStyle.Done, delegate { ModalManager.EnqueueModalTransition(NavigationController.PresentingViewController, null, true); string barcode = string.Join(barcodeSeparatorChar, barcodesScanned); if (barcodesScanned.Count > 0) { // append separator char to end barcode += barcodeSeparatorChar; } if (callback.Parameters == null) { callback.Parameters = new Dictionary <string, string>(); } if (_layer.ActionParameters != null) { callback.Parameters.AddRange(_layer.ActionParameters); } callback.Parameters[barcodeKey] = barcode; iApp.Navigate(callback); }); TableView.BackgroundColor = backgroundColor.IsDefaultColor ? UIColor.White : backgroundColor.ToUIColor(); }
protected override void OnOutputView(IMXView view) { var pairable = view as IPairable; if (!(view is UIViewController) && (pairable == null || !(pairable.Pair is UIViewController))) { iApp.Log.Debug("Cannot output a view whose native component is not a UIViewController."); return; } var controller = GetNativeObject <UIViewController>(view, "view") as UITabBarController; if (controller != null) { if (TopViewController.PresentedViewController != null) { ModalManager.EnqueueModalTransition(TopViewController, null, true); } if (KeyWindow.RootViewController is MGSplitViewController) { SplitViewController.SetViewControllers(new[] { controller, (UIViewController)PaneManager.Instance.FromNavContext(Pane.Detail, 0), (UIViewController)PaneManager.Instance.FromNavContext(Pane.Popover, 0) }); } else { SetRoot(TopViewController = controller); } } else { PaneManager.Instance.DisplayView(view); } }
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { ModalManager.EnqueueModalTransition(picker.PresentingViewController, null, true); Dictionary <string, string> parameters; NSString mediaType = (NSString)info.ObjectForKey(UIImagePickerController.MediaType); iApp.Factory.BeginBlockingUserInput(); iApp.Factory.ActivateLoadTimer(); if (mediaType == MobileCoreServices.UTType.Image) { ThreadPool.QueueUserWorkItem((image) => { using (new NSAutoreleasePool()) { string path = TouchFactory.Instance.StoreImage(((UIImage)image).AsPNG()); InvokeOnMainThread(() => { parameters = new Dictionary <string, string>() { { "PhotoImage", path } }; iApp.Navigate(callback, parameters); }); } }, info.ObjectForKey(UIImagePickerController.EditedImage)); } else if (mediaType == MobileCoreServices.UTType.Movie) { NSUrl url = info.ObjectForKey(UIImagePickerController.MediaURL) as NSUrl; string path = url.AbsoluteString.Remove(0, url.AbsoluteString.IndexOf(TouchFactory.Instance.TempPath) + TouchFactory.Instance.TempPath.Length); parameters = new Dictionary <string, string>() { { "VideoId", path } }; iApp.Navigate(callback, parameters); } }
internal static void Display(this LoginLayer layer) { UIViewController controller = new ViewController() { View = UIDevice.CurrentDevice.CheckSystemVersion(8, 1) && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone ? new LoginView(UIScreen.MainScreen.ApplicationFrame) : new UIView(UIScreen.MainScreen.ApplicationFrame), ModalPresentationStyle = UIModalPresentationStyle.FullScreen, ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve, Autorotate = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad }; if (!string.IsNullOrEmpty(layer.LayerStyle.LayerBackgroundImage)) { controller.View.InsertSubview(new UIImageView() { Image = UIImage.FromBundle(layer.LayerStyle.LayerBackgroundImage), AutoresizingMask = UIViewAutoresizing.FlexibleMargins, Frame = controller.View.Frame, ContentMode = UIViewContentMode.Center }, 0); } else if (!layer.LayerStyle.LayerBackgroundColor.IsDefaultColor) { controller.View.BackgroundColor = layer.LayerStyle.LayerBackgroundColor.ToUIColor(); } UIView container = new UIView() { AutoresizingMask = UIViewAutoresizing.FlexibleMargins }; ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, controller, true); List <UITextField> textFields = new List <UITextField>(); foreach (TextField field in layer.Items.OfType <Fieldset>().SelectMany(i => i).OfType <TextField>()) { UITextField previous = textFields.LastOrDefault(); if (previous != null) { previous.ReturnKeyType = UIReturnKeyType.Next; previous.ShouldReturn += delegate { textFields[textFields.IndexOf(previous) + 1].BecomeFirstResponder(); return(false); }; } textFields.Add(CreateTextField(field, (DefaultHeight + 10) * (textFields.Count + 1))); } UIButton button = new UIButton(); button.TouchUpInside += (sender, e) => Submit(layer, controller, container, textFields); UIImage buttonImage = null; if (TouchFactory.Instance.Settings.ContainsKey("LoginButtonImage")) { buttonImage = UIImage.FromBundle(TouchFactory.Instance.Settings["LoginButtonImage"]); } if (buttonImage == null) { buttonImage = TouchStyle.ImageFromResource("loginButton.png"); button.SetTitle(layer.ActionButtons.FirstOrDefault() == null ? TouchFactory.Instance.GetResourceString("Login") : layer.ActionButtons.First().Text, UIControlState.Normal); button.SetTitleColor(UIColor.White, UIControlState.Normal); } button.SetBackgroundImage(buttonImage, UIControlState.Normal); button.Frame = new CGRect(DefaultWidth - buttonImage.Size.Width, (DefaultHeight + 10) * (textFields.Count + 1), buttonImage.Size.Width, buttonImage.Size.Height); container.Frame = new CGRect(0, 0, DefaultWidth, button.Frame.Bottom); container.Center = new CGPoint(controller.View.Center.X, controller.View.Center.Y - (button.Frame.Bottom / 2 + 24)); container.AddSubviews(textFields.ToArray()); container.AddSubview(button); if (layer.BrandImage != null) { container.AddSubview(new UIImageView() { Image = UIImage.FromBundle(layer.BrandImage.Location ?? string.Empty), Center = new CGPoint(container.Frame.Width / 2, DefaultHeight + 10), ContentMode = UIViewContentMode.Bottom }); } UITextField last = textFields.LastOrDefault(); if (last != null) { last.ReturnKeyType = UIReturnKeyType.Go; last.ShouldReturn += delegate { Submit(layer, controller, container, textFields); return(false); }; } authLabel.RemoveFromSuperview(); authLabel.SizeToFit(); authLabel.Center = new CGPoint((container.Frame.Width / 2) - (21 / 2), button.Center.Y); authLabel.Alpha = 0; authLabel.TextColor = layer.LayerStyle.TextColor.IsDefaultColor ? UIColor.Black : layer.LayerStyle.TextColor.ToUIColor(); authActivity.Frame = new CGRect(authLabel.Frame.Right, authLabel.Frame.Y, 21, 21); authActivity.Alpha = 0; if (authActivity.RespondsToSelector(new Selector(Selector.GetHandle("color")))) { authActivity.Color = layer.LayerStyle.TextColor.IsDefaultColor ? UIColor.Black : layer.LayerStyle.TextColor.ToUIColor(); } container.AddSubviews(authLabel, authActivity); controller.View.AddSubview(container); }
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 override void ViewDidLoad() { base.ViewDidLoad(); this.View.BackgroundColor = UIColor.White; int v = 0; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { v = 20; } nfloat height = this.View.Frame.Height / 2 - v; CGRect frame = new CGRect(0, v, this.View.Frame.Width, height); UIImage image = TouchStyle.ImageFromResource("barcode-overlay-sm.png"); this._imageOverlay = new UIImageView(image) { Frame = frame, ContentMode = UIViewContentMode.Center, AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin) }; this.View.Add(this._imageOverlay); UIImage image2 = TouchStyle.ImageFromResource("barcode-scanblocked-sm.png"); this._imageOverlayScanBlocked = new UIImageView(image2) { Frame = frame, ContentMode = UIViewContentMode.Center, AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin), Hidden = true }; this.View.Add(this._imageOverlayScanBlocked); this._cameraView = new UIView { AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin) }; this._cameraView.Frame = frame; AVAuthorizationStatus authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus == AVAuthorizationStatus.Authorized) { AVCaptureDevice device = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); // update for iOS 13 NSError nSError; AVCaptureDeviceInput aVCaptureDeviceInput = AVCaptureDeviceInput.FromDevice(device, out nSError); if (aVCaptureDeviceInput != null) { this._captureSession = new AVCaptureSession(); this._captureSession.AddInput(aVCaptureDeviceInput); AVCaptureMetadataOutput aVCaptureMetadataOutput = new AVCaptureMetadataOutput(); this._captureSession.AddOutput(aVCaptureMetadataOutput); this._cameraMetaDataDelegate = new CameraScannerSplitView.CameraMetaDataDelegate(this); aVCaptureMetadataOutput.SetDelegate(this._cameraMetaDataDelegate, DispatchQueue.MainQueue); //aVCaptureMetadataOutput.MetadataObjectTypes = aVCaptureMetadataOutput.AvailableMetadataObjectTypes; aVCaptureMetadataOutput.MetadataObjectTypes = AVMetadataObjectType.QRCode | AVMetadataObjectType.Code128Code | AVMetadataObjectType.UPCECode | AVMetadataObjectType.EAN13Code; } } else if (authorizationStatus == AVAuthorizationStatus.NotDetermined) { AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) => { if (!granted) { Device.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType not granted!"); } else { Device.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType granted!"); } }); } else { Device.Log.Error("Not Authorized! Status: " + authorizationStatus.ToString()); } if (authorizationStatus >= AVAuthorizationStatus.NotDetermined && authorizationStatus <= AVAuthorizationStatus.Authorized) { switch ((int)authorizationStatus) { case 0: AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, delegate(bool result) { Device.Thread.ExecuteOnMainThread(delegate { if (result) { this.SetupVideoPreviewLayer(); } else { this.AddNoCameraAccessLabels(); } }); }); break; case 1: Device.Log.Warn("Camera Access is restricted", new object[0]); this.AddNoCameraAccessLabels(); break; case 2: this.AddNoCameraAccessLabels(); break; case 3: this.SetupVideoPreviewLayer(); break; } } this.View.InsertSubviewBelow(this._cameraView, this._imageOverlay); CGRect frame2 = new CGRect(0, frame.Bottom, this.View.Frame.Width, this.View.Frame.Height - frame.Height); this._resultsView = new UITableView(frame2, UITableViewStyle.Plain) { AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleHeight) }; this._resultsView.Source = new CameraScannerSplitView.CameraListSource(this); this.View.Add(this._resultsView); this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, delegate { string text = string.Empty; if (this._resultsView.Source != null) { try { string text2 = string.Empty; List <string> list = (this._resultsView.Source as CameraScannerSplitView.CameraListSource).ScannedBarcodes(); foreach (string current in list) { if (!string.IsNullOrEmpty(current)) { text2 = text2 + current + "\r\n"; } } text = text2; } catch (Exception arg) { Device.Log.Error("This error occurred while parsing barcodes scanned: \r\n" + arg, new object[0]); } } if (this._callback.Parameters == null) { this._callback.Parameters = new Dictionary <string, string>(); } this._callback.Parameters[this._barcodeValueKey] = text; iApp.Navigate(this._callback); ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, null, true); }); }
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(); } }
private static void PresentPicker() { picker.AllowsEditing = true; ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, picker, true);; }
public override void Finished(MFMailComposeViewController controller, MFMailComposeResult result, NSError error) { ModalManager.EnqueueModalTransition(controller.PresentingViewController, null, true); }
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; } }
public override void ViewDidLoad() { base.ViewDidLoad(); View.BackgroundColor = UIColor.Black; NSError error = null; _captureSession = new AVCaptureSession(); CameraMetaDataDelegate del = null; var authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); AVCaptureDevice captureDevice = null; // check authorization status if (authStatus == AVAuthorizationStatus.Authorized) { captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); // update for iOS 13 } else if (authStatus == AVAuthorizationStatus.NotDetermined) { AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) => { if (!granted) { iApp.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType not granted!"); } else { iApp.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType granted!"); } }); } else { iApp.Log.Error("Not Authorized! Status: " + authStatus.ToString()); } if (captureDevice != null) { var videoInput = AVCaptureDeviceInput.FromDevice(captureDevice, out error); if (videoInput != null) { _captureSession.AddInput(videoInput); } else { iApp.Log.Error("Video capture error: " + error.LocalizedDescription); } var metaDataOutput = new AVCaptureMetadataOutput(); _captureSession.AddOutput(metaDataOutput); del = new CameraMetaDataDelegate(this, _layer); metaDataOutput.SetDelegate(del, CoreFoundation.DispatchQueue.MainQueue); //metaDataOutput.MetadataObjectTypes = metaDataOutput.AvailableMetadataObjectTypes; metaDataOutput.MetadataObjectTypes = AVMetadataObjectType.QRCode | AVMetadataObjectType.Code128Code | AVMetadataObjectType.UPCECode | AVMetadataObjectType.EAN13Code; _videoPreviewLayer = new AVCaptureVideoPreviewLayer(_captureSession) { Frame = View.Bounds, Orientation = (AVCaptureVideoOrientation)InterfaceOrientation, }; View.Layer.AddSublayer(_videoPreviewLayer); var image = TouchStyle.ImageFromResource("barcode-overlay-sm.png"); _imageOverlay = new UIImageView(image) { Frame = View.Frame, ContentMode = UIViewContentMode.Center, AutoresizingMask = UIViewAutoresizing.FlexibleMargins, }; View.Add(_imageOverlay); // preload this, and display when scan event occurs var imageScanBlocked = TouchStyle.ImageFromResource("barcode-scanblocked-sm.png"); _imageOverlayScanBlocked = new UIImageView(imageScanBlocked) { Frame = View.Frame, ContentMode = UIViewContentMode.Center, AutoresizingMask = UIViewAutoresizing.FlexibleMargins, Hidden = true, }; View.Add(_imageOverlayScanBlocked); } else { //TODO: Add "Scanner currently not active overlay Image" iApp.Log.Error("null capture device!"); } nfloat startVerticalLoc = UIScreen.MainScreen.Bounds.Height - LastValueScanOverlay.ViewHeight; _lastScanOverlay = new LastValueScanOverlay(startVerticalLoc, _layerFont); View.Add(_lastScanOverlay); NavigationItem.LeftBarButtonItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, delegate { string scannedBarcodes = string.Empty; if (del != null && del.Buffer != null && del.Buffer.CurrentBuffer != null) { foreach (var s in del.Buffer.CurrentBuffer) { scannedBarcodes += s + "\r\n"; } } if (_callback.Parameters == null) { _callback.Parameters = new Dictionary <string, string>(); } _callback.Parameters[_barcodeValueKey] = scannedBarcodes; iApp.Navigate(_callback); ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, null, true); }); }