Beispiel #1
0
        public void Dialog(string title, string content, Action afterOk = null, Action afterCancel = null)
        {
            var context = Mvx.Resolve <IMvxAndroidCurrentTopActivity>();
            var builder = new AlertDialog.Builder(context.Activity);

            builder.SetTitle(title);
            builder.SetMessage(content);
            builder.SetOnDismissListener(new OnDismissListener(this.OnDismiss(afterCancel ?? afterOk)));

            if (afterOk != null)
            {
                builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) =>
                {
                    this.buttonPressd = true;
                    afterOk.Invoke();
                });
            }

            if (afterCancel != null)
            {
                builder.SetNegativeButton(Android.Resource.String.Cancel, (sender, args) =>
                {
                    this.buttonPressd = true;
                    afterCancel.Invoke();
                });
            }

            builder.Create().Show();
        }
Beispiel #2
0
        private static AlertDialogInfo CreateDialog(string content, string title, string okText = null, string cancelText = null, Action <bool> afterHideCallbackWithResponse = null)
        {
            var tcs     = new TaskCompletionSource <bool>();
            var builder = new AlertDialog.Builder(AppCompatActivityBase.CurrentActivity);

            builder.SetMessage(content);
            builder.SetTitle(title);
            var dialog = (AlertDialog)null;

            builder.SetPositiveButton(okText ?? "OK", (d, index) =>
            {
                tcs.TrySetResult(true);
                if (dialog != null)
                {
                    dialog.Dismiss();
                    dialog.Dispose();
                }
                if (afterHideCallbackWithResponse == null)
                {
                    return;
                }
                afterHideCallbackWithResponse(true);
            });

            if (cancelText != null)
            {
                builder.SetNegativeButton(cancelText, (d, index) =>
                {
                    tcs.TrySetResult(false);
                    if (dialog != null)
                    {
                        dialog.Dismiss();
                        dialog.Dispose();
                    }
                    if (afterHideCallbackWithResponse == null)
                    {
                        return;
                    }
                    afterHideCallbackWithResponse(false);
                });
            }

            builder.SetOnDismissListener(new OnDismissListener(() =>
            {
                tcs.TrySetResult(false);
                if (afterHideCallbackWithResponse == null)
                {
                    return;
                }
                afterHideCallbackWithResponse(false);
            }));

            dialog = builder.Create();

            return(new AlertDialogInfo
            {
                Dialog = dialog,
                Tcs = tcs
            });
        }
Beispiel #3
0
        private async Task <bool> ShowAsync()
        {
            _waitHandle = new ManualResetEvent(false);
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(_context);

            if (!string.IsNullOrEmpty(_title))
            {
                dialogBuilder.SetTitle(_title);
            }
            if (!string.IsNullOrEmpty(_message))
            {
                dialogBuilder.SetMessage(_message);
            }
            if (!string.IsNullOrEmpty(_positiveButtonCaption))
            {
                dialogBuilder.SetPositiveButton(_positiveButtonCaption, OnPositiveClick);
            }
            if (!string.IsNullOrEmpty(_negativeButtonCaption))
            {
                dialogBuilder.SetNegativeButton(_negativeButtonCaption, OnNegativeClick);
            }
            dialogBuilder.SetOnDismissListener(this);
            dialogBuilder.Show();

            Task <bool> dialogTask = new Task <bool>(() =>
            {
                _waitHandle.WaitOne();
                return(_dialogResult);
            });

            dialogTask.Start();
            return(await dialogTask);
        }
        void VerityBluetooth()
        {
            try
            {
                if (!BeaconManager.GetInstanceForApplication(this).CheckAvailability())
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetTitle("Bluetooth not enabled");
                    builder.SetMessage("Please enable bluetooth in settings and restart this application.");
                    EventHandler <DialogClickEventArgs> handler = null;
                    builder.SetPositiveButton(Android.Resource.String.Ok, handler);
                    builder.SetOnDismissListener(this);
                    builder.Show();
                }
            }
            catch (BleNotAvailableException e)
            {
                Log.Debug("BleNotAvailableException", e.Message);

                var builder = new AlertDialog.Builder(this);
                builder.SetTitle("Bluetooth LE not available");
                builder.SetMessage("Sorry, this device does not support Bluetooth LE.");
                EventHandler <DialogClickEventArgs> handler = null;
                builder.SetPositiveButton(Android.Resource.String.Ok, handler);
                builder.SetOnDismissListener(this);
                builder.Show();
            }
        }
        public async Task ShowMessageDialogAsync(string content, string title)
        {
            var sem    = new SemaphoreSlim(0);
            var dialog = new AlertDialog.Builder(SimpleIoc.Default.GetInstance <Activity>());

            dialog.SetNeutralButton("OK", (sender, args) => { });
            dialog.SetTitle(title);
            dialog.SetMessage(content);
            dialog.SetCancelable(true);
            dialog.Show();
            dialog.SetOnDismissListener(new DialogDissmissListener(() => sem.Release()));
            await sem.WaitAsync();
        }
        public static void checkIfOnline(Context context, Activity activity, IDialogInterfaceOnDismissListener listener)
        {
            AlertDialog.Builder dialogs = new AlertDialog.Builder(context);
            dialogs.SetOnDismissListener(listener);
            dialogs.SetMessage("Veza na internet je neophodna za nastavak. Pokušajte kasnije.");
            dialogs.SetPositiveButton("U redu", (senderAlert, args) => {
                activity.Finish();
                dialogs.Dispose();
            });
            Dialog alertDialogs = dialogs.Create();

            alertDialogs.Show();
            return;
        }
        public void ShowErrorMessage(string text, bool lengthLong = false, EventHandler eventHandler = null, string nextButton = null, string cancelButton = null)
        {
            if (text.Length > 0 && !isDialogShow)
            {
                isDialogShow = true;

                Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(Xamarin.Forms.Forms.Context);
                dialog.SetOnDismissListener(new OnDismissListener(() =>
                {
                    isDialogShow = false;
                }));

                string btn = "OK";

                if (cancelButton != null)
                {
                    btn = cancelButton;
                }

                AlertDialog alert = dialog.Create();
                alert.SetTitle("DeliverIt");
                alert.SetMessage(text);
                alert.SetButton(btn, (c, ev) => {
                    isDialogShow = false;

                    if (eventHandler != null)
                    {
                        eventHandler.Invoke(this, null);
                    }
                });

                if (nextButton != null)
                {
                    alert.SetButton2(nextButton, (c, ev) => {
                        isDialogShow = false;

                        if (eventHandler != null)
                        {
                            eventHandler.Invoke(this, EventArgs.Empty);
                        }
                    });
                }

                alert.Show();
            }
        }
Beispiel #8
0
        // ----------------------------------------------------------------------------------------------------------------

        /*
         *  INTERNAL ALERTS FOR Dice Rolls.
         */
        // Display an error message for the invalid move.
        // Also stops the chronometer from continuing to count up.
        // http://stackoverflow.com/questions/42006181/chronometer-is-still-running-after-calling-stop
        // Helped with how to stop, and start the chronometer.s
        private void Alert(int iTitle, int iMessage)
        {
            string title   = this.getAlertTitle(iTitle);
            string message = this.getAlertMessage(iMessage);

            // Stop the chronometer or the player will be timed for actually not playing the game.
            chronometer.Stop();

            // Say that time the chronometer was stopped so we can restart it.
            pausedAt = chronometer.Base - SystemClock.ElapsedRealtime();

            // Now we build the Alert that will show the error message.
            AlertDialog.Builder adb = new AlertDialog.Builder(this);
            adb.SetMessage(message);
            adb.SetTitle(title);
            adb.SetOnDismissListener(this);
            adb.Show();
        }
Beispiel #9
0
        private void ConfigureBuilder(AlertDialog.Builder builder, DialogServiceMultiItemsBundle bundle, TaskCompletionSource <List <int> > tcs)
        {
            var checkedItemsIndex    = GetIndexOfCheckedItems(bundle);
            var orgCheckedItemsIndex = new List <int>(checkedItemsIndex);

            builder.SetTitle(bundle.Title);

            var titles = bundle.Items.Select(x => x.Title).ToArray();

            builder.SetMultiChoiceItems(titles, bundle.CheckedItems, (sender, e) =>
            {
                if (e.IsChecked)
                {
                    checkedItemsIndex.Add(e.Which);
                }
                else if (checkedItemsIndex.Contains(e.Which))
                {
                    checkedItemsIndex.Remove(e.Which);
                }
            });

            builder.SetPositiveButton(bundle.PositiveLabel, (sender, e) =>
            {
                if (tcs.TrySetResult(checkedItemsIndex) == false)
                {
                    Console.WriteLine("Unable to set CHECKED_ITEMS result in builder");
                }
            });

            builder.SetNegativeButton(bundle.NegativeLabel, (sender, e) =>
            {
                if (tcs.TrySetResult(orgCheckedItemsIndex) == false)
                {
                    Console.WriteLine("Unable to set ORG_CHECKED_ITEMS result in builder");
                }
            });

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBeanMr1)
            {
                builder.SetOnDismissListener(new MyDismissListener(tcs, orgCheckedItemsIndex));
            }
        }
        public Task <GridItem> ShowAsync(string title, List <GridItem> actions, enumPlace gravity)
        {
            TaskCompletionSource <GridItem> tcs = new TaskCompletionSource <GridItem>();
            bool            clicked             = false;
            AlertDialog     ad             = null;
            View            customView     = CrossCurrentActivity.Current.Activity.LayoutInflater.Inflate(Resource.Layout.CustomGridViewDialog, null);
            List <GridItem> correctActions = new List <GridItem>();

            if (actions != null)
            {
                foreach (var action in actions)
                {
                    action.ClickAction = () =>
                    {
                        clicked = true;
                        if (ad != null)
                        {
                            ad.Dismiss();
                        }

                        tcs.SetResult(action);
                    };
                    correctActions.Add(action);
                }
            }

            (customView.FindViewById <GridView>(Resource.Id.gridview)).Adapter = new GridAdapter(CrossCurrentActivity.Current.Activity, correctActions, gravity);
            AlertDialog.Builder builder = new AlertDialog.Builder(CrossCurrentActivity.Current.Activity);
            builder.SetTitle(title ?? "");
            builder.SetView(customView);
            builder.SetOnDismissListener(new OnDismissListener(() =>
            {
                if (!clicked)
                {
                    tcs.TrySetResult(null);
                }
            }));
            ad = builder.Show();

            return(tcs.Task);
        }
 void VerifyBluetooth()
 {
     try {
         if (!BeaconManager.GetInstanceForApplication(this).CheckAvailability())
         {
             var builder = new AlertDialog.Builder(this);
             builder.SetTitle("Bluetooth not enabled");
             builder.SetMessage("Please enable bluetooth in settings and restart this application.");
             builder.SetPositiveButton(Android.Resource.String.Ok, (obj, sender) => { });
             builder.SetOnDismissListener(new DialogExitOnDismissListener(this));
             builder.Show();
         }
     }
     catch (RuntimeException ex) {
         var builder = new AlertDialog.Builder(this);
         builder.SetTitle("Bluetooth LE not available");
         builder.SetMessage("Sorry, this device does not support Bluetooth LE.");
         builder.SetPositiveButton(Android.Resource.String.Ok, (obj, sender) => { });
         builder.SetOnDismissListener(new DialogExitOnDismissListener(this));
         builder.Show();
     }
 }
Beispiel #12
0
        public static Task ShowChartDialog(Chart chart, string title = "", string close = "关闭")
        {
            var     dbtask  = new DismissByTask();
            Context context = MainActivity.ActivityContext;
            var     builder = new AlertDialog.Builder(context);

            chart.LabelTextSize = MainActivity.Dip2Px(12);
            LayoutInflater layoutInflater = LayoutInflater.From(context);
            var            chartLayout    = layoutInflater.Inflate(HSResource.Layout.SkiaChart, null);

            builder.SetView(chartLayout);

            var canvasView = chartLayout.FindViewById <SKCanvasView>(HSResource.Id.skia_chart_canvas);

            canvasView.PaintSurface += (sender, args) =>
            {
                chart.Draw(args.Surface.Canvas, args.Info.Width, args.Info.Height);
            };

            builder.SetTitle(title);
            builder.SetPositiveButton(close, (sender, args) => { });
            builder.SetOnDismissListener(dbtask);
            var dialog = builder.Create();

            dialog.Show();

            IWindowManager            manager = MainActivity.Instance.WindowManager;
            Display                   d       = manager.DefaultDisplay;
            Window                    window  = dialog.Window;
            WindowManagerLayoutParams param   = window.Attributes;

            param.Height             = MainActivity.Dip2Px(340);
            param.Gravity            = GravityFlags.CenterHorizontal;
            dialog.Window.Attributes = param;

            return(dbtask.EndTask);
        }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
        {
            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            switch (requestCode)
            {
            case PERMISSION_REQUEST_COARSE_LOCATION: {
                if (grantResults[0] == Android.Content.PM.Permission.Granted)
                {
                    Debug.WriteLine("coarse location permission granted", TAG);
                }
                else
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetTitle("Functionality limited");
                    builder.SetMessage("Since location access has not been granted, this app will not be able to discover beacons when in the background.");
                    builder.SetPositiveButton(Android.Resource.String.Ok, (obj, sender) => { });
                    builder.SetOnDismissListener(null);
                    builder.Show();
                }
                return;
            }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Debug.WriteLine("onCreate", TAG);
            base.OnCreate(savedInstanceState);
            Title = "Monitoring";
            SetContentView(Resource.Layout.activity_monitoring);

            VerifyBluetooth();
            LogToDisplay("Application just launched");

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                // Android M Permission check
                if (this.CheckSelfPermission(Manifest.Permission.AccessCoarseLocation) != Android.Content.PM.Permission.Granted)
                {
                    var builder = new AlertDialog.Builder(this);
                    builder.SetTitle("This app needs location access");
                    builder.SetMessage("Please grant location access so this app can detect beacons in the background.");
                    builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { });
                    builder.SetOnDismissListener(this);
                    builder.Show();
                }
            }
        }
Beispiel #15
0
        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();

                    // SetOnDismissListener was added to the AlertDialog.Builder class at API level 17. Call it here to keep us at API level 16.
                    dialog.SetOnDismissListener(new AndroidOnDismissListener(() =>
                    {
                        dialogDismissWait.Set();
                    }));

                    ManualResetEvent dialogShowWait = new ManualResetEvent(false);

                    dialog.SetOnShowListener(new AndroidOnShowListener(() =>
                    {
                        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();
        }
Beispiel #16
0
        private async void ConfirmOrderButton_Click(object sender, EventArgs e)
        {
            if (!IsOnline())
            {
                MainActivity.checkIfOnline(this, this, this);
                return;
            }

            var auth = FirebaseAuth.GetInstance(loginActivity.app);

            id = auth.CurrentUser.Uid;
            var firebase = new FirebaseClient(loginActivity.FirebaseURL);

            string datum = DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm");

            orders orders = new orders();

            orders.uid               = id;
            orders.carName           = carChosen;
            orders.vrstaUsluge       = vrstaUsluge;
            orders.vrstaPosla        = vrstaPosla;
            orders.opisKvara         = opisKvara.Text;
            orders.datumKreiranja    = datum;
            orders.vucnaSluzba       = potrebnaVucnaSluzba;
            orders.dijelovi          = potrebnoNarucivanje;
            orders.pozeljniDatum     = addedDate.Text;
            orders.datumServisa      = "Nepoznato";
            orders.vrijemeServisa    = "Nepoznato";
            orders.cijena            = "Nepoznato";
            orders.napomenaServisera = "Serviser još uvijek nije dodao nikakvu napomenu";
            orders.status            = "Kreirano";

            int numOfOrders = 1;
            int orderIDInt  = 0;

            orderID = JsonConvert.SerializeObject(numOfOrders.ToString());

            List <orders> allOrders          = new List <orders>();
            var           getONumberOfOrders = await firebase.Child("order").Child(id).OnceAsync <orders>();

            foreach (var item in getONumberOfOrders)
            {
                string key = item.Key;
                orderID    = key.Substring(1, 1);
                orderIDInt = Convert.ToInt32(orderID);
            }
            orderIDInt++;
            orderID   = orderIDInt.ToString();
            orderID   = JsonConvert.SerializeObject(orderID);
            orders.id = orderIDInt.ToString();

            try
            {
                var addOrder = firebase.Child("order").Child(id).Child(orderID.ToString()).PostAsync <orders>(orders);
            }
            catch (Exception)
            {
                throw;
            }


            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.SetOnDismissListener(this);
            dialog.SetMessage("Uspješno ste poslali zahtjev za popravkom. Status zahtjeva možete pratiti pod 'Moji termini' u glavnom izborniku");
            dialog.SetPositiveButton("U redu", (senderAlert, args) => {
                dialog.Dispose();
                this.Finish();
                addCarToOrder.finish.Finish();
                Intent intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
            });
            Dialog alertDialog = dialog.Create();

            alertDialog.Show();
        }
 public void SetDissmisEvent(OnDismissListener listener)
 {
     _builder.SetOnDismissListener(listener);
 }
Beispiel #18
0
        private static AlertDialogInfo CreateDialog(
            string content,
            string title,
            string okText     = null,
            string cancelText = null,
            Action <bool> afterHideCallbackWithResponse = null)
        {
            var tcs = new TaskCompletionSource <bool>();

            var builder = new AlertDialog.Builder(CrossCurrentActivity.Current.Activity);

            builder.SetMessage(content);
            builder.SetTitle(title);

            AlertDialog dialog = null;

            builder.SetPositiveButton(
                okText ?? "OK",
                (d, index) =>
            {
                tcs.TrySetResult(true);

                // ReSharper disable AccessToModifiedClosure
                if (dialog != null)
                {
                    dialog.Dismiss();
                    dialog.Dispose();
                }

                if (afterHideCallbackWithResponse != null)
                {
                    afterHideCallbackWithResponse(true);
                }
                // ReSharper restore AccessToModifiedClosure
            });

            if (cancelText != null)
            {
                builder.SetNegativeButton(
                    cancelText,
                    (d, index) =>
                {
                    tcs.TrySetResult(false);

                    // ReSharper disable AccessToModifiedClosure
                    if (dialog != null)
                    {
                        dialog.Dismiss();
                        dialog.Dispose();
                    }

                    if (afterHideCallbackWithResponse != null)
                    {
                        afterHideCallbackWithResponse(false);
                    }
                    // ReSharper restore AccessToModifiedClosure
                });
            }

            builder.SetOnDismissListener(
                new OnDismissListener(
                    () =>
            {
                tcs.TrySetResult(false);

                if (afterHideCallbackWithResponse != null)
                {
                    afterHideCallbackWithResponse(false);
                }
            }));

            dialog = builder.Create();

            return(new AlertDialogInfo
            {
                Dialog = dialog,
                Tcs = tcs
            });
        }
		private static AlertDialogInfo CreateDialog(string content, string title, string okText = null, string cancelText = null, Action<bool> afterHideCallbackWithResponse = null)
		{
			var tcs = new TaskCompletionSource<bool>();
			var builder = new AlertDialog.Builder(AppCompatActivityBase.CurrentActivity);
			builder.SetMessage(content);
			builder.SetTitle(title);
			var dialog = (AlertDialog)null;
			builder.SetPositiveButton(okText ?? "OK", (d, index) =>
				{
					tcs.TrySetResult(true);
					if (dialog != null)
					{
						dialog.Dismiss();
						dialog.Dispose();
					}
					if (afterHideCallbackWithResponse == null)
						return;
					afterHideCallbackWithResponse(true);
				});

			if (cancelText != null)
			{
				builder.SetNegativeButton(cancelText, (d, index) =>
					{
						tcs.TrySetResult(false);
						if (dialog != null)
						{
							dialog.Dismiss();
							dialog.Dispose();
						}
						if (afterHideCallbackWithResponse == null)
							return;
						afterHideCallbackWithResponse(false);
					});
			}

			builder.SetOnDismissListener(new OnDismissListener(() =>
				{
					tcs.TrySetResult(false);
					if (afterHideCallbackWithResponse == null)
						return;
					afterHideCallbackWithResponse(false);
				}));

			dialog = builder.Create();

			return new AlertDialogInfo
			{
				Dialog = dialog,
				Tcs = tcs
			};
		}