protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.config_child_db); _adapter = new ChildDatabasesAdapter(this); var listView = FindViewById <ListView>(Android.Resource.Id.List); listView.Adapter = _adapter; SetSupportActionBar(FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.mytoolbar)); FindViewById <Button>(Resource.Id.add_child_db_button).Click += (sender, args) => { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle(Resource.String.add_child_db); List <string> items = new List <string>(); Dictionary <int, Database> indexToDb = new Dictionary <int, Database>(); foreach (var db in App.Kp2a.OpenDatabases) { if (db != App.Kp2a.CurrentDb) { indexToDb[items.Count] = db; items.Add(App.Kp2a.GetFileStorage(db.Ioc).GetDisplayName(db.Ioc)); } } indexToDb[items.Count] = null; items.Add(GetString(Resource.String.open_other_db)); builder.SetItems(items.ToArray(), (o, eventArgs) => { Database db; if (!indexToDb.TryGetValue(eventArgs.Which, out db) || (db == null)) { StartFileSelect(); } else { AddAutoOpenEntryForDatabase(db); } }); AlertDialog dialog = builder.Create(); dialog.Show(); }; }
public Dialog Build(Activity activity, ActionSheetConfig config) { var dialog = new AlertDialog.Builder(activity, config.AndroidStyleId ?? 0) .SetTitle(config.Title); if (config.Cancel != null) { dialog.SetNeutralButton(config.Cancel.Text, (s, a) => { config.Cancel.Action?.Invoke(); }); } if (config.Destructive != null) { dialog.SetNegativeButton(config.Destructive.Text, (s, a) => { config.Destructive.Action?.Invoke(); }); } if (config.Items != null && config.Items.Count > 0) { if (config.Items.Any(t => t.ItemIcon != null)) { var array = config.Items.Select(t => t.Text).ToArray(); dialog.SetItems(array, (s, a) => { config.Items[a.Which].Action?.Invoke(); }); } else { var adapter = new ActionSheetListAdapter(activity, global::Android.Resource.Layout.SelectDialogItem, global::Android.Resource.Id.Text1, config); dialog.SetAdapter(adapter, (s, a) => { config.Items[a.Which].Action?.Invoke(); }); } } return(dialog.Create()); }
private void OnItemSelected(string protocolId) { if (protocolId == "kp2a") { //send user to market page of regular edition to get more protocols Util.GotoUrl(this, GetString(Resource.String.MarketURL) + "keepass2android.keepass2android"); return; } if (protocolId.Contains(",")) { //bring up a selection dialog to select the variant of the file storage AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetItems(protocolId.Split(",").Select(singleProtocolId => App.Kp2a.GetStorageDisplayName(singleProtocolId)).ToArray(), delegate(object sender, DialogClickEventArgs args) { string[] singleProtocolIds = protocolId.Split(","); OnItemSelected(singleProtocolIds[args.Which]); }); builder.Show(); return; } var field = typeof(Resource.String).GetField("filestoragehelp_" + protocolId); if (field == null) { //no help available ReturnProtocol(protocolId); } else { //set help: string help = GetString((int)field.GetValue(null)); new AlertDialog.Builder(this) .SetTitle(GetString(Resource.String.app_name)) .SetMessage(help) .SetPositiveButton(Android.Resource.String.Ok, (sender, args) => ReturnProtocol(protocolId)) .Create() .Show(); } }
public static AlertDialog.Builder Build(Activity activity, ActionSheetConfig config) { var dlg = new AlertDialog .Builder(activity) .SetCancelable(false) .SetTitle(config.Title); //.SetCustomTitle(new TextView(activity) { // Text = config.Title, // TextSize = 18.0f //}); if (config.ItemIcon != null || config.Options.Any(x => x.ItemIcon != null)) { var adapter = new ActionSheetListAdapter(activity, Android.Resource.Layout.SelectDialogItem, Android.Resource.Id.Text1, config); dlg.SetAdapter(adapter, (s, a) => config.Options[a.Which].Action?.Invoke()); } else { var array = config .Options .Select(x => x.Text) .ToArray(); dlg.SetItems(array, (s, args) => config.Options[args.Which].Action?.Invoke()); } if (config.Destructive != null) { dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke()); } if (config.Cancel != null) { dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke()); } return(dlg); }
public override void ActionSheet(ActionSheetConfig config) { var array = config .Options .Select(x => x.Text) .ToArray(); var dlg = new AlertDialog .Builder(this.GetTopActivity()) .SetCancelable(false) .SetTitle(config.Title); dlg.SetItems(array, (s, args) => config.Options[args.Which].Action?.Invoke()); if (config.Destructive != null) dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke()); if (config.Cancel != null) dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke()); Utils.RequestMainThread(() => dlg.ShowExt()); }