private void Present(UIAlertController controller) { this.Dispatch(() => { var top = Utils.GetTopViewController(); top.PresentViewController(controller, true, null); }); }
public override void ViewDidLoad() { uploadVideo.Enabled = false; pickerController = new UIImagePickerController(); pickerController.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; pickerController.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); pickerController.FinishedPickingMedia += finishPickImage; pickerController.Canceled += cancelImagePicker; selectVideo.TouchUpInside += (sender, e) => PresentViewController (pickerController, true, null); uploadVideo.TouchUpInside += (sender, e) => { uploadResult = new CISolution.CloudinaryHelper().uploadVideo(fd); if(uploadResult.Error == null) { alertController = UIAlertController.Create("Success", uploadResult.JsonObj.ToString(), UIAlertControllerStyle.ActionSheet); } else { alertController = UIAlertController.Create("Error", uploadResult.Error.Message, UIAlertControllerStyle.ActionSheet); } alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(alertController,true,null); uploadVideo.Enabled = false; }; }
public override void ViewDidLoad () { base.ViewDidLoad (); if (TraitCollection.ForceTouchCapability == UIForceTouchCapability.Available) RegisterForPreviewingWithDelegate (this, View); else alertController = UIAlertController.Create ("3D Touch Not Available", "Unsupported device.", UIAlertControllerStyle.Alert); }
public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection) { //Important: Must call base method base.TraitCollectionDidChange(previousTraitCollection); if (TraitCollection.ForceTouchCapability == UIForceTouchCapability.Available) RegisterForPreviewingWithDelegate (this, View); else alertController = UIAlertController.Create ("3D Touch Not Available", "Unsupported device.", UIAlertControllerStyle.Alert); }
public override void ViewDidAppear (bool animated) { base.ViewDidAppear (animated); if (alertController == null) return; alertController.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Default, null)); PresentViewController (alertController, true, null); alertController = null; }
partial void letUsKnowClicked (UIButton sender) { if (MFMailComposeViewController.CanSendMail) { var mailComposeViewController = configuredMailComposeViewController(); PresentViewController(mailComposeViewController, true, null); } else { var sendMailErrorController = new UIAlertController { Title = "Could Not Send Email", Message = "Your device could not send e-mail. Please check e-mail configuration and try again." }; PresentViewController(sendMailErrorController, true, null); } }
private void DismissAll() { UIApplication.SharedApplication.InvokeOnMainThread(() => { if (alertView != null) { alertView.DismissWithClickedButtonIndex(-1, false); alertView.Dispose(); alertView = null; } if (modalViewController != null) { modalViewController.DismissViewController(false, null); modalViewController.Dispose(); modalViewController = null; } if (alertController != null) { alertController.DismissViewController(false, null); alertController.Dispose(); alertController = null; } }); }
public Task <string> DisplayPromptAync(string title = null, string description = null, string text = null) { var result = new TaskCompletionSource <string>(); var alert = UIAlertController.Create(title ?? string.Empty, description, UIAlertControllerStyle.Alert); UITextField input = null; alert.AddAction(UIAlertAction.Create(AppResources.Cancel, UIAlertActionStyle.Cancel, x => { result.TrySetResult(null); })); alert.AddAction(UIAlertAction.Create(AppResources.Ok, UIAlertActionStyle.Default, x => { result.TrySetResult(input.Text ?? string.Empty); })); alert.AddTextField(x => { input = x; input.Text = text ?? string.Empty; }); var vc = GetPresentedViewController(); vc?.PresentViewController(alert, true, null); return(result.Task); }
partial void UIButton342_TouchUpInside(UIButton sender) { if (string.IsNullOrEmpty(this.EmailText.Text)) { var alert = UIAlertController.Create("Error", "You must enter an email.", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Accept", UIAlertActionStyle.Default, null)); this.PresentViewController(alert, true, null); return; } if (string.IsNullOrEmpty(this.PasswordText.Text)) { var alert = UIAlertController.Create("Error", "You must enter a password.", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Accept", UIAlertActionStyle.Default, null)); this.PresentViewController(alert, true, null); return; } //var ok = UIAlertController.Create("Ok", "F**k yeah!", UIAlertControllerStyle.Alert); //ok.AddAction(UIAlertAction.Create("Accept", UIAlertActionStyle.Default, null)); //this.PresentViewController(ok, true, null); this.DoLogin(); }
public override void Prompt(PromptConfig config) { var result = new PromptResult(); var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert); UITextField txt = null; dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => { result.Ok = true; result.Text = txt.Text.Trim(); config.OnResult(result); })); dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Default, x => { result.Ok = false; result.Text = txt.Text.Trim(); config.OnResult(result); })); dlg.AddTextField(x => { x.SecureTextEntry = config.InputType == InputType.Password; x.Placeholder = config.Placeholder ?? String.Empty; x.KeyboardType = Utils.GetKeyboardType(config.InputType); txt = x; }); this.Present(dlg); }
private void PickTime(string index) { postid = index; try { Lab_city.Text = "city: " + weather.cityname; Lab_date.Text = "date: " + weather.data[index.ToString()]["date"]; Lab_time.Text = "time: " + weather.data[index.ToString()]["time"]; Lab_MaxTemperature.Text = "maxTemperature: " + weather.data[index.ToString()]["maxTemperature"]; Lab_MinTemperature.Text = "minTemperature: " + weather.data[index.ToString()]["minTemperature"]; Console.WriteLine("Response 11111"); } catch (Exception e) { Console.WriteLine(e); UIAlertController actionSheetAlertdate = UIAlertController.Create("error", "沒發現該時段資料", UIAlertControllerStyle.ActionSheet); UIPopoverPresentationController presentationPopover2 = actionSheetAlertdate.PopoverPresentationController; if (presentationPopover2 != null) { presentationPopover2.SourceView = this.View; presentationPopover2.PermittedArrowDirections = UIPopoverArrowDirection.Up; } this.PresentViewController(actionSheetAlertdate, true, null); Lab_city.Text = "city: " + weather.cityname; Lab_date.Text = "date: " + weather.data["0"]["date"]; Lab_time.Text = "time: " + weather.data["0"]["time"]; Lab_MaxTemperature.Text = "maxTemperature: " + weather.data["0"]["maxTemperature"]; Lab_MinTemperature.Text = "minTemperature: " + weather.data["0"]["minTemperature"]; Console.WriteLine("Response 11111"); } }
partial void EditAsset(UIBarButtonItem sender) { // Use a UIAlertController to display editing options to the user. var alertController = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet); #if !__TVOS__ alertController.ModalPresentationStyle = UIModalPresentationStyle.Popover; var popoverController = alertController.PopoverPresentationController; if (popoverController != null) { popoverController.BarButtonItem = sender; popoverController.PermittedArrowDirections = UIPopoverArrowDirection.Up; } #endif // Add a Cancel action to dismiss the alert without doing anything. alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); // Allow editing only if the PHAsset supports edit operations. if (Asset.CanPerformEditOperation(PHAssetEditOperation.Content)) { // Add actions for some canned filters. alertController.AddAction(UIAlertAction.Create("Sepia Tone", UIAlertActionStyle.Default, _ => { ApplyFilter(new CISepiaTone()); })); alertController.AddAction(UIAlertAction.Create("Chrome", UIAlertActionStyle.Default, _ => { ApplyFilter(new CIPhotoEffectChrome()); })); // Add actions to revert any edits that have been made to the PHAsset. alertController.AddAction(UIAlertAction.Create("Revert", UIAlertActionStyle.Default, RevertAsset)); } // Present the UIAlertController. PresentViewController(alertController, true, null); }
public void RunJavaScriptTextInputPanel(WKWebView webView, string prompt, string defaultText, WebKit.WKFrameInfo frame, System.Action <string> completionHandler) { var alertController = UIAlertController.Create(null, prompt, UIAlertControllerStyle.Alert); UITextField alertTextField = null; alertController.AddTextField(textField => { textField.Placeholder = defaultText; alertTextField = textField; }); alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => { completionHandler(alertTextField.Text); })); alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => { completionHandler(null); })); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null); }
public void ShowDialogWithTextField(string text, string textFieldPlaceholder, bool isSecureField, string negativeButton, string positiveButton, Action <string> positiveAction) { var bundle = Locator.Current.GetService <NSBundle>(); UIAlertController alert = UIAlertController.Create(null, bundle.GetLocalizedString(text), UIAlertControllerStyle.Alert); UIAlertAction okAction = UIAlertAction.Create(bundle.GetLocalizedString(positiveButton), UIAlertActionStyle.Default, (o) => { alert.DismissViewController(false, null); positiveAction?.Invoke(alert.TextFields[0]?.Text); }); UIAlertAction cancelAction = UIAlertAction.Create(bundle.GetLocalizedString(negativeButton), UIAlertActionStyle.Cancel, (o) => { alert.DismissViewController(false, null); }); alert.AddAction(okAction); alert.AddAction(cancelAction); alert.AddTextField((textField) => { textField.Placeholder = textFieldPlaceholder; textField.SecureTextEntry = isSecureField; }); PresentViewController(alert, false, null); }
private void GridColorButton_Click(object sender, EventArgs e) { // Create the view controller that will present the list of grid color options. UIAlertController gridColorAlert = UIAlertController.Create("Select a grid color", "", UIAlertControllerStyle.ActionSheet); // Needed to prevent a crash on iPad. UIPopoverPresentationController presentationPopover = gridColorAlert.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Add an option for each color. foreach (Colors item in new[] { Colors.Red, Colors.Green, Colors.Blue, Colors.White }) { // Record the selection and re-apply all settings. gridColorAlert.AddAction(UIAlertAction.Create(item.Name, UIAlertActionStyle.Default, action => { _selectedGridColor = item; ApplyCurrentSettings(); })); } // Add an option to hide the grid. gridColorAlert.AddAction(UIAlertAction.Create("Hide the grid", UIAlertActionStyle.Default, action => { // Record the selection and re-apply all settings. _selectedGridColor = null; ApplyCurrentSettings(); })); // Show the alert. PresentViewController(gridColorAlert, true, null); }
private void DownloadButton_Click(object sender, EventArgs e) { // Create the alert controller. UIAlertController mapAreaSelectionAlertController = UIAlertController.Create("Map Area Selection", "Select a map area to download and show.", UIAlertControllerStyle.ActionSheet); // Add one action per map area. foreach (PreplannedMapArea area in _preplannedMapAreas) { mapAreaSelectionAlertController.AddAction(UIAlertAction.Create(area.PortalItem.Title, UIAlertActionStyle.Default, action => { // Download and show the selected map area. OnDownloadMapAreaClicked(action.Title); })); } // Needed to prevent a crash on iPad. UIPopoverPresentationController presentationPopover = mapAreaSelectionAlertController.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Display the alert. PresentViewController(mapAreaSelectionAlertController, true, null); // Remove the startup prompt if it hasn't been removed already. if (_initialPrompt != null) { _initialPrompt.RemoveFromSuperview(); _initialPrompt = null; } }
private async void RegisterButton_TouchUpInside(object sender, EventArgs e) { if (!string.IsNullOrEmpty(passwordTextField.Text)) { if (passwordTextField.Text == confirmPasswordTextField.Text) { var user = new User() { Email = emailTextField.Text, Password = passwordTextField.Text }; await AppDelegate.MobileService.GetTable <User>().InsertAsync(user); var alert = UIAlertController.Create("Success", "User inserted", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } } }
EventHandler DatePickerPopUp(UIButton btnLabel) { return((sender, e) => { var swithView = new UIDatePicker { Mode = UIDatePickerMode.Date, Frame = new CGRect(10, 5, 250, 160) }; var alert = UIAlertController.Create("\n\n\n", "\n\n\n", UIAlertControllerStyle.Alert); alert.Add(swithView); alert.AddAction(UIAlertAction.Create("Cancelar", UIAlertActionStyle.Cancel, (actionCancel) => { MetricsManager.TrackEvent("CancelDatePicker"); })); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, (actionOK) => { var date = (DateTime)swithView.Date; btnLabel.SetTitle(date.ToString("d"), UIControlState.Normal); })); alert.View.TintColor = UIColor.FromRGB(10, 88, 90); UiView.PresentViewController(alert, true, null); }); }
private void ShowMissionOptions(object sender, EventArgs eventArgs) { // Create the view controller that will present the list of missions. UIAlertController missionSelectionAlert = UIAlertController.Create("Select a mission", "", UIAlertControllerStyle.ActionSheet); // Needed to prevent a crash on iPad. UIPopoverPresentationController presentationPopover = missionSelectionAlert.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Add an option for each mission. foreach (string item in _missionToItemId.Keys) { // Selecting the mission will call the ChangeMission method. missionSelectionAlert.AddAction(UIAlertAction.Create(item, UIAlertActionStyle.Default, async action => await ChangeMission(item))); } // Show the alert. PresentViewController(missionSelectionAlert, true, null); }
//handles button click depending on action void btnActionTouchUpInside(object sender, EventArgs e) { if (add) { UIAlertController actionSheetAlert = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet); foreach (Profiel p in _appController.DistinctProfielen) { actionSheetAlert.AddAction(UIAlertAction.Create(p.name, UIAlertActionStyle.Default, action => addToProfile(p.name))); } actionSheetAlert.AddAction(UIAlertAction.Create("Nieuw profiel", UIAlertActionStyle.Default, action => addProfileDialog())); actionSheetAlert.AddAction(UIAlertAction.Create("Annuleer", UIAlertActionStyle.Cancel, null)); // Required for iPad - You must specify a source for the Action Sheet since it is // displayed as a popover UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = imgAction; presentationPopover.SourceRect = new RectangleF(0, 0, 25, 25); presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } PresentViewController(actionSheetAlert, true, null); } else { var okCancelAlertController = UIAlertController.Create(null, _appController.CurrentTotem.title + " verwijderen uit profiel " + _appController.CurrentProfiel.name + "?", UIAlertControllerStyle.Alert); okCancelAlertController.AddAction(UIAlertAction.Create("Ja", UIAlertActionStyle.Default, alert => deleteFromProfile())); okCancelAlertController.AddAction(UIAlertAction.Create("Nee", UIAlertActionStyle.Cancel, null)); PresentViewController(okCancelAlertController, true, null); } }
private void buttonOKClicked(UIAlertController textInputAlertController) { Database_interaction db = new Database_interaction(); db.AddBudget(new Budget(float.Parse(textInputAlertController.TextFields[0].Text), DateTime.Now)); Budget budget = db.GetBudget(DateTime.Now); float totalcost = db.GetTotalCostMonth(DateTime.Now); if (budget != null) { lblmonth.Text = "This Month's Budget: " + budget.BudgetAmount.ToString(); lblRemaining.Text = "Remaining Budget: " + (budget.BudgetAmount - totalcost).ToString(); lblTotalCost.Text = "Total Cost This Month: " + totalcost.ToString(); } else { lblmonth.Text = "This Month's Budget: Not Set"; lblRemaining.Text = "Remaining Budget: 0"; lblTotalCost.Text = "Total Cost This Month: 0"; } }
protected virtual IDisposable Present(Func <UIAlertController> alertFunc) { UIAlertController alert = null; var app = UIApplication.SharedApplication; app.SafeInvokeOnMainThread(() => { alert = alertFunc(); var top = this.viewControllerFunc(); if (alert.PreferredStyle == UIAlertControllerStyle.ActionSheet && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { var x = top.View.Bounds.Width / 2; var y = top.View.Bounds.Bottom; var rect = new CGRect(x, y, 0, 0); #if __IOS__ alert.PopoverPresentationController.SourceView = top.View; alert.PopoverPresentationController.SourceRect = rect; alert.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Unknown; #endif } top.PresentViewController(alert, true, null); }); return(new DisposableAction(() => app.SafeInvokeOnMainThread(() => alert.DismissViewController(true, null)))); }
private void selectTime(int index) { // Create a new Alert Controller UIAlertController actionSheetAlertTime = UIAlertController.Create("選擇時間", "是要哪個時段呢?", UIAlertControllerStyle.ActionSheet); // Add Actions actionSheetAlertTime.AddAction(UIAlertAction.Create("早上", UIAlertActionStyle.Default, (action) => PickTime((index + 2).ToString()))); actionSheetAlertTime.AddAction(UIAlertAction.Create("中午", UIAlertActionStyle.Default, (action) => PickTime((index + 4).ToString()))); actionSheetAlertTime.AddAction(UIAlertAction.Create("晚上", UIAlertActionStyle.Default, (action) => PickTime((index + 6).ToString()))); actionSheetAlertTime.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (action) => Console.WriteLine("Cancel button pressed."))); UIPopoverPresentationController presentationPopover = actionSheetAlertTime.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = this.View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Display the alert this.PresentViewController(actionSheetAlertTime, true, null); }
private void ButtonAddItem_Clicked(object sender, EventArgs e) { // https://developer.xamarin.com/recipes/ios/standard_controls/alertcontroller/#ActionSheet_Alert UIAlertController actionSheetAlert = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet); actionSheetAlert.AddAction(UIAlertAction.Create("Add Task", UIAlertActionStyle.Default, delegate { ViewModel.AddTask(); })); actionSheetAlert.AddAction(UIAlertAction.Create("Add Event", UIAlertActionStyle.Default, delegate { ViewModel.AddEvent(); })); actionSheetAlert.AddAction(UIAlertAction.Create("Add Holiday", UIAlertActionStyle.Default, delegate { ViewModel.AddHoliday(); })); actionSheetAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); // Required for iPad - You must specify a source for the Action Sheet since it is // displayed as a popover UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.BarButtonItem = NavItem.RightBarButtonItem; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Display the alert this.PresentViewController(actionSheetAlert, true, null); }
void DeleteBarButtonItemClicked(object sender, EventArgs ea) { UIAlertController alert = UIAlertController.Create( "Delete?", $"Are you sure you want to delete {Acquaintance.FirstName} {Acquaintance.LastName}?", UIAlertControllerStyle.Alert); // cancel button alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); // delete button alert.AddAction(UIAlertAction.Create("Delete", UIAlertActionStyle.Destructive, async(action) => { if (action != null) { await _DataSource.RemoveItem(Acquaintance); NavigationController.PopViewController(true); } })); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null); }
private async void mapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { Exception error = null; try { var result = await mapView.IdentifyLayersAsync(e.Position, 3, false); // Retrieves or builds Popup from IdentifyLayerResult var popup = GetPopup(result); // Displays callout and on (i) button click shows PopupViewer in it's own view controller if (popup != null) { var callout = new CalloutDefinition(popup.GeoElement); callout.Tag = popup; callout.ButtonImage = InfoIcon; callout.OnButtonClick = new Action <object>((s) => { var pvc = new PopupInfoViewController(popup); this.PresentModalViewController(pvc, true); }); mapView.ShowCalloutForGeoElement(popup.GeoElement, e.Position, callout); } } catch (Exception ex) { error = ex; } if (error != null) { var alert = UIAlertController.Create(error.GetType().Name, error.Message, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); this.PresentViewController(alert, true, null); } }
public override void ReceivedForegroundNotification(UANotificationContent notificationContent, Action completionHandler) { // Application received a foreground notification Console.WriteLine("The application received a foreground notification"); // iOS 10 - let foreground presentations options handle it if (NSProcessInfo.ProcessInfo.IsOperatingSystemAtLeastVersion(new NSOperatingSystemVersion(10, 0, 0))) { completionHandler(); return; } UIAlertController alertController = UIAlertController.Create(title: notificationContent.AlertTitle, message: notificationContent.AlertBody, preferredStyle: UIAlertControllerStyle.Alert); UIAlertAction okAction = UIAlertAction.Create(title: "OK", style: UIAlertActionStyle.Default, handler: (UIAlertAction action) => { NSString messageID = UAInboxUtils.InboxMessageIDFromNotification(notificationContent.NotificationInfo); if (messageID != null) { UAActionRunner.RunAction("open_mc_action", messageID, UASituation.ManualInvocation); } }); alertController.AddAction(okAction); UIViewController topController = UIApplication.SharedApplication.KeyWindow.RootViewController; alertController.PopoverPresentationController.SourceView = topController.View; topController.PresentViewController(alertController, true, null); completionHandler(); }
private void CreateAlert(string title, string message, string[] inputs, Action <List <string> > completeHandler) { var okAlertController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert); for (int i = 0; i < inputs.Length; i++) { okAlertController.AddTextField((obj) => { obj.Font = UIFont.SystemFontOfSize(20); obj.TextAlignment = UITextAlignment.Center; obj.Placeholder = inputs[i]; }); } okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, (alert) => { var resultArray = new List <string>(); resultArray.AddRange(okAlertController.TextFields.Select(a => a.Text).ToList()); completeHandler.Invoke(resultArray); })); // Present Alert owner.PresentViewController(okAlertController, true, null); }
private void ShowBasemapList() { // Create a new Alert Controller. UIAlertController basemapsActionSheet = UIAlertController.Create("Basemaps", "Choose a basemap", UIAlertControllerStyle.ActionSheet); // Add actions to apply each basemap type. basemapsActionSheet.AddAction(UIAlertAction.Create("Topographic", UIAlertActionStyle.Default, action => _myMapView.Map.Basemap = Basemap.CreateTopographic())); basemapsActionSheet.AddAction(UIAlertAction.Create("Streets", UIAlertActionStyle.Default, action => _myMapView.Map.Basemap = Basemap.CreateStreets())); basemapsActionSheet.AddAction(UIAlertAction.Create("Imagery", UIAlertActionStyle.Default, action => _myMapView.Map.Basemap = Basemap.CreateImagery())); basemapsActionSheet.AddAction(UIAlertAction.Create("Oceans", UIAlertActionStyle.Default, action => _myMapView.Map.Basemap = Basemap.CreateOceans())); basemapsActionSheet.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, action => Console.WriteLine("Canceled"))); // Required for iPad - You must specify a source for the Action Sheet since it is displayed as a popover. UIPopoverPresentationController presentationPopover = basemapsActionSheet.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } // Display the list of basemaps. PresentViewController(basemapsActionSheet, true, null); }
public override IDisposable Login(LoginConfig config) { UITextField txtUser = null; UITextField txtPass = null; var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert); dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x => config.OnAction(new LoginResult(false, txtUser.Text, txtPass.Text)))); dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => config.OnAction(new LoginResult(true, txtUser.Text, txtPass.Text)))); dlg.AddTextField(x => { txtUser = x; x.Placeholder = config.LoginPlaceholder; x.Text = config.LoginValue ?? String.Empty; }); dlg.AddTextField(x => { txtPass = x; x.Placeholder = config.PasswordPlaceholder; x.SecureTextEntry = true; }); return(this.Present(dlg)); }
public Task ShowLoadingAsync(string text) { if (_progressAlert != null) { HideLoadingAsync().GetAwaiter().GetResult(); } var result = new TaskCompletionSource <int>(); var loadingIndicator = new UIActivityIndicatorView(new CGRect(10, 5, 50, 50)); loadingIndicator.HidesWhenStopped = true; loadingIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray; loadingIndicator.StartAnimating(); _progressAlert = UIAlertController.Create(null, text, UIAlertControllerStyle.Alert); _progressAlert.View.TintColor = UIColor.Black; _progressAlert.View.Add(loadingIndicator); var vc = GetPresentedViewController(); vc?.PresentViewController(_progressAlert, false, () => result.TrySetResult(0)); return(result.Task); }
public Task <string> DisplayPromptAync(string title = null, string description = null, string text = null, string okButtonText = null, string cancelButtonText = null, bool numericKeyboard = false, bool autofocus = true) { var result = new TaskCompletionSource <string>(); var alert = UIAlertController.Create(title ?? string.Empty, description, UIAlertControllerStyle.Alert); UITextField input = null; okButtonText = okButtonText ?? AppResources.Ok; cancelButtonText = cancelButtonText ?? AppResources.Cancel; alert.AddAction(UIAlertAction.Create(cancelButtonText, UIAlertActionStyle.Cancel, x => { result.TrySetResult(null); })); alert.AddAction(UIAlertAction.Create(okButtonText, UIAlertActionStyle.Default, x => { result.TrySetResult(input.Text ?? string.Empty); })); alert.AddTextField(x => { input = x; input.Text = text ?? string.Empty; if (numericKeyboard) { input.KeyboardType = UIKeyboardType.NumberPad; } if (!ThemeHelpers.LightTheme) { input.KeyboardAppearance = UIKeyboardAppearance.Dark; } }); var vc = GetPresentedViewController(); vc?.PresentViewController(alert, true, null); return(result.Task); }
public async Task <bool> ShowCheckboxDialogAsync(string title, string content, string checkboxTitle, string confirm = "Ok") { UIAlertController actionSheetAlert = UIAlertController.Create(title, content, UIAlertControllerStyle.ActionSheet); TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>(); // Add Actions actionSheetAlert.AddAction(UIAlertAction.Create(confirm, UIAlertActionStyle.Default, (action) => taskCompletionSource.TrySetResult(false))); actionSheetAlert.AddAction(UIAlertAction.Create(checkboxTitle, UIAlertActionStyle.Default, (action) => taskCompletionSource.TrySetResult(true))); var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; while (vc.PresentedViewController != null) { vc = vc.PresentedViewController; } // Required for iPad - You must specify a source for the Action Sheet since it is // displayed as a popover UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = vc.View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } vc.PresentViewController(actionSheetAlert, true, null); var res = await taskCompletionSource.Task; return(res); }
void PresentPrompt(PromptArguments arguments) { var window = new UIWindow { BackgroundColor = Colors.Transparent.ToUIColor() }; var alert = UIAlertController.Create(arguments.Title, arguments.Message, UIAlertControllerStyle.Alert); alert.AddTextField(uiTextField => { uiTextField.Placeholder = arguments.Placeholder; uiTextField.Text = arguments.InitialValue; uiTextField.ShouldChangeCharacters = (field, range, replacementString) => arguments.MaxLength <= -1 || field.Text.Length + replacementString.Length - range.Length <= arguments.MaxLength; uiTextField.ApplyKeyboard(arguments.Keyboard); }); var oldFrame = alert.View.Frame; alert.View.Frame = new CGRect(oldFrame.X, oldFrame.Y, oldFrame.Width, oldFrame.Height - _alertPadding * 2); alert.AddAction(CreateActionWithWindowHide(arguments.Cancel, UIAlertActionStyle.Cancel, () => arguments.SetResult(null), window)); alert.AddAction(CreateActionWithWindowHide(arguments.Accept, UIAlertActionStyle.Default, () => arguments.SetResult(alert.TextFields[0].Text), window)); PresentPopUp(window, alert); }
public Task <string> DisplayAlertAsync(string title, string message, string cancel, params string[] buttons) { var result = new TaskCompletionSource <string>(); var alert = UIAlertController.Create(title ?? string.Empty, message, UIAlertControllerStyle.Alert); if (!string.IsNullOrWhiteSpace(cancel)) { alert.AddAction(UIAlertAction.Create(cancel, UIAlertActionStyle.Cancel, x => { result.TrySetResult(cancel); })); } foreach (var button in buttons) { alert.AddAction(UIAlertAction.Create(button, UIAlertActionStyle.Default, x => { result.TrySetResult(button); })); } var vc = GetPresentedViewController(); vc?.PresentViewController(alert, true, null); return(result.Task); }
void backTouched() { var option_back = UIAlertController.Create("Выйти без сохранения введенных данных?", null, UIAlertControllerStyle.ActionSheet); option_back.AddAction(UIAlertAction.Create("Подтвердить", UIAlertActionStyle.Default, (action) => this.NavigationController.PopViewController(true))); option_back.AddAction(UIAlertAction.Create("Отмена", UIAlertActionStyle.Cancel, null /*, (action) => Console.WriteLine("Cancel button pressed.")*/)); if (PersonalDataViewControllerNew.images_list != null) { if (PersonalDataViewControllerNew.images_list.Count > 0) { this.PresentViewController(option_back, true, null); return; } } if (changedSomething) { this.PresentViewController(option_back, true, null); return; } this.NavigationController.PopViewController(true); }
void BtnAceptar_TouchUpOutside(object sender, EventArgs e) { var pass1 = ""; pass1 = txtContrasenia.Text; var pass2 = ""; pass2 = txtVerificarContrasenia.Text; var correo = ""; correo = txtCorreo.Text; if (pass1 != "" && pass2 != "" && correo != "") { if (pass1.Equals(pass2)) { Auth.DefaultInstance.CreateUser(correo, pass1, HandleAuthResult); } else { //Create Alert var okAlertController = UIAlertController.Create("Error", "Contraseñas diferentes", UIAlertControllerStyle.Alert); //Add Action okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); // Present Alert PresentViewController(okAlertController, true, null); } } else { UIAlertView _error = new UIAlertView("Campos vacios", "Favor de no dejar campos vacios", null, "Ok", null); _error.Show(); } }
void InputActionSheet(Action<SelectionItem> selection, List<SelectionItem> options, string cancelButton = "Cancel") { DismissAll(); UIApplication.SharedApplication.InvokeOnMainThread(() => { alertController = new UIAlertController(); //alertController.ModalPresentationStylePreferredStyle = UIAlertControllerStyle.ActionSheet; foreach (var option in options) { var action = UIAlertAction.Create(option.Title, UIAlertActionStyle.Default, (a) => { selection(options.FirstOrDefault(x => x.Title == a.Title)); }); alertController.AddAction(action); } //cancel var cancel = UIAlertAction.Create(cancelButton, UIAlertActionStyle.Default, (a) => { selection(null); }); alertController.AddAction(cancel); var topViewController = TopViewControllerWithRootViewController(UIApplication.SharedApplication.KeyWindow.RootViewController); topViewController.PresentViewController(alertController, true, null); }); }
protected virtual void Present(UIAlertController alert) { //UIApplication.SharedApplication.Present(alert); }
protected virtual void AddActionSheetOption(ActionSheetOption opt, UIAlertController controller, UIAlertActionStyle style, IBitmap image = null) { var alertAction = UIAlertAction.Create(opt.Text, style, x => opt.Action?.Invoke()); if (opt.ItemIcon == null && image != null) opt.ItemIcon = image; if (opt.ItemIcon != null) alertAction.SetValueForKey(opt.ItemIcon.ToNative(), new Foundation.NSString("image")); controller.AddAction(alertAction); }
private void createUI () { Version version = new Version (UIDevice.CurrentDevice.SystemVersion); if (this.alertType == ALERT_TYPE.DEFAULT || version < new Version (8, 0)) { this.alert7 = new UIAlertView (this.title, this.message, null, this.cancelButtonTitle, new string[] { this.okButtonTitle }); this.alert7.Clicked += (object sender, UIButtonEventArgs e) => { if (e.ButtonIndex == 0) { // cancel clicked if (this.cancelButtonTitle == null) { okClicked (this); } else { cancelClicked (this); } } else if (e.ButtonIndex == 1) { // okClicked okClicked (this); } }; if (this.customView != null) this.alert7.SetValueForKey (this.customView, new NSString ("accessoryView")); } else { if (this.customView != null) { string tMessage = ""; CGSize size = CGSize.Empty; if (customView is TCMessageView) { size = MUtils.getSizeText (this.customView.ToString (), MUtils.getFontWithSize (false, 14.0f), this.customView.Frame.Width); } else { size = this.customView.Frame.Size; } CGSize sizeAText = MUtils.getSizeWithALineText (MUtils.getFontWithSize (false, 14.0f)); for (int i = 0; i < size.Height / sizeAText.Height ; i++) { tMessage += "\r"; } this.message = tMessage + message; CGSize sizeATitle = MUtils.getSizeText (this.title, MUtils.getFontWithSize (true, 16.0f), 220); this.alert8 = UIAlertController.Create (this.title, this.message, UIAlertControllerStyle.Alert); nfloat heighTitle = sizeATitle.Height > 30.0f ? sizeATitle.Height * 2 : sizeATitle.Height * 3; this.customView.Frame = new CGRect (10.0f, heighTitle, this.customView.Frame.Width, this.customView.Frame.Height); this.alert8.View.AddSubview (this.customView); } else { this.alert8 = UIAlertController.Create (this.title, this.message, UIAlertControllerStyle.Alert); } if (this.cancelButtonTitle != null && !this.cancelButtonTitle.Equals ("")) { UIAlertAction cancelAction = UIAlertAction.Create (this.cancelButtonTitle, UIAlertActionStyle.Cancel, cancelClicked); this.alert8.AddAction (cancelAction); } if (this.okButtonTitle != null && !this.okButtonTitle.Equals ("")) { UIAlertAction okAction = UIAlertAction.Create (this.okButtonTitle, UIAlertActionStyle.Default, okClicked); this.alert8.AddAction (okAction); } } }
protected virtual void Present(UIAlertController alert) { UIApplication.SharedApplication.InvokeOnMainThread(() => { var top = this.GetTopViewController(); if (alert.PopoverPresentationController != null) { var x = top.View.Bounds.Width / 2; var y = top.View.Bounds.Bottom; var rect = new CGRect(x, y, 0, 0); alert.PopoverPresentationController.SourceView = top.View; alert.PopoverPresentationController.SourceRect = rect; alert.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Unknown; } top.PresentViewController(alert, true, null); }); }
protected virtual void AddActionSheetOption(ActionSheetOption opt, UIAlertController controller, UIAlertActionStyle style) { controller.AddAction(UIAlertAction.Create(opt.Text, style, x => opt.TryExecute())); }
/// <summary> /// Shows the context menu in the preferred placement relative to the specified selection. /// </summary> /// <param name="selection">The coordinates (in DIPs) of the selected rectangle, relative to the window.</param> /// <param name="preferredPlacement">The preferred placement of the context menu relative to the selection rectangle.</param> /// <returns></returns> public Task<IUICommand> ShowForSelectionAsync(Rect selection, Placement preferredPlacement) { if (Commands.Count > MaxCommands) { throw new InvalidOperationException(); } #if WINDOWS_UWP return Task.Run<IUICommand>(async () => { foreach (IUICommand command in Commands) { _menu.Commands.Add(new Windows.UI.Popups.UICommand(command.Label, new Windows.UI.Popups.UICommandInvokedHandler((c2) => { command.Invoked?.Invoke(command); }), command.Id)); } Windows.Foundation.Rect r = new Windows.Foundation.Rect(selection.X, selection.Y, selection.Width, selection.Height); var c = await _menu.ShowForSelectionAsync(r, (Windows.UI.Popups.Placement)((int)preferredPlacement)); return c == null ? null : new UICommand(c.Label, new UICommandInvokedHandler((c2) => { c2.Invoked?.Invoke(c2); }), c.Id); }); #elif __ANDROID__ Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity); Android.App.AlertDialog dialog = builder.Create(); dialog.SetTitle(Title); dialog.SetMessage(Content); if (Commands.Count == 0) { dialog.SetButton(-1, Resources.System.GetString(Android.Resource.String.Cancel), new EventHandler<Android.Content.DialogClickEventArgs>(Clicked)); } else { for (int i = 0; i < Commands.Count; i++) { dialog.SetButton(-1 - i, Commands[i].Label, new EventHandler<Android.Content.DialogClickEventArgs>(Clicked)); } } dialog.Show(); return Task.Run<IUICommand>(() => { handle.WaitOne(); return _selectedCommand; }); #elif __IOS__ uac = UIAlertController.Create("", "", UIAlertControllerStyle.ActionSheet); if (Commands.Count == 0) { uac.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel | UIAlertActionStyle.Default, ActionClicked)); } else { for (int i = 0; i < Commands.Count; i++) { UIAlertAction action = UIAlertAction.Create(Commands[i].Label, UIAlertActionStyle.Default, ActionClicked); uac.AddAction(action); } } UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (currentController.PresentedViewController != null) currentController = currentController.PresentedViewController; // set layout requirements for iPad var popoverController = uac.PopoverPresentationController; if(popoverController != null) { popoverController.SourceView = currentController.View; popoverController.SourceRect = new CoreGraphics.CGRect(selection.X, selection.Y, selection.Width, selection.Height); popoverController.PermittedArrowDirections = PlacementHelper.ToArrowDirection(preferredPlacement); } currentController.PresentViewController(uac, true, null); return Task.Run<IUICommand>(() => { handle.WaitOne(); return _selectedCommand; }); #else throw new PlatformNotSupportedException(); #endif }
protected virtual void Present(UIAlertController controller) { UIApplication.SharedApplication.InvokeOnMainThread(() => { var top = this.GetTopViewController(); var po = controller.PopoverPresentationController; if (po != null) { po.SourceView = top.View; var h = (top.View.Frame.Height / 2) - 400; var v = (top.View.Frame.Width / 2) - 300; po.SourceRect = new CGRect(v, h, 0, 0); po.PermittedArrowDirections = UIPopoverArrowDirection.Any; } top.PresentViewController(controller, true, null); }); }
/// <summary> /// Begins an asynchronous operation showing a dialog. /// </summary> /// <returns>An object that represents the asynchronous operation. /// For more on the async pattern, see Asynchronous programming in the Windows Runtime.</returns> /// <remarks>In some cases, such as when the dialog is closed by the system out of your control, your result can be an empty command. /// Returns either the command selected which destroyed the dialog, or an empty command. /// For example, a dialog hosted in a charms window will return an empty command if the charms window has been dismissed.</remarks> public Task<IUICommand> ShowAsync() { if (Commands.Count > MaxCommands) { throw new InvalidOperationException(); } #if __ANDROID__ Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity); Android.App.AlertDialog dialog = builder.Create(); dialog.SetTitle(Title); dialog.SetMessage(Content); if (Commands.Count == 0) { dialog.SetButton(-1, Resources.System.GetString(Android.Resource.String.Cancel), new EventHandler<Android.Content.DialogClickEventArgs>(Clicked)); } else { for (int i = 0; i < Commands.Count; i++) { dialog.SetButton(-1 - i, Commands[i].Label, new EventHandler<Android.Content.DialogClickEventArgs>(Clicked)); } } dialog.Show(); return Task.Run<IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; }); #elif __IOS__ || __TVOS__ uac = UIAlertController.Create(Title, Content, UIAlertControllerStyle.Alert); if (Commands.Count == 0) { uac.AddAction(UIAlertAction.Create("Close", UIAlertActionStyle.Cancel | UIAlertActionStyle.Default, ActionClicked)); } else { for (int i = 0; i < Commands.Count; i++) { UIAlertAction action = UIAlertAction.Create(Commands[i].Label, CancelCommandIndex == i ? UIAlertActionStyle.Cancel : UIAlertActionStyle.Default, ActionClicked); uac.AddAction(action); } } UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (currentController.PresentedViewController != null) currentController = currentController.PresentedViewController; currentController.PresentViewController(uac, true, null); return Task.Run<IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; }); #elif __MAC__ NSAlert alert = new NSAlert(); alert.AlertStyle = NSAlertStyle.Informational; alert.InformativeText = Content; alert.MessageText = Title; foreach(IUICommand command in Commands) { var button = alert.AddButton(command.Label); } alert.BeginSheetForResponse(NSApplication.SharedApplication.MainWindow, NSAlert_onEnded); return Task.Run<IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; }); #elif WINDOWS_PHONE List<string> buttons = new List<string>(); foreach(IUICommand uic in this.Commands) { buttons.Add(uic.Label); } if (buttons.Count == 0) { buttons.Add("Close"); } MessageDialogAsyncOperation asyncOperation = new MessageDialogAsyncOperation(this); string contentText = Content; // trim message body to 255 chars if (contentText.Length > 255) { contentText = contentText.Substring(0, 255); } while(Microsoft.Xna.Framework.GamerServices.Guide.IsVisible) { Thread.Sleep(250); } Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox( string.IsNullOrEmpty(Title) ? " " : Title, contentText, buttons, (int)DefaultCommandIndex, // can choose which button has the focus Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None, // can play sounds result => { int? returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result); // process and fire the required handler if (returned.HasValue) { if (Commands.Count > returned.Value) { IUICommand theCommand = Commands[returned.Value]; asyncOperation.SetResults(theCommand); if (theCommand.Invoked != null) { theCommand.Invoked(theCommand); } } else { asyncOperation.SetResults(null); } } else { asyncOperation.SetResults(null); } }, null); return asyncOperation.AsTask<IUICommand>(); #elif WINDOWS_UWP if (Commands.Count < 3 && Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.UI.ApplicationSettings.ApplicationsSettingsContract", 1)) { Windows.UI.Xaml.Controls.ContentDialog cd = new Windows.UI.Xaml.Controls.ContentDialog(); cd.Title = Title; cd.Content = Content; if(Commands.Count == 0) { cd.PrimaryButtonText = "Close"; } else { cd.PrimaryButtonText = Commands[0].Label; cd.PrimaryButtonClick += Cd_PrimaryButtonClick; if(Commands.Count > 1) { cd.SecondaryButtonText = Commands[1].Label; cd.SecondaryButtonClick += Cd_SecondaryButtonClick; } } return Task.Run<IUICommand>(async () => { ManualResetEvent mre = new ManualResetEvent(false); IUICommand command = null; await cd.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { ContentDialogResult dr = await cd.ShowAsync(); if (Commands.Count > 0) { switch (dr) { case ContentDialogResult.Primary: command = Commands[0]; if(Commands[0].Invoked != null) { Commands[0].Invoked.Invoke(Commands[0]); } break; case ContentDialogResult.Secondary: command = Commands[1]; if (Commands[1].Invoked != null) { Commands[1].Invoked.Invoke(Commands[1]); } break; } } }); mre.WaitOne(); return command; }); } else { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(Content, Title); foreach (IUICommand command in Commands) { dialog.Commands.Add(new Windows.UI.Popups.UICommand(command.Label, (c)=> { command.Invoked(command); }, command.Id)); } return Task.Run<IUICommand>(async () => { Windows.UI.Popups.IUICommand command = await dialog.ShowAsync(); if (command != null) { int i = 0; foreach(Windows.UI.Popups.IUICommand c in dialog.Commands) { if(command == c) { break; } i++; } return Commands[i]; } return null; }); } #elif WIN32 return Task.Run<IUICommand>(() => { IUICommand cmd = ShowTaskDialog(); if (cmd != null) { cmd.Invoked?.Invoke(cmd); } return cmd; }); #else throw new PlatformNotSupportedException(); #endif }
private void Present(UIAlertController controller) { this.Dispatch(() => { var top = Utils.GetTopViewController(); var po = controller.PopoverPresentationController; if (po != null) { po.SourceView = top.View; var h = (top.View.Frame.Height / 2) - 400; var v = (top.View.Frame.Width / 2) - 300; po.SourceRect = new RectangleF((float)v, (float)h, 0, 0); po.PermittedArrowDirections = UIPopoverArrowDirection.Any; } top.PresentViewController(controller, true, null); }); }
void SetupPopover (UIAlertController alertController, UIView sourceView) { var popover = alertController.PopoverPresentationController; if (popover != null) { popover.SourceView = sourceView; popover.SourceRect = sourceView.Bounds; } }
protected virtual IDisposable Present(UIAlertController alert) { return null; }