private void ShowSftpDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel, string defaultPath)
        {
#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            View dlgContents            = activity.LayoutInflater.Inflate(Resource.Layout.sftpcredentials, null);

            if (!defaultPath.EndsWith(_schemeSeparator))
            {
                var fileStorage = new Keepass2android.Javafilestorage.SftpStorage();
                SftpStorage.ConnectionInfo ci = fileStorage.SplitStringToConnectionInfo(defaultPath);
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_host).Text        = ci.Host;
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_port).Text        = ci.Port.ToString();
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_user).Text        = ci.Username;
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_password).Text    = ci.Password;
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_initial_dir).Text = ci.LocalPath;
            }

            builder.SetView(dlgContents);
            builder.SetPositiveButton(Android.Resource.String.Ok,
                                      (sender, args) =>
            {
                string host     = dlgContents.FindViewById <EditText>(Resource.Id.sftp_host).Text;
                string portText = dlgContents.FindViewById <EditText>(Resource.Id.sftp_port).Text;
                int port        = Keepass2android.Javafilestorage.SftpStorage.DefaultSftpPort;
                if (!string.IsNullOrEmpty(portText))
                {
                    int.TryParse(portText, out port);
                }
                string user        = dlgContents.FindViewById <EditText>(Resource.Id.sftp_user).Text;
                string password    = dlgContents.FindViewById <EditText>(Resource.Id.sftp_password).Text;
                string initialPath = dlgContents.FindViewById <EditText>(Resource.Id.sftp_initial_dir).Text;
                if (string.IsNullOrEmpty(initialPath))
                {
                    initialPath = "/";
                }
                string sftpPath = new Keepass2android.Javafilestorage.SftpStorage().BuildFullPath(host, port, initialPath, user,
                                                                                                  password);
                onStartBrowse(sftpPath);
            });
            EventHandler <DialogClickEventArgs> evtH = new EventHandler <DialogClickEventArgs>((sender, e) => onCancel());

            builder.SetNegativeButton(Android.Resource.String.Cancel, evtH);
            builder.SetTitle(activity.GetString(Resource.String.enter_sftp_login_title));
            Dialog dialog = builder.Create();

            dialog.Show();
#endif
        }
        private void ShowSftpDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel, string defaultPath)
        {
#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            View dlgContents            = activity.LayoutInflater.Inflate(Resource.Layout.sftpcredentials, null);

            var spinner = dlgContents.FindViewById <Spinner>(Resource.Id.sftp_auth_mode_spinner);
            dlgContents.FindViewById <Button>(Resource.Id.send_public_key_button).Click += (sender, args) =>
            {
                var    fileStorage  = new Keepass2android.Javafilestorage.SftpStorage(activity.ApplicationContext);
                string pub_filename = fileStorage.CreateKeyPair();

                Intent sendIntent = new Intent();
                sendIntent.SetAction(Intent.ActionSend);
                sendIntent.PutExtra(Intent.ExtraText, System.IO.File.ReadAllText(pub_filename));

                sendIntent.PutExtra(Intent.ExtraSubject, "Keepass2Android sftp public key");
                sendIntent.SetType("text/plain");
                activity.StartActivity(Intent.CreateChooser(sendIntent, "Send public key to..."));
            };


            spinner.ItemSelected += (sender, args) =>
            {
                if (spinner.SelectedItemPosition == 0)
                {
                    dlgContents.FindViewById <EditText>(Resource.Id.sftp_password).Visibility        = ViewStates.Visible;
                    dlgContents.FindViewById <Button>(Resource.Id.send_public_key_button).Visibility = ViewStates.Gone;
                }
                else
                {
                    dlgContents.FindViewById <EditText>(Resource.Id.sftp_password).Visibility        = ViewStates.Gone;
                    dlgContents.FindViewById <Button>(Resource.Id.send_public_key_button).Visibility = ViewStates.Visible;
                }
            };

            if (!defaultPath.EndsWith(_schemeSeparator))
            {
                var fileStorage = new Keepass2android.Javafilestorage.SftpStorage(activity.ApplicationContext);
                SftpStorage.ConnectionInfo ci = fileStorage.SplitStringToConnectionInfo(defaultPath);
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_host).Text        = ci.Host;
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_port).Text        = ci.Port.ToString();
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_user).Text        = ci.Username;
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_password).Text    = ci.Password;
                dlgContents.FindViewById <EditText>(Resource.Id.sftp_initial_dir).Text = ci.LocalPath;
                if (string.IsNullOrEmpty(ci.Password))
                {
                    spinner.SetSelection(1);
                }
            }

            builder.SetView(dlgContents);
            builder.SetPositiveButton(Android.Resource.String.Ok,
                                      (sender, args) =>
            {
                string host     = dlgContents.FindViewById <EditText>(Resource.Id.sftp_host).Text;
                string portText = dlgContents.FindViewById <EditText>(Resource.Id.sftp_port).Text;
                int port        = Keepass2android.Javafilestorage.SftpStorage.DefaultSftpPort;
                if (!string.IsNullOrEmpty(portText))
                {
                    int.TryParse(portText, out port);
                }
                string user        = dlgContents.FindViewById <EditText>(Resource.Id.sftp_user).Text;
                string password    = dlgContents.FindViewById <EditText>(Resource.Id.sftp_password).Text;
                string initialPath = dlgContents.FindViewById <EditText>(Resource.Id.sftp_initial_dir).Text;
                if (string.IsNullOrEmpty(initialPath))
                {
                    initialPath = "/";
                }
                string sftpPath = new Keepass2android.Javafilestorage.SftpStorage(activity.ApplicationContext).BuildFullPath(host, port, initialPath, user,
                                                                                                                             password);
                onStartBrowse(sftpPath);
            });
            EventHandler <DialogClickEventArgs> evtH = new EventHandler <DialogClickEventArgs>((sender, e) => onCancel());

            builder.SetNegativeButton(Android.Resource.String.Cancel, evtH);
            builder.SetTitle(activity.GetString(Resource.String.enter_sftp_login_title));
            Dialog dialog = builder.Create();

            dialog.Show();
#endif
        }