protected void ShowErrorDialog(Exception ex) { RunOnUiThread(() => { AlertDialog ad = new AlertDialog.Builder(this).Create(); ad.SetCancelable(false); ad.SetMessage(string.Format("An error has occured: {0}", ex)); ad.SetButton("OK", (sender, args) => ad.Dismiss()); ad.Show(); }); }
public static void ShowMsgBox_OK(Activity currentActivity, string title, string msg) { AlertDialog alertDialog = new AlertDialog.Builder(currentActivity).Create(); alertDialog.SetTitle(title); alertDialog.SetMessage(msg); alertDialog.SetButton((int)DialogButtonType.Neutral, "OK", (object sender, DialogClickEventArgs e) => { alertDialog.Dismiss(); }); alertDialog.Show(); }
private void RenderResults(List<Product> products) { if (products == null || products.Count == 0) { _progressDialog.Dismiss (); var alertDialog = new AlertDialog.Builder(this).Create(); alertDialog.SetTitle("Search Results"); alertDialog.SetMessage("We were unable to find any matches in the catalog."); alertDialog.SetIcon(Resource.Drawable.icon); alertDialog.SetButton("OK", (o, e) => { alertDialog.Dismiss(); Finish(); }); alertDialog.Show(); } else { SetContentView (Resource.Layout.SearchResults); ListView.SetBackgroundColor (G.Color.Transparent); ListAdapter = new ProductListAdapter(this, products); _progressDialog.Dismiss (); } }
public void SyncCompleted() { RunOnUiThread(() => { _lblTitle.Text = "Sync completed"; AlertDialog ad = new AlertDialog.Builder(this).Create(); ad.SetCancelable(false); ad.SetMessage("Sync has completed successfully."); ad.SetButton("OK", (sender, args) => { ad.Dismiss(); Finish(); }); ad.Show(); }); }
public void ShowMessage(string title, string message) { RunOnUiThread(() => { AlertDialog ad = new AlertDialog.Builder(this).Create(); ad.SetCancelable(false); ad.SetTitle(title); ad.SetMessage(message); ad.SetButton("OK", (sender, args) => ad.Dismiss()); ad.Show(); }); }
public void SyncEmptyError(Exception ex) { RunOnUiThread(() => { AlertDialog ad = new AlertDialog.Builder(this).Create(); ad.SetCancelable(false); ad.SetTitle("Error"); ad.SetMessage(ex.Message); ad.SetButton("OK", (sender, args) => ad.Dismiss()); ad.Show(); }); }
public override void PromptForInputAsync(string prompt, bool startVoiceRecognizer, Action<string> callback) { new Thread(() => { string input = null; ManualResetEvent dialogDismissWait = new ManualResetEvent(false); GetMainActivityAsync(true, mainActivity => mainActivity.RunOnUiThread(() => { EditText inputEdit = new EditText(mainActivity); AlertDialog dialog = new AlertDialog.Builder(mainActivity) .SetTitle("Sensus is requesting input...") .SetMessage(prompt) .SetView(inputEdit) .SetPositiveButton("OK", (o, e) => { input = inputEdit.Text; }) .SetNegativeButton("Cancel", (o, e) => { }) .Create(); // for some reason, stopping the activity with the home button doesn't raise the alert dialog's dismiss // event. so, we'll manually trap the activity stop and dismiss the dialog ourselves. this is important // because the caller of this method might be blocking itself or others (e.g., other prompts) until // the dialog is dismissed. if we don't trap the activity stop then those blocks could go on indefinitely. EventHandler activityStoppedHandler = (o,e) => { dialog.Dismiss(); }; mainActivity.Stopped += activityStoppedHandler; dialog.DismissEvent += (o,e) => { // we don't need the dismiss event anymore, since the dialog has closed mainActivity.Stopped -= activityStoppedHandler; dialogDismissWait.Set(); }; ManualResetEvent dialogShowWait = new ManualResetEvent(false); dialog.ShowEvent += (o,e) => { dialogShowWait.Set(); }; // dismiss the keyguard when dialog appears dialog.Window.AddFlags(global::Android.Views.WindowManagerFlags.DismissKeyguard); dialog.Window.AddFlags(global::Android.Views.WindowManagerFlags.ShowWhenLocked); dialog.Window.AddFlags(global::Android.Views.WindowManagerFlags.TurnScreenOn); dialog.Window.SetSoftInputMode(global::Android.Views.SoftInput.StateAlwaysVisible); // dim whatever is behind the dialog dialog.Window.AddFlags(global::Android.Views.WindowManagerFlags.DimBehind); dialog.Window.Attributes.DimAmount = 0.75f; dialog.Show(); #region voice recognizer if (startVoiceRecognizer) { new Thread(() => { // wait for the dialog to be shown so it doesn't hide our speech recognizer activity dialogShowWait.WaitOne(); // there's a slight race condition between the dialog showing and speech recognition showing. pause here to prevent the dialog from hiding the speech recognizer. Thread.Sleep(1000); Intent intent = new Intent(RecognizerIntent.ActionRecognizeSpeech); intent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm); intent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500); intent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500); intent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000); intent.PutExtra(RecognizerIntent.ExtraMaxResults, 1); intent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default); intent.PutExtra(RecognizerIntent.ExtraPrompt, prompt); mainActivity.GetActivityResultAsync(intent, AndroidActivityResultRequestCode.RecognizeSpeech, result => { if (result != null && result.Item1 == Result.Ok) { IList<string> matches = result.Item2.GetStringArrayListExtra(RecognizerIntent.ExtraResults); if (matches != null && matches.Count > 0) mainActivity.RunOnUiThread(() => { inputEdit.Text = matches[0]; }); } }); }).Start(); } #endregion })); dialogDismissWait.WaitOne(); callback(input); }).Start(); }