public void PresentFromBarButtonItem_BadButton()
        {
            if (UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Pad)
            {
                Assert.Inconclusive("Requires iPad");
            }

            if (Runtime.Arch == Arch.DEVICE)
            {
                Assert.Ignore("ObjectiveC exception crash on devices - bug #3980");
            }

            using (var vc = new UIViewController())
                using (var bbi = new UIBarButtonItem(UIBarButtonSystemItem.Action))
                    using (var pc = new UIPopoverController(vc)) {
#if __MACCATALYST__
                        pc.PresentFromBarButtonItem(bbi, UIPopoverArrowDirection.Down, true);
#else
                        // UIBarButtonItem is itself 'ok' but it's not assigned to a view
                        Assert.Throws <MonoTouchException> (() => pc.PresentFromBarButtonItem(bbi, UIPopoverArrowDirection.Down, true));
#endif
                        // fails with:
                        // Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIPopoverController presentPopoverFromBarButtonItem:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.
                    }
        }
 partial void showInfo(NSObject sender)
 {
     if (UserInterfaceIdiomIsPhone)
     {
         var controller = new FlipsideViewController()
         {
             ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal,
         };
         controller.Done += delegate {
             this.DismissModalViewControllerAnimated(true);
         };
         this.PresentModalViewController(controller, true);
     }
     else
     {
         if (flipsidePopoverController == null)
         {
             var controller = new FlipsideViewController();
             flipsidePopoverController = new UIPopoverController(controller);
             controller.Done          += delegate {
                 flipsidePopoverController.Dismiss(true);
             };
         }
         if (flipsidePopoverController.PopoverVisible)
         {
             flipsidePopoverController.Dismiss(true);
         }
         else
         {
             flipsidePopoverController.PresentFromBarButtonItem((UIBarButtonItem)sender, UIPopoverArrowDirection.Any, true);
         }
     }
 }
Beispiel #3
0
        void HandlePageModeButtonTouchUpInside()
        {
            HidePopover();

            if (pageModeViewController == null)
            {
                PopoverPageModeController pmc = new PopoverPageModeController();
                pmc.Title          = StringRef.PageView;
                pmc.PageModeEvent += HandlePageModeEvent;

                UINavigationController navController = new UINavigationController();
                navController.SetViewControllers(new UIViewController[] { pmc }, true);
                navController.View.Frame = new CGRect(0, 0, 280, 44 * 3 + 20);

                pageModeViewController = new UIPopoverController(navController);
                pageModeViewController.SetPopoverContentSize(new CGSize(navController.View.Frame.Width, navController.View.Frame.Height), true);
                pageModeViewController.PresentFromBarButtonItem(PageModeItem, UIPopoverArrowDirection.Any, true);
                pageModeViewController.DidDismiss += delegate
                {
                    pageModeViewController = null;
                };
            }
            else
            {
                pageModeViewController.Dismiss(true);
                pageModeViewController = null;
            }
        }
Beispiel #4
0
        void HandleSearchButtonTouchUpInside(object sender, EventArgs args)
        {
            HidePopovers();

            // psc
            if (psc == null)
            {
                psc = new PopoverSearchController(searchString);
                psc.RowSelectedEvent   += HandleSearchResultSelectedEvent;
                psc.ResizePopoverEvent += (nfloat height) =>
                {
                    // Do not cover the TabBar
                    nfloat viewHeight = this.View.Frame.Height - 55;
                    if (height > viewHeight)
                    {
                        height = viewHeight - 20;
                    }

                    psc.PreferredContentSize = new CGSize(psc.View.Frame.Width, height);
                };
            }

            // searchViewController
            searchViewController             = new UIPopoverController(psc);
            searchViewController.DidDismiss += delegate
            {
                searchString = psc.SearchDisplayController.SearchBar.Text;

                searchViewController.Dispose();
                searchViewController = null;
            };
            searchViewController.SetPopoverContentSize(new CGSize(psc.View.Frame.Width, psc.View.Frame.Height), true);
            searchViewController.PresentFromBarButtonItem(searchButton, UIPopoverArrowDirection.Any, true);
        }
Beispiel #5
0
        partial void ChooseVideoTapped(UIBarButtonItem sender)
        {
            var videoPicker = new UIImagePickerController {
                ModalPresentationStyle = UIModalPresentationStyle.CurrentContext,
                SourceType             = UIImagePickerControllerSourceType.SavedPhotosAlbum,
                MediaTypes             = new string[] { UTType.Movie }
            };

            videoPicker.FinishedPickingMedia += (object s, UIImagePickerMediaPickedEventArgs e) => {
                displayLink.Paused = true;
                playButton.Title   = "Play";
                popover.Dismiss(true);

                outputFrames.Clear();
                presentationTimes.Clear();

                lastCallbackTime = 0.0;
                var asset = AVAsset.FromUrl(e.MediaUrl);

                if (assetReader != null && assetReader.Status == AVAssetReaderStatus.Reading)
                {
                    bufferSemaphore.Release();
                    assetReader.CancelReading();
                }

                backgroundQueue.DispatchAsync(() => ReadSampleBuffers(asset));
            };
            videoPicker.Canceled += (object s, EventArgs e) => DismissViewController(true, null);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                popover = new UIPopoverController(videoPicker);
                popover.PresentFromBarButtonItem(sender, UIPopoverArrowDirection.Down, true);
            }
        }
Beispiel #6
0
        partial void share(UIKit.UIBarButtonItem sender)
        {
            if (shareController == null)
            {
                List <UIImage> items           = associatedObject.ItemsForSharing();
                NSObject []    itemsForSharing = new NSObject [(items == null? 0 : items.Count) + 1];
                int            i = 0;
                if (items != null)
                {
                    for (i = 0; i < items.Count; i++)
                    {
                        itemsForSharing [i] = items [i];
                    }
                }
                itemsForSharing [i] = new NSString(Comment());

                UIActivityViewController activityController = new UIActivityViewController(itemsForSharing, null);
                shareController          = new UIPopoverController(activityController);
                shareController.Delegate = new MyDelegate(this);
                shareController.PresentFromBarButtonItem(shareButton, UIPopoverArrowDirection.Any, true);
            }
            else
            {
                shareController.Dismiss(true);
                shareController = null;
            }
        }
        public static void ShareUrl(string url, UIBarButtonItem barButtonItem = null)
        {
            try
            {
                var          item                  = new NSUrl(url);
                var          activityItems         = new NSObject[] { item };
                UIActivity[] applicationActivities = null;
                var          activityController    = new UIActivityViewController(activityItems, applicationActivities);

                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    var window = UIApplication.SharedApplication.KeyWindow;
                    var pop    = new UIPopoverController(activityController);

                    if (barButtonItem != null)
                    {
                        pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true);
                    }
                    else
                    {
                        var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0);
                        pop.PresentFromRect(rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true);
                    }
                }
                else
                {
                    var viewController = UIApplication.SharedApplication.KeyWindow.GetVisibleViewController();
                    viewController.PresentViewController(activityController, true, null);
                }
            }
            catch
            {
            }
        }
Beispiel #8
0
        public void ShareUrl(object sender, Uri uri)
        {
            var item = new NSUrl(uri.AbsoluteUri);
            var activityItems = new NSObject[] { item };
            UIActivity[] applicationActivities = null;
            var activityController = new UIActivityViewController (activityItems, applicationActivities);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) 
            {
                var window = UIApplication.SharedApplication.KeyWindow;
                var pop = new UIPopoverController (activityController);

                var barButtonItem = sender as UIBarButtonItem;
                if (barButtonItem != null)
                {
                    pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0);
                    pop.PresentFromRect (rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true);
                }
            } 
            else 
            {
                var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                viewController.PresentViewController(activityController, true, null);
            }
        }
        private void OpenClicked(object sender, EventArgs e)
        {
            if (iPopover == null)
            {
                UINavigationController navigationController = new UINavigationController(iController);
                iRefreshButton  = new UIBarButtonItem(UIBarButtonSystemItem.Refresh);
                iEditButton     = new UIBarButtonItem(UIBarButtonSystemItem.Edit);
                iEditDoneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done);
                navigationController.NavigationBar.TopItem.Title = iDefaultTitle;
                navigationController.NavigationBar.TopItem.RightBarButtonItem = iRefreshButton;
                navigationController.NavigationBar.TopItem.LeftBarButtonItem  = iEditButton;
                iPopover          = new UIPopoverController(navigationController);
                iPopover.Delegate = this;

                iRefreshButton.Clicked  += RefreshClicked;
                iEditButton.Clicked     += EditClicked;
                iEditDoneButton.Clicked += EditClicked;

                navigationController.PopToRootViewController(false);
                iPopover.SetPopoverContentSize(new SizeF(380, iPopover.PopoverContentSize.Height), true);
                iPopover.PresentFromBarButtonItem(iButton, UIPopoverArrowDirection.Any, true);
            }
            else
            {
                Dismiss();
            }
        }
        void Initialize()
        {
            _timingItemManager = null;            //  new TimingItemManager () { Race = new Race() { Name = _details.Race, Code = _details.Race}, Location =  _details.Location, Token = _details.OurLittleSecret};

            _popover = new SettingsDialogViewController(_details.Location, _details.OurLittleSecret);
            UIPopoverController myPopOver = new UIPopoverController(_popover);

            _popover.Changed += () =>
            {
                _details.Location        = _popover.Location;
                _details.OurLittleSecret = _popover.Secret;
//				_timingItemManager = new TimingItemManager () { Race = new Race() { Name = _details.Race, Code = _details.Race}, Location =  _details.Location, Token = _details.OurLittleSecret};
                PopulateTable(true);
            };
            _popover.Clear += () =>
            {
                // _timingItemManager.Reset();
                _details.Reset();
                PopulateTable(false);
            };
            _popover.Save += () => {
//				_timingItemManager.SaveItem (null);
                _popover.UpdateStatus(_timingItemManager.Status);
            };

            NavigationItem.RightBarButtonItem          = new UIBarButtonItem("Settings", UIBarButtonItemStyle.Plain, null);
            NavigationItem.RightBarButtonItem.Clicked += (sender, e) => { myPopOver.PopoverContentSize = new SizeF(450f, 800f);
                                                                          myPopOver.PresentFromBarButtonItem(NavigationItem.RightBarButtonItem, UIPopoverArrowDirection.Left, true); };
            PopulateTable(true);
        }
        private void OpenClicked(object sender, EventArgs e)
        {
            if (iPopover == null)
            {
                UINavigationController navigationController = new UINavigationController(iController);
                iRefreshButton = new UIBarButtonItem(UIBarButtonSystemItem.Refresh);
                navigationController.NavigationBar.TopItem.RightBarButtonItem = iRefreshButton;
                if (typeof(T) == typeof(Linn.Kinsky.Room))
                {
                    iButtonStandbyAll = new UIButton(new RectangleF(0, 0, 35, 30));
                    iButtonStandbyAll.SetImage(new UIImage("Standby.png"), UIControlState.Normal);
                    iButtonStandbyAll.SetImage(new UIImage("StandbyDown.png"), UIControlState.Highlighted);
                    iButtonStandbyAll.SetImage(new UIImage("StandbyOn.png"), UIControlState.Selected);
                    iButtonStandbyAll.SetBackgroundImage(new UIImage("UIBarButton.png"), UIControlState.Normal);
                    iButtonStandbyAll.TouchUpInside += StandbyAllClicked;

                    UIBarButtonItem barButton = new UIBarButtonItem();
                    barButton.CustomView = iButtonStandbyAll;
                    navigationController.NavigationBar.TopItem.LeftBarButtonItem = barButton;
                    UpdateStandbyAllButtonState();
                }
                iPopover          = new UIPopoverController(navigationController);
                iPopover.Delegate = this;

                iRefreshButton.Clicked += RefreshClicked;

                navigationController.PopToRootViewController(false);
                //iPopover.SetPopoverContentSize(new SizeF(320, 600), true);
                iPopover.PresentFromBarButtonItem(iButton, UIPopoverArrowDirection.Any, true);
            }
            else
            {
                Dismiss();
            }
        }
Beispiel #12
0
        void HandleCollectionMenuButtonTouchUpInside()
        {
            HidePopover();

            if (collectionViewController == null)
            {
                PopoverCollectionController pcc = new PopoverCollectionController();
                pcc.Title             = "Menu";
                pcc.RowSelectedEvent += HandleCollectionMenuButtonEvent;

                UINavigationController navController = new UINavigationController();
                navController.SetViewControllers(new UIViewController[] { pcc }, true);
                navController.View.Frame = new CGRect(0, 0, 280, 44 * 6 + 20);

                collectionViewController = new UIPopoverController(navController);
                collectionViewController.SetPopoverContentSize(new CGSize(navController.View.Frame.Width, navController.View.Frame.Height), true);
                collectionViewController.PresentFromBarButtonItem(CollectionMenuItem, UIPopoverArrowDirection.Any, true);
                collectionViewController.DidDismiss += delegate
                {
                    collectionViewController = null;
                };
            }
            else
            {
                collectionViewController.Dismiss(true);
                collectionViewController = null;
            }
        }
Beispiel #13
0
        // moveToVerifyViewSegue
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            btnAdd.Enabled = false;

            PopMenuView = new PopMenuViewController();
            PopMenuView.FeatureSelected += (sender, e) => {
                Debug.WriteLine(e.SelectedFeatureName);

                if ("Edit" == e.SelectedFeatureName)
                {
                    btnAdd.Enabled = true;
                }
                else if ("Edit" == e.SelectedFeatureName)
                {
                    btnAdd.Enabled = true;
                }
                else
                {
                    btnAdd.Enabled = false;
                }
            };


            btnMenu.Clicked += (sender, e) => {
                UIPopoverController pop = new UIPopoverController(PopMenuView);
                pop.SetPopoverContentSize(new CGSize(200, 150), true);
                pop.PresentFromBarButtonItem(btnMenu, UIPopoverArrowDirection.Any, true);
            };

            btnAdd.Clicked += (sender, e) => {
                PerformSegue("moveToFlow01ViewSegue", this);
            };

            var editingVotes = new VoteManager().ReadEditVotesFromRemote();

            AppDelegate.EditingVotes.AddRange(editingVotes);

            var source = new TableSource(AppDelegate.EditingVotes);

            editingVoteTable.Source = source;

            source.EditingVoteSelected += (sender, e) => {
                AppDelegate.SelectedEditingVote = e.SelectedEditingVote;

                if (AppDelegate.SelectedEditingVote.Status == EditStatus.Request)
                {
                    PerformSegue("moveToVerifyViewSegue", this);
                }
            };
        }
Beispiel #14
0
        public void ShowMasterPopover()
        {
            if (_hiddenPopoverController != null && !(_hiddenPopoverController.PopoverVisible))
            {
                // Inform delegate.
                if (_splitViewDelegate != null)
                {
                    _splitViewDelegate.WillPresentViewController(_masterViewController);
                }

                // Show popover.
                _hiddenPopoverController.PresentFromBarButtonItem(_barButtonItem, UIPopoverArrowDirection.Any, true);
            }
        }
        // moveToVerifyViewSegue
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            // Perform any additional setup after loading the view, typically from a nib.

            btnAdd.Enabled = false;

            PopMenuView = new PopMenuViewController ();
            PopMenuView.FeatureSelected += (sender, e) => {
                Debug.WriteLine (e.SelectedFeatureName);

                if ("Edit" == e.SelectedFeatureName) {
                    btnAdd.Enabled = true;
                }
                else if ("Edit" == e.SelectedFeatureName) {
                    btnAdd.Enabled = true;
                }
                else {
                    btnAdd.Enabled = false;
                }

            };

            btnMenu.Clicked += (sender, e) => {
                UIPopoverController pop = new UIPopoverController (PopMenuView);
                pop.SetPopoverContentSize (new CGSize (200, 150), true);
                pop.PresentFromBarButtonItem ( btnMenu, UIPopoverArrowDirection.Any, true);
            };

            btnAdd.Clicked += (sender, e) => {
                PerformSegue ("moveToFlow01ViewSegue", this);
            };

            var editingVotes = new VoteManager ().ReadEditVotesFromRemote ();
            AppDelegate.EditingVotes.AddRange (editingVotes);

            var source = new TableSource (AppDelegate.EditingVotes);

            editingVoteTable.Source = source;

            source.EditingVoteSelected += ( sender, e) => {

                AppDelegate.SelectedEditingVote = e.SelectedEditingVote;

                if (AppDelegate.SelectedEditingVote.Status == EditStatus.Request) {
                    PerformSegue ("moveToVerifyViewSegue", this);
                }
            };
        }
		void SharePlaceInfo (object sender, EventArgs e)
		{
			var message = new NSString (string.Format("{0}\n{1}\n{2}", viewModel.Place.Name, viewModel.Place.Website, viewModel.ShortAddress));

			var activityController = new UIActivityViewController (new NSObject [] {
				message
			}, null);

			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
				shareController = new UIPopoverController (activityController);
				shareController.PresentFromBarButtonItem(shareButton, UIPopoverArrowDirection.Any, true);
			} else {
				PresentViewController(activityController, true, null);
			}
		}
Beispiel #17
0
        /// <summary>
        /// Opens the publicaion sorting panel.
        /// </summary>
        /// <param name="o">O.</param>
        /// <param name="e">E.</param>
        private void OpenPublicaionSortingPanel(object o, EventArgs e)
        {
            PublicationSortingController publicationSortingController = new PublicationSortingController();

            publicationSortingController.CurPublicationListController = this;
            UIPopoverController sortingPop = new UIPopoverController(publicationSortingController);

            //Dismiss current popover controller if it exist
            AppDisplayUtil.Instance.SetPopoverController(sortingPop);

            sortingPop.PresentFromBarButtonItem((UIBarButtonItem)o, UIPopoverArrowDirection.Any, true);
            sortingPop.SetPopoverContentSize(new CGSize(320, 400), true);

            publicationList = PublicationUtil.Instance.GetPublicationOffline();
            publicationSortingController.SetEditing(true, true);
        }
Beispiel #18
0
        public static void Share(string title = null, string body = null, string url = null, UIBarButtonItem barButtonItem = null)
        {
            try
            {
                var activityItems = new List <NSObject>();
                if (body != null)
                {
                    activityItems.Add(new NSString(body));
                }
                if (url != null)
                {
                    activityItems.Add(new NSUrl(url));
                }

                UIActivity[] applicationActivities = null;
                var          activityController    = new UIActivityViewController(activityItems.ToArray(), applicationActivities);

                if (title != null)
                {
                    activityController.SetValueForKey(new NSString(title), new NSString("subject"));
                }

                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    var window = UIApplication.SharedApplication.KeyWindow;
                    var pop    = new UIPopoverController(activityController);

                    if (barButtonItem != null)
                    {
                        pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true);
                    }
                    else
                    {
                        var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0);
                        pop.PresentFromRect(rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true);
                    }
                }
                else
                {
                    var viewController = UIApplication.SharedApplication.KeyWindow.GetVisibleViewController();
                    viewController.PresentViewController(activityController, true, null);
                }
            }
            catch
            {
            }
        }
Beispiel #19
0
        void ShowMasterPopover()
        {
            AdjustingMaster = true;
            if (hiddenPopoverController != null && !(hiddenPopoverController.PopoverVisible))
            {
                // Inform delegate.
                if (splitViewDelegate != null && splitViewDelegate.RespondsToSelector(new Selector("WillPresentViewController")))
                {
                    WillPresentViewController(viewControllers[0]);
                }

                // Show popover.
                hiddenPopoverController.PopoverContentSize = new CGSize(hiddenPopoverController.PopoverContentSize.Width, hiddenPopoverController.ContentViewController.View.Frame.Height);
                hiddenPopoverController.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true);
            }
            AdjustingMaster = false;
        }
        void SharePlaceInfo(object sender, EventArgs e)
        {
            var message = new NSString(string.Format("{0}\n{1}\n{2}", viewModel.Place.Name, viewModel.Place.Website, viewModel.ShortAddress));

            var activityController = new UIActivityViewController(new NSObject [] {
                message
            }, null);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                shareController = new UIPopoverController(activityController);
                shareController.PresentFromBarButtonItem(shareButton, UIPopoverArrowDirection.Any, true);
            }
            else
            {
                PresentViewController(activityController, true, null);
            }
        }
Beispiel #21
0
        partial void showInfo(NSObject sender)
        {
            if (flipsidePopoverController == null)
            {
                var controller = new FlipsideViewController();
                flipsidePopoverController = new UIPopoverController(controller);
                controller.Done          += delegate {
                    flipsidePopoverController.Dismiss(true);
                };
            }

            if (flipsidePopoverController.PopoverVisible)
            {
                flipsidePopoverController.Dismiss(true);
            }
            else
            {
                flipsidePopoverController.PresentFromBarButtonItem((UIBarButtonItem)sender, UIPopoverArrowDirection.Any, true);
            }
        }
Beispiel #22
0
        protected void Initialize()
        {
            var crews = Create().ToDictionary(b => b.StartNumber, b => b.Name);

            if (crews.Count == 0)
            {
                crews = Enumerable.Range(1, 220).ToDictionary(i => i, i => "crew " + i);
            }

            _popover = new CrewsDialogViewController(crews);
            UIPopoverController myPopOver = new UIPopoverController(_popover);

            _popover.Changed += () =>
            {
                PopulateTable();
            };

            NavigationItem.RightBarButtonItem          = new UIBarButtonItem("Crews", UIBarButtonItemStyle.Plain, null);
            NavigationItem.RightBarButtonItem.Clicked += (sender, e) => { myPopOver.PopoverContentSize = new SizeF(450f, 420f);
                                                                          myPopOver.PresentFromBarButtonItem(NavigationItem.RightBarButtonItem, UIPopoverArrowDirection.Up, true); };
        }
        void HandleContentSyncErrorButtonTouchUpInside(object sender, EventArgs args)
        {
            HidePopovers();

            //popoverContentSyncViewController
            var popover = new PopoverContentSyncViewController();

            popover.SyncButtonTouch += HandleSyncButtonTouchEvent;
            popover.View.Frame       = new CGRect(0, 0, 300, 190);

            // contentSyncViewController
            contentSyncViewController             = new UIPopoverController(popover);
            contentSyncViewController.DidDismiss += delegate
            {
                contentSyncViewController.Dispose();
                contentSyncViewController = null;
            };

            contentSyncViewController.SetPopoverContentSize(new CGSize(popover.View.Frame.Width, popover.View.Frame.Height), true);
            contentSyncViewController.PresentFromBarButtonItem(contentSyncErrorButton, UIPopoverArrowDirection.Any, true);
        }
        void ShowAlertViewController(string showMapsButtonTitle, string makeCallButtonTitle, string addToContactsButtonTitle, string streetViewButtonTitle, string cancelButtonTitle)
        {
            var alertController = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet);

            alertController.AddAction(UIAlertAction.Create(streetViewButtonTitle, UIAlertActionStyle.Default, OpenStreetView));
            alertController.AddAction(UIAlertAction.Create(showMapsButtonTitle, UIAlertActionStyle.Default, ShowMaps));
            alertController.AddAction(UIAlertAction.Create(makeCallButtonTitle, UIAlertActionStyle.Default, MakeACall));
            alertController.AddAction(UIAlertAction.Create(addToContactsButtonTitle, UIAlertActionStyle.Default, AddContact));
            alertController.AddAction(UIAlertAction.Create(cancelButtonTitle, UIAlertActionStyle.Destructive, null));

            SetupPopover(alertController, View);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                var moreController = new UIPopoverController(alertController);
                moreController.PresentFromBarButtonItem(moreButton, UIPopoverArrowDirection.Any, true);
            }
            else
            {
                PresentViewController(alertController, true, null);
            }
        }
Beispiel #25
0
        void HandleSettingButtonTouchUpInside(object sender, EventArgs args)
        {
            HidePopovers();

            // psc
            PopoverSettingController psc = new PopoverSettingController(UITableViewStyle.Grouped);

            psc.View.Frame        = new CGRect(0, 0, 300, 444);
            psc.RowSelectedEvent += HandleSettingRowSelectedEvent;
            psc.SyncOnEvent      += HandleSyncOnEvent;
            psc.SyncOffEvent     += HandleSyncOffEvent;

            // settingViewController
            settingViewController             = new UIPopoverController(psc);
            settingViewController.DidDismiss += delegate
            {
                settingViewController.Dispose();
                settingViewController = null;
            };
            settingViewController.SetPopoverContentSize(new CGSize(psc.View.Frame.Width, psc.View.Frame.Height), true);
            settingViewController.PresentFromBarButtonItem(settingButton, UIPopoverArrowDirection.Any, true);
        }
        public virtual void settingsTouched(object sender, EventArgs e)
        {
            SettingsViewController settings = new SettingsViewController(this);
            UIUserInterfaceIdiom   idiom    = UIDevice.CurrentDevice.UserInterfaceIdiom;

            if (idiom == UIUserInterfaceIdiom.Pad)
            {
                if (popover != null && popover.PopoverVisible)
                {
                    popover.Dismiss(true);
                    return;
                }
                popover = new UIPopoverController(settings);
                CGRect settingsRect = settings.View.Bounds;
                settings.Table.SizeToFit();
                popover.PopoverContentSize = new CGSize((float)(Math.Min(settingsRect.Size.Width, settingsRect.Size.Height) / 2.0), settings.Table.ContentSize.Height);
                popover.PresentFromBarButtonItem(settingsButton, UIPopoverArrowDirection.Up, true);
            }
            else
            {
                this.NavigationController.PushViewController(settings, true);
            }
        }
		partial void share (MonoTouch.UIKit.UIBarButtonItem sender)
		{
			if(shareController == null){
				List<UIImage> items = associatedObject.ItemsForSharing();
				NSObject [] itemsForSharing = new NSObject [(items == null? 0 : items.Count) + 1];
            	int i = 0;
				if (items!= null) {
					for (i = 0; i < items.Count; i++)
						itemsForSharing [i] = items [i];
				}
				itemsForSharing [i] = new NSString (Comment ());
			
			UIActivityViewController activityController = new UIActivityViewController(itemsForSharing, null);
			shareController = new UIPopoverController(activityController);
			shareController.Delegate = new MyDelegate(this);
			shareController.PresentFromBarButtonItem(shareButton, UIPopoverArrowDirection.Any, true);
			}
			else{
				shareController.Dismiss(true);
				shareController = null;
				}
		}
 public virtual void settingsTouched(object sender, EventArgs e)
 {
     SettingsViewController settings = new SettingsViewController (this);
     UIUserInterfaceIdiom idiom = UIDevice.CurrentDevice.UserInterfaceIdiom;
     if (idiom == UIUserInterfaceIdiom.Pad)
     {
         if (popover != null && popover.PopoverVisible)
         {
             popover.Dismiss (true);
             return;
         }
         popover = new UIPopoverController (settings);
         CGRect settingsRect = settings.View.Bounds;
         settings.Table.SizeToFit ();
         popover.PopoverContentSize = new CGSize ((float)(Math.Min(settingsRect.Size.Width, settingsRect.Size.Height) / 2.0), settings.Table.ContentSize.Height);
         popover.PresentFromBarButtonItem (settingsButton, UIPopoverArrowDirection.Up, true);
     }
     else
     {
         this.NavigationController.PushViewController (settings, true);
     }
 }
        internal Task <MobileServiceUser> SendLoginAsync(RectangleF rect, object view, MobileServiceAuthenticationProvider provider, JsonObject token = null)
        {
            if (this.LoginInProgress)
            {
                throw new InvalidOperationException(Resources.MobileServiceClient_Login_In_Progress);
            }

            if (!Enum.IsDefined(typeof(MobileServiceAuthenticationProvider), provider))
            {
                throw new ArgumentOutOfRangeException("provider");
            }

            string providerName = provider.ToString().ToLower();

            this.LoginInProgress = true;

            TaskCompletionSource <MobileServiceUser> tcs = new TaskCompletionSource <MobileServiceUser> ();

            if (token != null)
            {
                // Invoke the POST endpoint to exchange provider-specific token for a Windows Azure Mobile Services token

                this.RequestAsync("POST", LoginAsyncUriFragment + "/" + providerName, token)
                .ContinueWith(t =>
                {
                    this.LoginInProgress = false;

                    if (t.IsCanceled)
                    {
                        tcs.SetCanceled();
                    }
                    else if (t.IsFaulted)
                    {
                        tcs.SetException(t.Exception.InnerExceptions);
                    }
                    else
                    {
                        SetupCurrentUser(t.Result);
                        tcs.SetResult(this.CurrentUser);
                    }
                });
            }
            else
            {
                // Launch server side OAuth flow using the GET endpoint

                Uri startUri = new Uri(this.ApplicationUri, LoginAsyncUriFragment + "/" + providerName);
                Uri endUri   = new Uri(this.ApplicationUri, LoginAsyncDoneUriFragment);

                WebRedirectAuthenticator auth = new WebRedirectAuthenticator(startUri, endUri);
                auth.ClearCookiesBeforeLogin = false;

                UIViewController c = auth.GetUI();

                UIViewController    controller = null;
                UIPopoverController popover    = null;

                auth.Error += (o, e) =>
                {
                    this.LoginInProgress = false;

                    if (controller != null)
                    {
                        controller.DismissModalViewControllerAnimated(true);
                    }
                    if (popover != null)
                    {
                        popover.Dismiss(true);
                    }

                    Exception ex = e.Exception ?? new Exception(e.Message);
                    tcs.TrySetException(ex);
                };

                auth.Completed += (o, e) =>
                {
                    this.LoginInProgress = false;

                    if (controller != null)
                    {
                        controller.DismissModalViewControllerAnimated(true);
                    }
                    if (popover != null)
                    {
                        popover.Dismiss(true);
                    }

                    if (!e.IsAuthenticated)
                    {
                        tcs.TrySetCanceled();
                    }
                    else
                    {
                        SetupCurrentUser(JsonValue.Parse(e.Account.Properties["token"]));
                        tcs.TrySetResult(this.CurrentUser);
                    }
                };

                controller = view as UIViewController;
                if (controller != null)
                {
                    controller.PresentModalViewController(c, true);
                }
                else
                {
                    UIView          v         = view as UIView;
                    UIBarButtonItem barButton = view as UIBarButtonItem;

                    popover = new UIPopoverController(c);

                    if (barButton != null)
                    {
                        popover.PresentFromBarButtonItem(barButton, UIPopoverArrowDirection.Any, true);
                    }
                    else
                    {
                        popover.PresentFromRect(rect, v, UIPopoverArrowDirection.Any, true);
                    }
                }
            }

            return(tcs.Task);
        }
        protected void Initialize()
        {
            var crews = Create ().ToDictionary(b => b.StartNumber, b => b.Name);
            if(crews.Count == 0)
                crews = Enumerable.Range (1, 220).ToDictionary (i => i, i => "crew " + i);

            _popover = new CrewsDialogViewController(crews);
            UIPopoverController myPopOver = new UIPopoverController(_popover);
            _popover.Changed += () =>
            {
                PopulateTable();
            };

            NavigationItem.RightBarButtonItem = new UIBarButtonItem("Crews", UIBarButtonItemStyle.Plain, null);
            NavigationItem.RightBarButtonItem.Clicked += (sender, e) => { myPopOver.PopoverContentSize = new SizeF(450f, 420f);
                myPopOver.PresentFromBarButtonItem (NavigationItem.RightBarButtonItem, UIPopoverArrowDirection.Up, true); };
        }
partial         void ChooseVideoTapped(UIBarButtonItem sender)
        {
            var videoPicker = new UIImagePickerController {
                ModalPresentationStyle = UIModalPresentationStyle.CurrentContext,
                SourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum,
                MediaTypes = new string[] { UTType.Movie }
            };
            videoPicker.FinishedPickingMedia += (object s, UIImagePickerMediaPickedEventArgs e) => {
                displayLink.Paused = true;
                playButton.Title = "Play";
                popover.Dismiss (true);

                outputFrames.Clear ();
                presentationTimes.Clear ();

                lastCallbackTime = 0.0;
                var asset = AVAsset.FromUrl (e.MediaUrl);

                if (assetReader != null && assetReader.Status == AVAssetReaderStatus.Reading) {
                    bufferSemaphore.Release ();
                    assetReader.CancelReading ();
                }

                backgroundQueue.DispatchAsync (() => ReadSampleBuffers (asset));
            };
            videoPicker.Canceled += (object s, EventArgs e) => DismissViewController (true, null);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
                popover = new UIPopoverController (videoPicker);
                popover.PresentFromBarButtonItem (sender, UIPopoverArrowDirection.Down, true);
            }
        }
		void ShowAlertViewController (string showMapsButtonTitle, string makeCallButtonTitle, string addToContactsButtonTitle, string streetViewButtonTitle, string cancelButtonTitle)
		{
			var alertController = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet);

			alertController.AddAction(UIAlertAction.Create(streetViewButtonTitle, UIAlertActionStyle.Default, OpenStreetView));
			alertController.AddAction(UIAlertAction.Create(showMapsButtonTitle, UIAlertActionStyle.Default, ShowMaps));
			alertController.AddAction(UIAlertAction.Create(makeCallButtonTitle, UIAlertActionStyle.Default, MakeACall));
			alertController.AddAction(UIAlertAction.Create(addToContactsButtonTitle, UIAlertActionStyle.Default, AddContact));
			alertController.AddAction(UIAlertAction.Create(cancelButtonTitle, UIAlertActionStyle.Destructive, null));

			SetupPopover(alertController, View);

			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
				var moreController = new UIPopoverController (alertController);
				moreController.PresentFromBarButtonItem(moreButton, UIPopoverArrowDirection.Any, true);
			} else {
				PresentViewController(alertController, true, null);
			}
		}
Beispiel #33
0
        private static async Task <DropDownListSelection <TItem> > ShowInternal <TSection, TItem>(
            UIView containerView,
            object anchorUIElement,
            UITableViewCellStyle itemStyle,
            UITableViewStyle headerStyle,
            IEnumerable <TSection> sections,
            Func <TSection, GenericTableViewSection <TItem> > sectionDescriber,
            Func <TItem, GenericCellDescriptor> itemDescriber,
            UIPopoverArrowDirection arrowDirection,
            CGSize?fitSize
            ) where TSection : IEnumerable <TItem>
        {
            if (anchorUIElement == null)
            {
                throw new ArgumentNullException("anchorView");
            }

            if (!(anchorUIElement is UIView || anchorUIElement is UIBarButtonItem))
            {
                throw new ArgumentOutOfRangeException("anchorView", "Must be a UIView or a UIBarButtonItem");
            }

            var sectionsArray = sections.Select(sectionDescriber).ToArray();


            if (sectionsArray.Count() == 1 && string.IsNullOrWhiteSpace(sectionsArray.First().Title))
            {
                headerStyle = UITableViewStyle.Plain;
            }

            var selectSignal = new ManualResetEventSlim();
            var table        = new UITableViewController(headerStyle);

            table.AutomaticallyAdjustsScrollViewInsets = false;
            var result            = new DropDownListSelection <TItem>();
            var popOverController = new UIPopoverController(table);

            var dropDownSource = new GenericTableViewSource <TItem>(
                table.TableView,
                itemStyle,
                sectionsArray,
                itemDescriber,
                (x) => {
                result.SelectedItem = x;
                popOverController.Dismiss(false);
                selectSignal.Set();
            }
                );

            popOverController.DidDismiss += (object sender, EventArgs e) => {
                if (!selectSignal.IsSet)
                {
                    selectSignal.Set();
                }
            };

            ((UITableView)table.View).Source = dropDownSource;

            // Calculate how wide the view should be by finding how
            if (fitSize == null)
            {
                // calculate the fit size
                var    tableView     = (UITableView)table.View;
                nfloat largestWidth  = 0.0f;
                var    sectionHeight = (headerStyle == UITableViewStyle.Plain ? (float)tableView.SectionHeaderHeight : Tools.iOSTool.DefaultGroupedTableViewHeaderHeight);
                nfloat totalHeight   = sectionHeight * sectionsArray.Count(s => !string.IsNullOrWhiteSpace(s.Title));
                foreach (var section in sectionsArray)
                {
                    foreach (var itemDescriptor in ((IEnumerable <TItem>)section.Items).WithDescriptions())
                    {
                        var index    = itemDescriptor.Index;
                        var item     = itemDescriptor.Description;
                        var cellSize = (CGSize)dropDownSource.GetCell(tableView, (NSIndexPath)(NSIndexPath.FromRowSection(index, 0))).SizeThatFits((CGSize)CGSize.Empty);
                        if (cellSize.Width > largestWidth)
                        {
                            largestWidth = cellSize.Width;
                        }
                        totalHeight += cellSize.Height;
                    }
                }

                fitSize = new CGSize(largestWidth + ItemPadding, totalHeight);
            }
            popOverController.SetPopoverContentSize(fitSize.Value, false);

            TypeSwitch.Do(
                anchorUIElement,
                TypeSwitch.Case <UIBarButtonItem>(bbi =>
                                                  popOverController.PresentFromBarButtonItem(
                                                      (UIBarButtonItem)anchorUIElement,
                                                      arrowDirection,
                                                      true
                                                      )
                                                  ),
                TypeSwitch.Case <UIView>(v =>
                                         popOverController.PresentFromRect(
                                             ((UIView)anchorUIElement).Frame,
                                             containerView,
                                             arrowDirection,
                                             true
                                             )
                                         ),
                TypeSwitch.Case <UITabBarItem>(tb => {
                var tabBar = containerView as UITabBar;
                if (tabBar == null)
                {
                    throw new ArgumentException("Container view must be an UITabBar when the anchor view is an UITabBarItem");
                }

                if (!tabBar.Items.Contains(tb))
                {
                    throw new ArgumentException("Container view UITabBar does not contain the anchor view UITabBarItem");
                }

                var index           = tabBar.Items.IndexOf(tb);
                var tabBarItemWidth = tabBar.Frame.Size.Width / tabBar.Items.Count();
                var rect            = new CGRect(tabBarItemWidth * index, 0f, tabBarItemWidth, tabBar.Frame.Height);

                popOverController.PresentFromRect(
                    rect,
                    tabBar,
                    arrowDirection,
                    true
                    );
            }),
                TypeSwitch.Default(() => { throw new NotSupportedException("anchorUIElement was {0}".FormatWith(anchorUIElement.GetType().Name)); })
                );

            await Task.Run(() => selectSignal.Wait());

            table.View.DisposeEx();
            table.TableView.DisposeEx();
            table.Dispose();
            popOverController.Dispose();

            return(result);
        }
		private async Task<Auth0User> SendLoginAsync(
			RectangleF rect, 
			object view, 
			string connection,
			bool withRefreshToken,
			string scope,
			string title)
		{
			// Launch server side OAuth flow using the GET endpoint
            scope = IncreaseScopeWithOfflineAccess(withRefreshToken, scope);

			var tcs = new TaskCompletionSource<Auth0User> ();
			var auth = await this.GetAuthenticator (connection, scope, title);


			UIViewController c = auth.GetUI();

			UIViewController controller = null;
			UIPopoverController popover = null;

			auth.Error += (o, e) =>
			{
				if (controller != null) {
					controller.DismissViewController (true, null);
				}

				if (popover != null) {
					popover.Dismiss (true);
				}

				var ex = e.Exception ?? new AuthException (e.Message);
				tcs.TrySetException (ex);
			};

			auth.Completed += (o, e) =>
			{

				if (controller != null) {
					controller.DismissViewController (true, null);
				}

				if (popover != null) {
					popover.Dismiss (true);
				}

				if (!e.IsAuthenticated) {
					tcs.TrySetCanceled();
				}
				else
				{
					this.SetupCurrentUser (e.Account.Properties);
					tcs.TrySetResult (this.CurrentUser);
				}
			};

			controller = view as UIViewController;
			if (controller != null)
			{
				controller.PresentViewController (c, true, null);
			}
			else
			{
				UIView v = view as UIView;
				UIBarButtonItem barButton = view as UIBarButtonItem;

				popover = new UIPopoverController (c);

				if (barButton != null) {
					popover.PresentFromBarButtonItem (barButton, UIPopoverArrowDirection.Any, true);
				} 
				else {
					popover.PresentFromRect (rect, v, UIPopoverArrowDirection.Any, true);
				}
			}

			return await tcs.Task;
		}
        protected override Task <string> LoginAsyncOverride()
        {
            var tcs = new TaskCompletionSource <string>();

            var auth = new WebRedirectAuthenticator(StartUri, EndUri);

            auth.ShowUIErrors            = false;
            auth.ClearCookiesBeforeLogin = false;

            UIViewController c = auth.GetUI();

            UIViewController    controller = null;
            UIPopoverController popover    = null;

            auth.Error += (o, e) =>
            {
                NSAction completed = () =>
                {
                    Exception ex = e.Exception ?? new Exception(e.Message);
                    tcs.TrySetException(ex);
                };

                if (controller != null)
                {
                    controller.DismissViewController(true, completed);
                }
                if (popover != null)
                {
                    popover.Dismiss(true);
                    completed();
                }
            };

            auth.Completed += (o, e) =>
            {
                NSAction completed = () =>
                {
                    if (!e.IsAuthenticated)
                    {
                        tcs.TrySetException(new InvalidOperationException(Resources.IAuthenticationBroker_AuthenticationCanceled));
                    }
                    else
                    {
                        tcs.TrySetResult(e.Account.Properties["token"]);
                    }
                };

                if (controller != null)
                {
                    controller.DismissViewController(true, completed);
                }
                if (popover != null)
                {
                    popover.Dismiss(true);
                    completed();
                }
            };

            controller = view as UIViewController;
            if (controller != null)
            {
                controller.PresentViewController(c, true, null);
            }
            else
            {
                UIView          v         = view as UIView;
                UIBarButtonItem barButton = view as UIBarButtonItem;

                popover = new UIPopoverController(c);

                if (barButton != null)
                {
                    popover.PresentFromBarButtonItem(barButton, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    popover.PresentFromRect(rect, v, UIPopoverArrowDirection.Any, true);
                }
            }

            return(tcs.Task);
        }
        protected override Task<string> LoginAsyncOverride()
        {
            var tcs = new TaskCompletionSource<string>();

            var auth = new WebRedirectAuthenticator(StartUri, EndUri);
            auth.ShowUIErrors = false;
            auth.ClearCookiesBeforeLogin = false;

            UIViewController c = auth.GetUI();

            UIViewController controller = null;
            UIPopoverController popover = null;

            auth.Error += (o, e) =>
            {
                NSAction completed = () =>
                {
                    Exception ex = e.Exception ?? new Exception(e.Message);
                    tcs.TrySetException(ex);
                };

                if (controller != null)
                    controller.DismissViewController(true, completed);
                if (popover != null)
                {
                    popover.Dismiss(true);
                    completed();
                }
            };

            auth.Completed += (o, e) =>
            {
                NSAction completed = () =>
                {
                    if (!e.IsAuthenticated)
                        tcs.TrySetException(new InvalidOperationException("Authentication was cancelled by the user."));
                    else
                        tcs.TrySetResult(e.Account.Properties["token"]);
                };

                if (controller != null)
                    controller.DismissViewController(true, completed);
                if (popover != null)
                {
                    popover.Dismiss(true);
                    completed();
                }
            };

            controller = view as UIViewController;
            if (controller != null)
            {
                controller.PresentViewController(c, true, null);
            }
            else
            {
                UIView v = view as UIView;
                UIBarButtonItem barButton = view as UIBarButtonItem;

                popover = new UIPopoverController(c);

                if (barButton != null)
                    popover.PresentFromBarButtonItem(barButton, UIPopoverArrowDirection.Any, true);
                else
                    popover.PresentFromRect(rect, v, UIPopoverArrowDirection.Any, true);
            }

            return tcs.Task;
        }
        protected override Task <string> GetAuthorizationCodeAsync()
        {
            var tcs = new TaskCompletionSource <string>();

            if (CurrentAuthenticator != null)
            {
                tcs.TrySetException(new InvalidOperationException("Authentication is already in progress."));
                return(tcs.Task);
            }

            CurrentAuthenticator = new WebRedirectAuthenticator(LoginUri, CallbackUri)
            {
                IsUsingNativeUI         = ObjCRuntime.Class.GetHandle("SFSafariViewController") != IntPtr.Zero,
                ClearCookiesBeforeLogin = false
            };

            UIViewController c = CurrentAuthenticator.GetUI();

            UIViewController    controller = null;
            UIPopoverController popover    = null;

            CurrentAuthenticator.Error += (o, e) =>
            {
                NSAction completed = () =>
                {
                    Exception ex = e.Exception ?? new Exception(e.Message);
                    tcs.TrySetException(ex);
                };

                if (controller != null)
                {
                    controller.DismissViewController(true, completed);
                }

                if (popover != null)
                {
                    popover.Dismiss(true);
                    completed();
                }
                CurrentAuthenticator = null;
            };

            CurrentAuthenticator.Completed += (o, e) =>
            {
                NSAction completed = () =>
                {
                    string authorizationCode;
                    if (!e.IsAuthenticated)
                    {
                        tcs.TrySetException(new InvalidOperationException("Authentication was cancelled by the user."));
                    }
                    else if (!e.Account.Properties.TryGetValue("authorization_code", out authorizationCode))
                    {
                        tcs.TrySetException(new InvalidOperationException("Authentication failed: could not found \"authorization_code\"."));
                    }
                    else
                    {
                        tcs.TrySetResult(authorizationCode);
                    }
                };

                if (controller != null)
                {
                    controller.DismissViewController(true, completed);
                }

                if (popover != null)
                {
                    popover.Dismiss(true);
                    completed();
                }
                CurrentAuthenticator = null;
            };

            controller = view as UIViewController;
            if (controller != null)
            {
                controller.PresentViewController(c, true, null);
            }
            else
            {
                UIView          v         = view as UIView;
                UIBarButtonItem barButton = view as UIBarButtonItem;

                popover = new UIPopoverController(c);

                if (barButton != null)
                {
                    popover.PresentFromBarButtonItem(barButton, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    popover.PresentFromRect(rect, v, UIPopoverArrowDirection.Any, true);
                }
            }

            return(tcs.Task);
        }
        public void PickFromCamera()
        {
            // create a new picker controller

            // set our source to the photo library
            imagePicker = new UIImagePickerController ();
            imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
            // set what media types
            imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.Camera);
            imagePicker.FinishedPickingMedia += HandleFinishedPickingMedia;
            imagePicker.Canceled += Handle_Canceled;
            // show the picker
            if(UserInterfaceIdiomIsPhone){
                NavigationController.PresentViewController (imagePicker, true, delegate {});
            }else{
                Console.WriteLine("Popover");
                Pc = new UIPopoverController(imagePicker);
                Pc.PresentFromBarButtonItem(it, UIPopoverArrowDirection.Up, true);
            }
        }
 void extractImage()
 {
     imagePicker.FinishedPickingMedia += HandleFinishedPickingMedia;
     imagePicker.Canceled += Handle_Canceled;
     // show the picker
     if (UserInterfaceIdiomIsPhone) {
         NavigationController.PresentViewController (imagePicker, true, delegate{});
     }
     else {
         Console.WriteLine ("Popover");
         Pc = new UIPopoverController (imagePicker);
         Pc.PresentFromBarButtonItem (it, UIPopoverArrowDirection.Up, true);
     }
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
//			UIImage image = UIImage.FromBundle("tvBgImage.png");
//			UIImageView iv = new UIImageView(image);
//
//
//			iv.AddConstraints(new NSLayoutConstraint[]{});
//			iv.ContentMode = UIViewContentMode.ScaleToFill;
//			View.Add(iv);
//			View.SendSubviewToBack(iv);
//

            nameField.ClearButtonMode         = UITextFieldViewMode.WhileEditing;
            serialNumberField.ClearButtonMode = UITextFieldViewMode.WhileEditing;
            valueField.ClearButtonMode        = UITextFieldViewMode.WhileEditing;

            UIColor clr = null;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                clr = UIColor.FromRGBA(0.875f, 0.88f, 9.1f, 1f);
            }
            else
            {
                clr = UIColor.GroupTableViewBackgroundColor;
            }
            this.View.BackgroundColor = clr;

            dp      = new UIDatePicker();
            dp.Mode = UIDatePickerMode.Date;
            if (item.dateCreated.Kind == DateTimeKind.Unspecified)
            {
                item.dateCreated = DateTime.SpecifyKind(item.dateCreated, DateTimeKind.Local);
            }
            dp.Date = (NSDate)item.dateCreated;

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                ac = UIAlertController.Create(
                    NSBundle.MainBundle.LocalizedString("Do you really want to change the date?", "Confirm Date Change"),
                    NSBundle.MainBundle.LocalizedString("Modifying the date of an acquired item can result in charges of insurance fraud.", "Change Warning"),
                    UIAlertControllerStyle.Alert);

                ac.AddAction(UIAlertAction.Create(NSBundle.MainBundle.LocalizedString("Cancel", "Cancel"), UIAlertActionStyle.Cancel, (alertAction) => {
                    if (dateField.IsFirstResponder)
                    {
                        dateField.ResignFirstResponder();
                    }
                }));
                ac.AddAction(UIAlertAction.Create(NSBundle.MainBundle.LocalizedString("OK", "OK"), UIAlertActionStyle.Default, (alertAction) => {
                    dateField.BecomeFirstResponder();
                }));
            }
            else
            {
                av = new UIAlertView(
                    NSBundle.MainBundle.LocalizedString("Do you really want to change the date?", "Confirm Date Change"),
                    NSBundle.MainBundle.LocalizedString("Modifying the date of an acquired item can result in charges of insurance fraud.", "Change Warning"),
                    null,
                    NSBundle.MainBundle.LocalizedString("Cancel", "Cancel"),
                    new string[] { NSBundle.MainBundle.LocalizedString("OK", "OK") });
                av.Clicked += (object sender, UIButtonEventArgs e) => {
                    Console.WriteLine("Av Clicked");
                    av.DismissWithClickedButtonIndex(e.ButtonIndex, true);
                    if (e.ButtonIndex == 0)
                    {
                        if (dateField.IsFirstResponder)
                        {
                            dateField.ResignFirstResponder();
                        }
                    }
                    else
                    {
                        dateField.BecomeFirstResponder();
                    }
                };
            }

            dateField.InputView  = dp;
            dateField.TouchDown += (sender, e) => {
                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    PresentModalViewController(ac, true);
                }
                else
                {
                    av.Show();
                }
            };

            dp.ValueChanged += (object sender, EventArgs e) => {
                DateTime newDate = (DateTime)dp.Date;
                Console.WriteLine("test dp: " + newDate.ToLocalTime());
                item.dateCreated = newDate.ToLocalTime();
                dateField.Text   = item.dateCreated.ToShortDateString();
            };

            nameField.EditingChanged += (object sender, EventArgs e) => {
                this.NavigationItem.Title = nameField.Text;
            };

            takePicture.Clicked += (sender, e) => {
                if (imagePickerPopover != null && imagePickerPopover.PopoverVisible)
                {
                    // if the popover is already up, get rid of it
                    imagePickerPopover.Dismiss(true);
                    imagePickerPopover = null;
                    return;
                }

                UIImagePickerController imagePicker = new UIImagePickerController();

                // If device has camera, take picture, else pick from photo library
                if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
                {
                    imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
                }
                else
                {
                    imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
                }

                imagePicker.WeakDelegate = this;

                // Place the image picker on the screen
                //this.PresentViewController(imagePicker, true, null);
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
                    {
                        this.PresentViewController(imagePicker, true, null);
                        return;
                    }
                    imagePickerPopover = new UIPopoverController(imagePicker);
                    imagePickerPopover.WeakDelegate = this;

                    // Diaplay the popover controller
                    // sender is the camera bar button item
                    imagePickerPopover.PresentFromBarButtonItem((UIBarButtonItem)sender, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    this.PresentViewController(imagePicker, true, null);
                }
            };
        }
        void Initialize()
        {
            _timingItemManager = null;//  new TimingItemManager () { Race = new Race() { Name = _details.Race, Code = _details.Race}, Location =  _details.Location, Token = _details.OurLittleSecret};

            _popover = new SettingsDialogViewController (_details.Location, _details.OurLittleSecret);
            UIPopoverController myPopOver = new UIPopoverController(_popover);
            _popover.Changed += () =>
            {
                _details.Location = _popover.Location;
                _details.OurLittleSecret = _popover.Secret;
            //				_timingItemManager = new TimingItemManager () { Race = new Race() { Name = _details.Race, Code = _details.Race}, Location =  _details.Location, Token = _details.OurLittleSecret};
                PopulateTable(true);
            };
            _popover.Clear += () =>
            {
                // _timingItemManager.Reset();
                _details.Reset();
                PopulateTable(false);
            };
            _popover.Save += () => {
            //				_timingItemManager.SaveItem (null);
                _popover.UpdateStatus(_timingItemManager.Status);
            };

            NavigationItem.RightBarButtonItem = new UIBarButtonItem("Settings", UIBarButtonItemStyle.Plain, null);
            NavigationItem.RightBarButtonItem.Clicked += (sender, e) => { myPopOver.PopoverContentSize = new SizeF(450f, 800f);
                myPopOver.PresentFromBarButtonItem (NavigationItem.RightBarButtonItem, UIPopoverArrowDirection.Left, true); };
            PopulateTable (true);
        }
        internal Task<MobileServiceUser> SendLoginAsync(RectangleF rect, object view, MobileServiceAuthenticationProvider provider, JsonObject token = null)
        {
            if (this.LoginInProgress)
            {
                throw new InvalidOperationException(Resources.MobileServiceClient_Login_In_Progress);
            }
            
            if (!Enum.IsDefined(typeof(MobileServiceAuthenticationProvider), provider)) 
            {
                throw new ArgumentOutOfRangeException("provider");
            }

            string providerName = provider.ToString().ToLower();

            this.LoginInProgress = true;

            TaskCompletionSource<MobileServiceUser> tcs = new TaskCompletionSource<MobileServiceUser> ();

            if (token != null)
            {
                // Invoke the POST endpoint to exchange provider-specific token for a Windows Azure Mobile Services token

                this.RequestAsync("POST", LoginAsyncUriFragment + "/" + providerName, token)
                    .ContinueWith (t =>
                    {
                        this.LoginInProgress = false;

                        if (t.IsCanceled)
                            tcs.SetCanceled();
                        else if (t.IsFaulted)
                            tcs.SetException (t.Exception.InnerExceptions);
                        else
                        {
                            SetupCurrentUser (t.Result);
                            tcs.SetResult (this.CurrentUser);
                        }
                    });
            }
            else
            {
                // Launch server side OAuth flow using the GET endpoint

                Uri startUri = new Uri(this.ApplicationUri, LoginAsyncUriFragment + "/" + providerName);
                Uri endUri = new Uri(this.ApplicationUri, LoginAsyncDoneUriFragment);

                WebRedirectAuthenticator auth = new WebRedirectAuthenticator (startUri, endUri);
                auth.ClearCookiesBeforeLogin = false;

                UIViewController c = auth.GetUI();

                UIViewController controller = null;
                UIPopoverController popover = null;

                auth.Error += (o, e) =>
                {
                    this.LoginInProgress = false;

                    if (controller != null)
                        controller.DismissModalViewControllerAnimated (true);
                    if (popover != null)
                        popover.Dismiss (true);

                    Exception ex = e.Exception ?? new Exception (e.Message);
                    tcs.TrySetException (ex);
                };
                
                auth.Completed += (o, e) =>
                {
                    this.LoginInProgress = false;

                    if (controller != null)
                        controller.DismissModalViewControllerAnimated (true);
                    if (popover != null)
                        popover.Dismiss (true);

                    if (!e.IsAuthenticated)
                        tcs.TrySetCanceled();
                    else
                    {
                        SetupCurrentUser (JsonValue.Parse (e.Account.Properties["token"]));
                        tcs.TrySetResult (this.CurrentUser);
                    }
                };

                controller = view as UIViewController;
                if (controller != null)
                {
                    controller.PresentModalViewController (c, true);
                }
                else
                {
                    UIView v = view as UIView;
                    UIBarButtonItem barButton = view as UIBarButtonItem;

                    popover = new UIPopoverController (c);

                    if (barButton != null)
                        popover.PresentFromBarButtonItem (barButton, UIPopoverArrowDirection.Any, true);
                    else
                        popover.PresentFromRect (rect, v, UIPopoverArrowDirection.Any, true);
                }
            }
            
            return tcs.Task;
        }
        private async Task <IAuth0User> SendLoginAsync(
            RectangleF rect,
            object view,
            string connection,
            bool withRefreshToken,
            string scope,
            string title)
        {
            // Launch server side OAuth flow using the GET endpoint
            scope = IncreaseScopeWithOfflineAccess(withRefreshToken, scope);

            var tcs  = new TaskCompletionSource <IAuth0User>();
            var auth = await GetAuthenticator(connection, scope, title);

            var c = auth.GetUI();

            var controller = view as UIViewController;
            UIPopoverController popover = null;

            auth.Error += (o, e) =>
            {
                controller?.DismissViewController(true, null);
                popover?.Dismiss(true);

                var ex = e.Exception ?? new AuthException(e.Message);
                tcs.TrySetException(ex);
            };

            auth.Completed += (o, e) =>
            {
                controller?.DismissViewController(true, null);
                popover?.Dismiss(true);

                if (!e.IsAuthenticated)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    SetupCurrentUser(e.Account.Properties);
                    tcs.TrySetResult(CurrentUser);
                }
            };

            if (controller != null)
            {
                controller.PresentViewController(c, true, null);
            }
            else
            {
                var v         = view as UIView;
                var barButton = view as UIBarButtonItem;
                popover = new UIPopoverController(c);

                if (barButton != null)
                {
                    popover.PresentFromBarButtonItem(barButton, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    popover.PresentFromRect(rect, v, UIPopoverArrowDirection.Any, true);
                }
            }

            return(await tcs.Task);
        }
		public InvoiceViewController ()
		{
			SetTitle ();
			Settings.Shared.SubscribeToProperty ("TestMode", SetTitle);
			var searchBar = new ItemSearchView{ Frame = new System.Drawing.RectangleF (0, 0, 200, 30) };
			searchBar.ItemSelected += (Item obj) => {
				Invoice.AddItem (obj);
			};
			NavigationItem.RightBarButtonItem = new UIBarButtonItem (searchBar);
			NavigationItem.LeftBarButtonItem = new UIBarButtonItem (UIImage.FromBundle ("menu").ImageWithRenderingMode (UIImageRenderingMode.AlwaysTemplate), UIBarButtonItemStyle.Plain, (s, e) => {
				//Show simple actionsheet
				if (sheet != null) {
					sheet.DismissWithClickedButtonIndex (-1, true);
					return;
				}
				sheet = new SimpleActionSheet { 
					{"New Invoice",async() =>{
							if(await AskSave())
								NewInvoice();
						}
					},
					{"Load Invoice",() => {
							if(popover != null)
							{
								popover.Dismiss(true);
							}
							popover = new UIPopoverController(new UINavigationController(new LoadInvoiceViewController(){
								InvoiceSelected = async (i) =>{
									popover.Dismiss(true);
									try{
										BigTed.BTProgressHUD.ShowContinuousProgress();
										if(Invoice != null && Invoice.Id != i.Id)
										{
											if(!await AskSave())
												return;
										}
										Invoice.DeleteLocal();
										Invoice = await WebService.Main.GetInvoice(i.Id);
										Invoice.Save(true);
									}
									catch(Exception ex)
									{
										Console.WriteLine(ex);
									}
									finally{
										BigTed.BTProgressHUD.Dismiss();
									}
								},
							}));
							popover.DidDismiss += (sender,  evt) => {
								popover.Dispose();
							};
							popover.PresentFromBarButtonItem(NavigationItem.LeftBarButtonItem, UIPopoverArrowDirection.Any,true);
						}
					},
					{"Payout Buy",() => {
							if(popover != null)
							{
								popover.Dismiss(true);
							}
							popover = new UIPopoverController(new UINavigationController(new LoadBuyPayoutViewController(){
								InvoiceSelected = async (i) =>{
									popover.Dismiss(true);
									try{
										BigTed.BTProgressHUD.ShowContinuousProgress();
										if(Invoice != null && Invoice.Id != i.Id)
										{
											if(!await AskSave())
												return;
										}
										Invoice.DeleteLocal();
										Invoice = await WebService.Main.GetInvoice(i.Id);
										//Setup payments
										Database.Main.Table<PaymentType> ().Where (x => x.IsActive)
											.OrderBy (X => X.SortOrder).ToList ().ForEach (x => Invoice.Payments.Add (new Payment{ PaymentType = x }));
										Invoice.Save(true);
										if((i as BuyInvoice).IsOnAccount)
											Invoice.OnAccountPayment.Amount = Invoice.Total;
										else
											Invoice.CashPayment.Amount = Invoice.Total;
									}
									catch(Exception ex)
									{
										Console.WriteLine(ex);
									}
									finally{
										BigTed.BTProgressHUD.Dismiss();
									}
								},
							}));
							popover.DidDismiss += (sender,  evt) => {
								popover.Dispose();
							};
							popover.PresentFromBarButtonItem(NavigationItem.LeftBarButtonItem, UIPopoverArrowDirection.Any,true);

						}
					},
					{"Settings",() => this.PresentViewControllerAsync (new UINavigationController (new SettingsViewController ()), true)},
				};
				sheet.Dismissed += (object sender, UIButtonEventArgs e2) => {
					sheet.Dispose ();
					sheet = null;
				};
				sheet.ShowFrom (s as UIBarButtonItem, true);
			});
		
			//this.AutomaticallyAdjustsScrollViewInsets = false;
		}
Beispiel #45
0
        public ImageViewController()
        {
            Title = "AirPic Demo";
            // on iOS 8.x we delegate the AirPlay feature to our Action extension
            bool ios8 = UIDevice.CurrentDevice.CheckSystemVersion (8,0);
            // the action extension will do the browsing for airplay capable devices
            AirPlayBrowser.Enabled = !ios8;

            var bounds = UIScreen.MainScreen.Bounds;
            image_view = new UIImageView (bounds);
            image_view.Image = UIImage.FromFile ("687px-Leontopithecus_rosalia_-_Copenhagen_Zoo_-_DSC09082.JPG");
            image_view.Image.Scale (bounds.Size);
            Add (image_view);

            UIBarButtonItem action = null;
            action = new UIBarButtonItem (UIBarButtonSystemItem.Action, delegate {
                if (image_view.Image == null)
                    return;
                // UIActivity is only for iOS6+ but that should not limit us :-)
                if (UIDevice.CurrentDevice.CheckSystemVersion (6,0)) {
                    var activities = AirPlayBrowser.Enabled ? UIAirPlayActivity.GetCurrentActivities () : null;
                    var a = new UIActivityViewController (new [] { image_view.Image }, activities);
                    if (AppDelegate.RunningOnIPad) {
                        popup = new UIPopoverController (a);
                        popup.PresentFromBarButtonItem (action, UIPopoverArrowDirection.Up, true);
                    } else {
                        PresentViewController (a, true, null);
                    }
                } else {
                    var devices = AirPlayBrowser.GetDeviceNames ();
                    var a = new UIActionSheet (null, null, "Cancel", null, devices);
                    a.Clicked += (sender, e) => {
                        nint index = e.ButtonIndex;
                        // ignore Cancel button
                        if (index < devices.Length) {
                            var device = AirPlayBrowser.GetDevice (devices [index]);
                            if (device != null) // they can disappear anytime
                                device.SendTo (image_view.Image, null);
                        }
                    };
                    a.ShowFrom (NavigationItem.RightBarButtonItem, true);
                }
            });
            NavigationItem.RightBarButtonItem = action;
        }
        private Task <Auth0User> SendLoginAsync(RectangleF rect, object view, string connection, string scope)
        {
            // Launch server side OAuth flow using the GET endpoint
            var tcs  = new TaskCompletionSource <Auth0User> ();
            var auth = this.GetAuthenticator(connection, scope);

            UIViewController c = auth.GetUI();

            UIViewController    controller = null;
            UIPopoverController popover    = null;

            auth.Error += (o, e) =>
            {
                if (controller != null)
                {
                    controller.DismissViewController(true, null);
                }

                if (popover != null)
                {
                    popover.Dismiss(true);
                }

                var ex = e.Exception ?? new AuthException(e.Message);
                tcs.TrySetException(ex);
            };

            auth.Completed += (o, e) =>
            {
                if (controller != null)
                {
                    controller.DismissViewController(true, null);
                }

                if (popover != null)
                {
                    popover.Dismiss(true);
                }

                if (!e.IsAuthenticated)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    this.SetupCurrentUser(e.Account.Properties);
                    tcs.TrySetResult(this.CurrentUser);
                }
            };

            controller = view as UIViewController;
            if (controller != null)
            {
                controller.PresentViewController(c, true, null);
            }
            else
            {
                UIView          v         = view as UIView;
                UIBarButtonItem barButton = view as UIBarButtonItem;

                popover = new UIPopoverController(c);

                if (barButton != null)
                {
                    popover.PresentFromBarButtonItem(barButton, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    popover.PresentFromRect(rect, v, UIPopoverArrowDirection.Any, true);
                }
            }

            return(tcs.Task);
        }