public static void DisplayError(string errorTitle, string errorMessage) { Rock.Mobile.Threading.Util.PerformOnUIThread(delegate { #if __IOS__ UIKit.UIAlertView alert = new UIKit.UIAlertView(); alert.Title = errorTitle; alert.Message = errorMessage; alert.AddButton("Ok"); alert.Show( ); #elif __ANDROID__ #endif }); }
public static async void OpenMessageDialog(string title, string message) { if (PlatformFunctions.IsDialogOpen) { return; } PlatformFunctions.IsDialogOpen = true; Engine.Pause(); #if ANDROID var builder = new Android.App.AlertDialog.Builder(NeonPartyGamesControllerGame.AndroidContext); var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>(); builder.SetTitle(title); builder.SetMessage(message); builder.SetPositiveButton("OK", (sender_alert, sender_args) => { VibrationHelper.Vibrate(); }); builder.SetOnDismissListener(new OnDismissListener(() => tcs.TrySetResult(true))); builder.Show(); await tcs.Task; #elif IOS var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>(); UIKit.UIAlertView alert = new UIKit.UIAlertView(); alert.Title = title; alert.Message = message; alert.AddButton("OK"); alert.AlertViewStyle = UIKit.UIAlertViewStyle.Default; alert.Dismissed += (object s, UIKit.UIButtonEventArgs ev) => { tcs.TrySetResult(true); }; alert.Show(); await tcs.Task; #elif NETFX_CORE await Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async() => { var dialog = new Windows.UI.Popups.MessageDialog(message, title); await dialog.ShowAsync(); }); #endif Engine.Resume(); PlatformFunctions.IsDialogOpen = false; }
protected void ShowErrorForNativeUIAlert(string v) { new Plugin.Threading.UIThreadRunInvoker().BeginInvokeOnUIThread ( () => { UIKit.UIAlertView alert = null; alert = new UIKit.UIAlertView ( "WARNING", v, null, "Ok", null ); alert.Show(); } ); return; }
public static void ShowError(this Foundation.NSObject obj, Exception ex, string title = "") { if (ex == null) { return; } Error(ex); try { if (string.IsNullOrEmpty(title)) { title = "Error"; } var message = GetUserErrorMessage(ex); #if DEBUG message += "\n\n" + ((ex.GetType() == typeof(Exception)) ? "" : ex.GetType().Name); message += " " + ex.StackTrace; #endif if (obj != null) { obj.BeginInvokeOnMainThread(() => { try { var alert = new UIKit.UIAlertView( title, message, (UIKit.IUIAlertViewDelegate)null, "OK"); alert.Show(); } catch (Exception ex3) { Error(ex3); } }); } } catch (Exception ex2) { Error(ex2); } }
public static void ShowError (this Foundation.NSObject obj, Exception ex, string title = "") { if (ex == null) return; Error (ex); try { if (string.IsNullOrEmpty (title)) { title = "Error"; } var message = GetUserErrorMessage (ex); #if DEBUG message += "\n\n" + ((ex.GetType () == typeof (Exception)) ? "" : ex.GetType ().Name); message += " " + ex.StackTrace; #endif if (obj != null) { obj.BeginInvokeOnMainThread (() => { try { var alert = new UIKit.UIAlertView ( title, message, null, "OK"); alert.Show (); } catch (Exception ex3) { Error (ex3); } }); } } catch (Exception ex2) { Error (ex2); } }
public static async void OpenInputDialog(string title, Action <string> callback, int max_length = 0, object[] args = null) { if (PlatformFunctions.IsDialogOpen) { return; } PlatformFunctions.IsDialogOpen = true; string result = ""; Engine.Pause(); #if ANDROID var builder = new Android.App.AlertDialog.Builder(NeonPartyGamesControllerGame.AndroidContext); var input = new Android.Widget.EditText(NeonPartyGamesControllerGame.AndroidContext); var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>(); builder.SetTitle(title); if (args != null && args.Length > 0) { input.InputType = (Android.Text.InputTypes)args[0]; } else { input.InputType = Android.Text.InputTypes.ClassText; } if (max_length > 0) { input.SetFilters(new Android.Text.IInputFilter[] { new Android.Text.InputFilterLengthFilter(max_length) }); } builder.SetView(input); builder.SetPositiveButton("OK", (sender_alert, sender_args) => { VibrationHelper.Vibrate(); result = input.Text; }); builder.SetOnDismissListener(new OnDismissListener(() => tcs.TrySetResult(true))); builder.Show(); await tcs.Task; #elif IOS var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>(); UIKit.UIAlertView alert = new UIKit.UIAlertView(); alert.Title = title; alert.AddButton("OK"); alert.AlertViewStyle = UIKit.UIAlertViewStyle.PlainTextInput; alert.Clicked += (object s, UIKit.UIButtonEventArgs ev) => { if (ev.ButtonIndex == 0) { result = alert.GetTextField(0).Text; } }; alert.Dismissed += (object s, UIKit.UIButtonEventArgs ev) => { tcs.TrySetResult(true); }; alert.Show(); await tcs.Task; #elif NETFX_CORE await Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async() => { var input_text_box = new Windows.UI.Xaml.Controls.TextBox { AcceptsReturn = false, Height = 32 }; if (max_length > 0) { input_text_box.MaxLength = max_length; } var dialog = new Windows.UI.Xaml.Controls.ContentDialog { Content = input_text_box, Title = title, PrimaryButtonText = "Ok", IsSecondaryButtonEnabled = true, SecondaryButtonText = "Cancel", DefaultButton = Windows.UI.Xaml.Controls.ContentDialogButton.Primary }; if (await dialog.ShowAsync() == Windows.UI.Xaml.Controls.ContentDialogResult.Primary) { result = input_text_box.Text; } else { result = ""; } }); #else #if DEBUG await System.Threading.Tasks.Task.Run(() => { var debugger = Engine.GetFirstInstanceByType <DebuggerWithTerminal>(); debugger?.OpenConsoleWithCustomEvaluator(value => result = value); while (debugger != null && debugger.ConsoleOpen) { System.Threading.Thread.Sleep(1); } }); #endif #endif Engine.Resume(); PlatformFunctions.IsDialogOpen = false; if (!string.IsNullOrWhiteSpace(result)) { callback?.Invoke(result); } }
/*internal static void CompletionHandler(IAsyncInfo operation, AsyncStatus status) { global::System.Diagnostics.Debug.WriteLine(operation.ErrorCode); Type storeType = Type.GetType("Windows.ApplicationModel.Calls.PhoneCallStore, Windows, ContentType=WindowsRuntime"); Type template = typeof(Windows.Foundation.IAsyncOperation<>); Type genericType = template.MakeGenericType(storeType); var nativeStore = genericType.GetRuntimeMethod("GetResults", new Type[0]).Invoke(operation, new object[0]); } */ /// <summary> /// Launches the built-in phone call UI with the specified phone number and display name. /// </summary> /// <param name="phoneNumber">A phone number. /// This should be in international format e.g. +12345678901</param> /// <param name="displayName">A display name.</param> public static void ShowPhoneCallUI(string phoneNumber, string displayName) { #if __ANDROID__ string action = Intent.ActionDial; //promptUser ? Intent.ActionDial : Intent.ActionCall; Intent callIntent = new Intent(action, Android.Net.Uri.FromParts("tel", CleanPhoneNumber(phoneNumber), null)); callIntent.AddFlags(ActivityFlags.ClearWhenTaskReset); Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(callIntent); //Platform.Android.ContextManager.Context.StartActivity(callIntent); #elif __IOS__ if (UIKit.UIDevice.CurrentDevice.Model != "iPhone") { UIKit.UIAlertView av = new UIKit.UIAlertView("Phone", "Dial " + phoneNumber, null, "Done"); av.Show(); } else { global::Foundation.NSUrl url = new global::Foundation.NSUrl("telprompt:" + CleanPhoneNumber(phoneNumber)); UIKit.UIApplication.SharedApplication.OpenUrl(url); } #elif WINDOWS_UWP || WINDOWS_PHONE_APP #if WINDOWS_UWP if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.ApplicationModel.Calls.PhoneCallManager")) { #endif Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(phoneNumber, displayName); #if WINDOWS_UWP } else { Windows.System.Launcher.LaunchUriAsync(new Uri("tel:" + phoneNumber)); } #endif #elif WINDOWS_APP || WIN32 MessageDialog prompt = new MessageDialog(string.Format("Dial {0} at {1}?", displayName, phoneNumber), "Phone"); prompt.Commands.Add(new UICommand("Call", async (c) => { // Windows may prompt the user for an app e.g. Skype, Lync etc await Launcher.LaunchUriAsync(new Uri("tel:" + CleanPhoneNumber(phoneNumber))); })); prompt.Commands.Add(new UICommand("Cancel", null)); prompt.ShowAsync(); #elif WINDOWS_PHONE PhoneCallTask pct = new PhoneCallTask(); pct.PhoneNumber = phoneNumber; pct.DisplayName = displayName; pct.Show(); #else throw new PlatformNotSupportedException(); #endif }