예제 #1
0
        private Task <Card> ReadAsync(Products supportedProducts, string apiKey)
        {
            var window = UIApplication.SharedApplication.KeyWindow;

            if (window == null)
            {
                throw new InvalidOperationException("There's no current active window");
            }

            if (navigationController == null)
            {
                throw new InvalidOperationException("There's no current navigation controller");
            }

            var id   = GetRequestId();
            var ntcs = new TaskCompletionSource <Card>(id);

            if (Interlocked.CompareExchange(ref completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            readerController = new ReaderController(supportedProducts.ToArray(), apiKey, id);

            navigationController.PresentModalViewController(readerController, true);

            EventHandler <CardReadEventArgs> handler = null;

            handler = (s, e) =>
            {
                var tcs = Interlocked.Exchange(ref completionSource, null);
                readerController.CardRead -= handler;
                if (e.RequestId != id)
                {
                    navigationController.DismissModalViewController(true);
                    return;
                }
                if (e.IsCanceled)
                {
                    navigationController.DismissModalViewController(true);
                    tcs.SetResult(null);
                }
                else if (e.Error != null)
                {
                    navigationController.DismissModalViewController(true);
                    tcs.SetException(e.Error);
                }
                else
                {
                    navigationController.DismissModalViewController(true);
                    tcs.SetResult(e.Card);
                }
            };

            readerController.CardRead += handler;

            return(completionSource.Task);
        }
예제 #2
0
        Task <byte[]> TakeAsync()
        {
            var window = UIApplication.SharedApplication.KeyWindow;

            if (window == null)
            {
                throw new InvalidOperationException("No hay una ventana activa");
            }
            if (navigationController == null)
            {
                throw new InvalidOperationException("No hay un controlador de navegacion en la aplicación");
            }
            var id   = GetRequestId();
            var ntcs = new TaskCompletionSource <byte[]>(id);

            if (Interlocked.CompareExchange(ref completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Sólo se puede hacer una operación a la vez");
            }
            cameraController = new CameraContoller(id);
            navigationController.PresentModalViewController(cameraController, true);
            EventHandler <PhotoEventArgs> handler = null;

            handler = (s, e) =>
            {
                var tcs = Interlocked.Exchange(ref completionSource, null);
                cameraController.PhotoRead -= handler;
                if (e.RequestId != id)
                {
                    navigationController.DismissModalViewController(true);
                }
                if (e.IsCancelled)
                {
                    navigationController.DismissModalViewController(true);
                    tcs.SetResult(null);
                }
                else if (e.Error != null)
                {
                    navigationController.DismissModalViewController(true);
                    tcs.SetException(e.Error);
                }
                else
                {
                    navigationController.DismissModalViewController(true);
                    tcs.SetResult(e.Photo);
                }
            };

            cameraController.PhotoRead += handler;

            return(completionSource.Task);
        }
예제 #3
0
        public void ShowContact(NavigationPage page)
        {
            var key = DateTime.Now.ToString();
            var newPersonController = new ABNewPersonViewController();
            var person = new ABPerson();

            person.FirstName          = "John " + key;
            person.LastName           = "Doe" + key;
            newPersonController.Title = "This is a test";

            newPersonController.DisplayedPerson = person;

            UINavigationController nav = null;

            foreach (var vc in UIApplication.SharedApplication.Windows[0].RootViewController.ChildViewControllers)
            {
                if (vc is UINavigationController)
                {
                    nav = (UINavigationController)vc;
                }
            }

            newPersonController.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs e) =>
            {
                nav.DismissModalViewController(true);
            };


            nav.PresentModalViewController(new UINavigationController(newPersonController), true);
        }
예제 #4
0
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            tableView.DeselectRow(indexPath, false);
            var country    = TableItems[indexPath.Row];
            var controller = _navController.TopViewController as MainViewController;

            if (controller != null)
            {
                controller.GetCountry(country.CountryName, country.CountryFlag);
                _navController.DismissModalViewController(true);
            }
        }
예제 #5
0
 public void PopCustomModal()
 {
     nav.DismissModalViewController(false);
 }
예제 #6
0
 //the user dismissed the color picker
 void HandlePickerDismissed(object sender, EventArgs e)
 {
     HandleColorPicked();
     _pickerNav.DismissModalViewController(true);
 }
예제 #7
0
        public override Task <TEditorResponse> ShowTEditor(string html, ToolbarBuilder toolbarBuilder = null, EventHandler <ToolbarBuilderEventArgs> toolbarBuilderOnClick = null, bool autoFocusInput = false)
        {
            TaskCompletionSource <TEditorResponse> taskRes = new TaskCompletionSource <TEditorResponse>();
            var            tvc     = new TEditorViewController();
            ToolbarBuilder builder = toolbarBuilder;

            if (toolbarBuilder == null)
            {
                builder = new ToolbarBuilder();
            }
            tvc.BuildToolbar(builder, toolbarBuilderOnClick);
            tvc.SetHTML(html);
            tvc.SetAutoFocusInput(autoFocusInput);
            tvc.Title = CrossTEditor.PageTitle;

            UINavigationController nav = null;

            tvc.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(CrossTEditor.CancelText, UIBarButtonItemStyle.Plain, (item, args) =>
            {
                if (nav != null)
                {
                    if (UIKit.UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        nav.DismissModalViewController(true);
                    }
                    else
                    {
                        nav.PopViewController(true);
                    }
                }
                taskRes.SetResult(new TEditorResponse()
                {
                    IsSave = false, HTML = string.Empty
                });
            }), true);
            tvc.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(CrossTEditor.SaveText, UIBarButtonItemStyle.Done, async(item, args) =>
            {
                if (nav != null)
                {
                    if (UIKit.UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        nav.DismissModalViewController(true);
                    }
                    else
                    {
                        nav.PopViewController(true);
                    }
                }
                taskRes.SetResult(new TEditorResponse()
                {
                    IsSave = true, HTML = await tvc.GetHTML()
                });
            }), true);

            var root   = UIApplication.SharedApplication.KeyWindow.RootViewController;
            var window = UIApplication.SharedApplication.Windows;

            var rootWindow = window?.FirstOrDefault()?.RootViewController?.ModalViewController;

            if (rootWindow != null)
            {
                nav = GetNavController(rootWindow);
            }
            else
            {
                nav = GetNavController(root);
            }

            if (nav != null)
            {
                if (UIKit.UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    var childViewControllers = nav.ChildViewControllers;

                    var newnav = new UINavigationController(tvc);
                    newnav.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
                    nav.PresentModalViewController(newnav, true);
                }
                else
                {
                    nav.PushViewController(tvc, true);
                }
            }
            return(taskRes.Task);
        }
예제 #8
0
 private void ButtonReturn_TouchUpInside(object sender, EventArgs e)
 {
     NavController.DismissModalViewController(true);
 }
예제 #9
0
 void doneBtn_HandleClicked(object sender, EventArgs e)
 {
     HandleColorPicked();
     nav.DismissModalViewController(true);
 }