private async Task Init() { try { _connection = await Database.Connect(this); InitCategories(); InitAuthenticators(); await UpdateCategories(false); await UpdateAuthenticators(false); CreateTimer(); } catch (SQLiteException) { var builder = new AlertDialog.Builder(this); builder.SetMessage(Resource.String.databaseError); builder.SetTitle(Resource.String.warning); builder.SetPositiveButton(Resource.String.quit, (sender, args) => { Finish(); }); builder.SetCancelable(true); var dialog = builder.Create(); dialog.Show(); } }
/// <summary> /// ShowMessage /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="firstButtonContent"></param> /// <param name="nextButtonContent"></param> /// <param name="lastButtonContent"></param> /// <returns></returns> public async Task <ButtonDialog> ShowMessage(string title, string message, string firstButtonContent, string nextButtonContent, string lastButtonContent) { var tcs = new TaskCompletionSource <ButtonDialog>(); var builder = new AlertDialog.Builder(CrossCurrentActivity.Current.Activity, Resource.Style.AppCompatAlertDialogStyle); builder.SetTitle(title) .SetMessage(message) .SetCancelable(false) .SetPositiveButton(firstButtonContent, (s, args) => { tcs.TrySetResult(ButtonDialog.Primary); }) .SetNeutralButton(lastButtonContent, (s, args) => { tcs.TrySetResult(ButtonDialog.Close); }) .SetNegativeButton(nextButtonContent, (s, args) => { tcs.TrySetResult(ButtonDialog.Secondary); }); var alert = builder.Create(); alert.Show(); var btnPositive = alert.GetButton((int)DialogButtonType.Positive); var btnNegative = alert.GetButton((int)DialogButtonType.Negative); var btnNeutral = alert.GetButton((int)DialogButtonType.Neutral); var layoutParams = (LinearLayout.LayoutParams)btnPositive.LayoutParameters; layoutParams.Gravity = GravityFlags.Center; btnPositive.LayoutParameters = layoutParams; btnNegative.LayoutParameters = layoutParams; btnNeutral.LayoutParameters = layoutParams; return(await tcs.Task); }
private void FindByIson() { _countryPicker = new CountryPicker.Builder().With(this).Listener(this).Build(); var builder = new AlertDialog.Builder(this, R.Style.Base_Theme_MaterialComponents_Dialog_Alert); var input = new EditText(this) { InputType = InputTypes.ClassText | InputTypes.TextVariationPassword }; builder.SetTitle("Country Code") .SetView(input) .SetCancelable(false) .SetPositiveButton( textId: Android.Resource.String.Ok, handler: (sender, args) => { var country = _countryPicker.GetCountryByISO(input.Text); if (country == null) { ShowToast("Country not found"); } else { ShowResultActivity(country); } } ).SetNegativeButton( textId: Android.Resource.String.Cancel, handler: (sender, args) => (sender as IDialogInterface)?.Cancel() ).Show(); }
public static Task <JwtLoginCredentials> GetInputAsync(string title) { var context = GetContext(); var tcs = new TaskCompletionSource <JwtLoginCredentials>(); var result = new JwtLoginCredentials(); AlertDialog dialog = null; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.SetTitle(title); var viewInflated = LayoutInflater.From(context).Inflate(Resource.Layout.login_view, null, false); var userInput = viewInflated.FindViewById <AppCompatEditText>(Resource.Id.input_user); var passwordInput = viewInflated.FindViewById <AppCompatEditText>(Resource.Id.input_password); builder.SetView(viewInflated); builder.SetOnCancelListener(new DialogInterfaceOnCancelListener(() => tcs.TrySetResult(null))); builder.SetOnDismissListener(new DialogInterfaceOnDismissListener(() => tcs.TrySetResult(null))); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { result.User = userInput.Text; result.Password = passwordInput.Text; tcs.TrySetResult(result); dialog.Dismiss(); }); builder.SetNegativeButton(Android.Resource.String.Cancel, (sender, args) => { tcs.TrySetResult(null); dialog.Cancel(); }); dialog = builder.Show(); return(tcs.Task); }
void OnActionSheetRequested(Page sender, ActionSheetArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } var builder = new AlertDialog.Builder(Activity); builder.SetTitle(arguments.Title); string[] items = arguments.Buttons.ToArray(); builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which])); if (arguments.Cancel != null) { builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel)); } if (arguments.Destruction != null) { builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction)); } AlertDialog dialog = builder.Create(); builder.Dispose(); //to match current functionality of renderer we set cancelable on outside //and return null dialog.SetCanceledOnTouchOutside(true); dialog.CancelEvent += (o, e) => arguments.SetResult(null); dialog.Show(); }
public void SetTitle(string title) { if (_useAppCompat) { _appcompatBuilder.SetTitle(title); } else { _legacyBuilder.SetTitle(title); } }
protected virtual void ConfigureDialogBuilder(AndroidX_AlertDialog.Builder builder) { if (ShouldConfigureToBuilder(nameof(Config.Title))) { builder.SetTitle(Config.Title); } if (ShouldConfigureToBuilder(nameof(Config.Message))) { builder.SetMessage(Config.Message); } }
/// <summary> /// ShowMessage /// </summary> /// <returns></returns> public async Task <string> ShowInputDialog(string title, string hint = null, string messageInput = null, // ReSharper disable once MethodOverloadWithOptionalParameter DialogInputType type = DialogInputType.None, bool isEmpty = false) { var tcs = new TaskCompletionSource <string>(); CrossCurrentActivity.Current.Activity.RunOnUiThread(() => { var builder = new AlertDialog.Builder(CrossCurrentActivity.Current.Activity); var input = new EditText(CrossCurrentActivity.Current.Activity); var lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); lp.SetMargins((int)ConvertScreenValue.ConvertDpToPixel(20, CrossCurrentActivity.Current.Activity), 0, (int)ConvertScreenValue.ConvertDpToPixel(20, CrossCurrentActivity.Current.Activity), 0); input.LayoutParameters = lp; input.SetMaxLines(1); input.SetSingleLine(true); input.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(25) }); input.Text = string.IsNullOrEmpty(messageInput) || isEmpty ? string.Empty : messageInput; input.Hint = string.IsNullOrEmpty(messageInput) && !string.IsNullOrEmpty(hint) ? hint : string.Empty; input.InputType = GetInputType(type); var view = new LinearLayout(CrossCurrentActivity.Current.Activity); var lpView = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); view.LayoutParameters = lpView; view.AddView(input); view.Touch += (sender, args) => KeyboardManager.HideKeyboard(CrossCurrentActivity.Current.Activity, view); view.Click += (sender, args) => KeyboardManager.HideKeyboard(CrossCurrentActivity.Current.Activity, view); var dlg = new Dialog(CrossCurrentActivity.Current.Activity); var dlg1 = dlg; builder.SetTitle(title) .SetView(view) .SetPositiveButton("OK", (s, args) => { KeyboardManager.HideKeyboard(CrossCurrentActivity.Current.Activity, view); tcs.TrySetResult(input.Text); dlg1.Dismiss(); }) .SetNegativeButton("Cancel", (s, args) => { KeyboardManager.HideKeyboard(CrossCurrentActivity.Current.Activity, view); tcs.TrySetResult(null); dlg1.Dismiss(); }); dlg = builder.Create(); dlg.Show(); }); return(await tcs.Task); }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(Resource.String.chooseCategories); alert.SetCancelable(false); alert.SetPositiveButton(Resource.String.ok, (EventHandler <DialogClickEventArgs>)null); var view = Activity.LayoutInflater.Inflate(Resource.Layout.dialogChooseCategories, null); _categoryList = view.FindViewById <RecyclerView>(Resource.Id.dialogChooseCategories_list); alert.SetView(view); var dialog = alert.Create(); dialog.Show(); var layout = new LinearLayoutManager(Context); var decoration = new DividerItemDecoration(Context, layout.Orientation); _categoryList.AddItemDecoration(decoration); _categoryList.SetLayoutManager(layout); _categoryAdapter = new ChooseCategoriesAdapter(_categorySource); _categoryAdapter.ItemClick += _itemClick; _categoryList.SetAdapter(_categoryAdapter); _categoryList.HasFixedSize = true; _categoryList.SetItemViewCacheSize(20); var okButton = dialog.GetButton((int)DialogButtonType.Positive); okButton.Click += _onClose.Invoke; var emptyText = view.FindViewById <TextView>(Resource.Id.dialogChooseCategories_empty); if (_categorySource.Count() == 0) { emptyText.Visibility = ViewStates.Visible; _categoryList.Visibility = ViewStates.Gone; } foreach (var category in _checkedCategories) { var index = _categorySource.Categories.FindIndex(c => c.Id == category); _categoryAdapter.CheckedStatus[index] = true; } return(dialog); }
/// <summary> /// ShowMessage /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="firstButtonContent"></param> /// <returns></returns> public async Task <bool?> ShowMessage(string title, string message, string firstButtonContent) { var tcs = new TaskCompletionSource <bool?>(); var builder = new AlertDialog.Builder(CrossCurrentActivity.Current.Activity, Resource.Style.AppCompatAlertDialogStyle); builder.SetTitle(title) .SetMessage(message) .SetCancelable(false) .SetPositiveButton(firstButtonContent, (s, args) => { tcs.TrySetResult(true); }); builder.Create().Show(); return(await tcs.Task); }
void OnPromptRequested(Page sender, PromptArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } AlertDialog alertDialog = new AlertDialog.Builder(Activity).Create(); alertDialog.SetTitle(arguments.Title); alertDialog.SetMessage(arguments.Message); var frameLayout = new FrameLayout(Activity); var editText = new EditText(Activity) { Hint = arguments.Placeholder, Text = arguments.InitialValue }; var layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent) { LeftMargin = (int)(22 * Activity.Resources.DisplayMetrics.Density), RightMargin = (int)(22 * Activity.Resources.DisplayMetrics.Density) }; editText.LayoutParameters = layoutParams; editText.InputType = arguments.Keyboard.ToInputType(); if (arguments.Keyboard == Keyboard.Numeric) { editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType); } if (arguments.MaxLength > -1) { editText.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(arguments.MaxLength) }); } frameLayout.AddView(editText); alertDialog.SetView(frameLayout); alertDialog.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(editText.Text)); alertDialog.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(null)); alertDialog.CancelEvent += (o, args) => { arguments.SetResult(null); }; alertDialog.Window.SetSoftInputMode(SoftInput.StateVisible); alertDialog.Show(); editText.RequestFocus(); }
private void OpenDeleteDialog(int position) { var builder = new AlertDialog.Builder(this); builder.SetMessage(Resource.String.confirmAuthenticatorDelete); builder.SetTitle(Resource.String.warning); builder.SetPositiveButton(Resource.String.delete, async(sender, args) => { await _authSource.Delete(position); _authAdapter.NotifyItemRemoved(position); CheckEmptyState(); }); builder.SetNegativeButton(Resource.String.cancel, (sender, args) => { }); builder.SetCancelable(true); var dialog = builder.Create(); dialog.Show(); }
public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(Resource.String.changeIcon); alert.SetNegativeButton(Resource.String.cancel, (EventHandler <DialogClickEventArgs>)null); alert.SetCancelable(false); var view = Activity.LayoutInflater.Inflate(Resource.Layout.dialogChangeIcon, null); _searchText = view.FindViewById <EditText>(Resource.Id.editSearch); _iconList = view.FindViewById <RecyclerView>(Resource.Id.list); alert.SetView(view); var dialog = alert.Create(); dialog.Show(); _searchText.TextChanged += OnSearchChanged; _iconListAdapter = new IconListAdapter(Context, _iconSource); _iconListAdapter.ItemClick += OnItemClick; _iconListAdapter.HasStableIds = true; _iconList.SetAdapter(_iconListAdapter); _iconList.HasFixedSize = true; _iconList.SetItemViewCacheSize(20); var layout = new FixedGridLayoutManager(Context, 6); _iconList.SetLayoutManager(layout); var cancelButton = dialog.GetButton((int)DialogButtonType.Negative); cancelButton.Click += (sender, e) => { dialog.Dismiss(); }; return(dialog); }
void OnAlertRequested(Page sender, AlertArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } AlertDialog alert = new AlertDialog.Builder(Activity).Create(); alert.SetTitle(arguments.Title); alert.SetMessage(arguments.Message); if (arguments.Accept != null) { alert.SetButton((int)DialogButtonType.Positive, arguments.Accept, (o, args) => arguments.SetResult(true)); } alert.SetButton((int)DialogButtonType.Negative, arguments.Cancel, (o, args) => arguments.SetResult(false)); alert.CancelEvent += (o, args) => { arguments.SetResult(false); }; alert.Show(); }
private void OnDeleteClick(object item, int position) { var builder = new AlertDialog.Builder(this); builder.SetMessage(Resource.String.confirmCategoryDelete); builder.SetTitle(Resource.String.warning); builder.SetCancelable(true); builder.SetPositiveButton(Resource.String.delete, async(sender, args) => { await _categorySource.Delete(position); _categoryAdapter.NotifyItemRemoved(position); CheckEmptyState(); }); builder.SetNegativeButton(Resource.String.cancel, (sender, args) => { }); var dialog = builder.Create(); dialog.Show(); }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(Resource.String.changeIcon); alert.SetNegativeButton(Resource.String.cancel, (EventHandler <DialogClickEventArgs>)null); alert.SetCancelable(false); var view = Activity.LayoutInflater.Inflate(Resource.Layout.dialogIcon, null); _searchText = view.FindViewById <EditText>(Resource.Id.dialogIcon_search); _iconList = view.FindViewById <RecyclerView>(Resource.Id.dialogIcon_list); alert.SetView(view); var dialog = alert.Create(); dialog.Show(); dialog.Window.SetSoftInputMode(SoftInput.StateAlwaysVisible); _searchText.TextChanged += SearchChanged; _iconAdapter = new IconAdapter(Context, _iconSource); _iconAdapter.ItemClick += ItemClick; _iconAdapter.SetHasStableIds(true); _iconList.SetAdapter(_iconAdapter); _iconList.HasFixedSize = true; _iconList.SetItemViewCacheSize(20); var layout = new AuthListGridLayoutManager(Context, 6); _iconList.SetLayoutManager(layout); var cancelButton = dialog.GetButton((int)DialogButtonType.Negative); cancelButton.Click += _negativeButtonEvent.Invoke; return(dialog); }
private void SetupDeleteButton(View deleteButton) { if (_mediaList == null) { deleteButton.Visibility = ViewStates.Gone; return; } deleteButton.Click += (sender, args) => { var confirmation = new AlertDialog.Builder(Activity, Activity.GetThemedResourceId(Resource.Attribute.Dialog_Theme)); confirmation.SetMessage( "Do you really wish to delete this item from your lists? This action CAN NOT be undone!"); confirmation.SetTitle($"Delete {_media.Title.UserPreferred}"); confirmation.SetNegativeButton("Cancel", (cancelSender, cancelArgs) => { }); confirmation.SetPositiveButton("Delete", async(delSender, delArgs) => await DeleteMediaListItem()); confirmation.Show(); }; }