public override View NewView(Context context, ICursor cursor, ViewGroup parent) { if (cursorInflater == null) { cursorInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService); } View view = cursorInflater.Inflate(Resource.Layout.file_row, parent, false); view.FindViewById(Resource.Id.group_name_vdots).Click += (sender, args) => { Handler handler = new Handler(Looper.MainLooper); handler.Post(() => { PopupMenu popupMenu = new PopupMenu(context, view.FindViewById(Resource.Id.group_name_vdots)); AccessManager.PreparePopup(popupMenu); int remove = 0; int edit = 1; popupMenu.Menu.Add(0, remove, 0, context.GetString(Resource.String.remove_from_filelist)).SetIcon(Resource.Drawable.ic_menu_delete_grey); TextView textView = view.FindViewById <TextView>(Resource.Id.file_filename); String filename = (string)textView.Tag; IOConnectionInfo ioc = new IOConnectionInfo { Path = filename }; if (FileSelectHelper.CanEditIoc(ioc)) { popupMenu.Menu.Add(0, edit, 0, context.GetString(Resource.String.edit)).SetIcon(Resource.Drawable.ic_menu_edit_grey); } popupMenu.MenuItemClick += delegate(object sender2, PopupMenu.MenuItemClickEventArgs args2) { if (args2.Item.ItemId == remove) { App.Kp2a.FileDbHelper.DeleteFile(filename); cursor.Requery(); } if (args2.Item.ItemId == edit) { var fsh = new FileSelectHelper(_activity, false, RequestCodeEditIoc); fsh.OnOpen += (o, newConnectionInfo) => { _activity.EditFileEntry(filename, newConnectionInfo); }; fsh.PerformManualFileSelect(filename); } }; popupMenu.Show(); }); }; return(view); }
protected override void StartSelectFile(bool isForSave, int browseRequestCode, string protocolId) { FileSelectHelper fileSelectHelper = new FileSelectHelper(this, isForSave, browseRequestCode); fileSelectHelper.OnOpen += (sender, ioc) => { IocSelected(ioc, browseRequestCode); }; fileSelectHelper.OnCancel += (sender, args) => { ReturnCancel(); }; App.Kp2a.GetFileStorage(protocolId).StartSelectFile(new FileStorageSetupInitiatorActivity(this, OnActivityResult, s => fileSelectHelper.PerformManualFileSelect(s) ), isForSave, browseRequestCode, protocolId); }
public bool OnActivityResult(int requestCode, Result resultCode, Intent data) { if (requestCode == _requestCode) { if (resultCode == KeePass.ExitFileStorageSelectionOk) { string protocolId = data.GetStringExtra("protocolId"); if (protocolId == "content") { Util.ShowBrowseDialog(_activity, _requestCode, true, true); } else { FileSelectHelper fileSelectHelper = new FileSelectHelper(_activity, true, _requestCode); fileSelectHelper.OnOpen += (sender, ioc) => { SaveFile(ioc); }; App.Kp2a.GetFileStorage(protocolId).StartSelectFile( new FileStorageSetupInitiatorActivity(_activity, (i, result, arg3) => OnActivityResult(i, result, arg3), s => fileSelectHelper.PerformManualFileSelect(s)), true, _requestCode, protocolId); } return(true); } if (resultCode == (Result)FileStorageResults.FileUsagePrepared) { var ioc = new IOConnectionInfo(); Util.SetIoConnectionFromIntent(ioc, data); SaveFile(ioc); return(true); } if (resultCode == (Result)FileStorageResults.FileChooserPrepared) { IOConnectionInfo ioc = new IOConnectionInfo(); Util.SetIoConnectionFromIntent(ioc, data); new FileSelectHelper(_activity, true, _requestCode).StartFileChooser(ioc.Path); return(true); } if (resultCode == Result.Ok) { if (requestCode == _requestCode) { if (data.Data.Scheme == "content") { if ((int)Android.OS.Build.VERSION.SdkInt >= 19) { //try to take persistable permissions try { Kp2aLog.Log("TakePersistableUriPermission"); var takeFlags = data.Flags & (ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission); _activity.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags); } catch (Exception e) { Kp2aLog.Log(e.ToString()); } } } string filename = Util.IntentToFilename(data, _activity); if (filename == null) { filename = data.DataString; } bool fileExists = data.GetBooleanExtra("group.pals.android.lib.ui.filechooser.FileChooserActivity.result_file_exists", true); if (fileExists) { SaveFile(new IOConnectionInfo { Path = ConvertFilenameToIocPath(filename) }); } else { var task = new CreateNewFilename(_activity, new ActionOnFinish(_activity, (success, messageOrFilename, activity) => { if (!success) { Toast.MakeText(activity, messageOrFilename, ToastLength.Long).Show(); return; } SaveFile(new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) }); }), filename); new ProgressTask(App.Kp2a, _activity, task).Run(); } return(true); } } Clear(); return(true); } return(false); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == KeePass.ExitFileStorageSelectionOk) { string protocolId = data.GetStringExtra("protocolId"); if (protocolId == "content") { Util.ShowBrowseDialog(this, RequestCodeDbFilename, true, true); } else { FileSelectHelper fileSelectHelper = new FileSelectHelper(this, true, RequestCodeDbFilename) { DefaultExtension = _ffp[_fileFormatIndex].DefaultExtension }; fileSelectHelper.OnOpen += (sender, ioc) => { ExportTo(ioc); }; App.Kp2a.GetFileStorage(protocolId).StartSelectFile( new FileStorageSetupInitiatorActivity(this, OnActivityResult, s => fileSelectHelper.PerformManualFileSelect(s)), true, RequestCodeDbFilename, protocolId); } return; } if (resultCode == Result.Ok) { if (requestCode == RequestCodeDbFilename) { if (data.Data.Scheme == "content") { if ((int)Android.OS.Build.VERSION.SdkInt >= 19) { //try to take persistable permissions try { Kp2aLog.Log("TakePersistableUriPermission"); var takeFlags = data.Flags & (ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission); this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags); } catch (Exception e) { Kp2aLog.Log(e.ToString()); } } } string filename = Util.IntentToFilename(data, this); if (filename == null) { filename = data.DataString; } bool fileExists = data.GetBooleanExtra("group.pals.android.lib.ui.filechooser.FileChooserActivity.result_file_exists", true); if (fileExists) { ExportTo(new IOConnectionInfo { Path = ConvertFilenameToIocPath(filename) }); } else { var task = new CreateNewFilename(new ActionOnFinish((success, messageOrFilename) => { if (!success) { Toast.MakeText(this, messageOrFilename, ToastLength.Long).Show(); return; } ExportTo(new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) }); }), filename); new ProgressTask(App.Kp2a, this, task).Run(); } return; } } if (resultCode == (Result)FileStorageResults.FileUsagePrepared) { var ioc = new IOConnectionInfo(); PasswordActivity.SetIoConnectionFromIntent(ioc, data); ExportTo(ioc); return; } if (resultCode == (Result)FileStorageResults.FileChooserPrepared) { IOConnectionInfo ioc = new IOConnectionInfo(); PasswordActivity.SetIoConnectionFromIntent(ioc, data); new FileSelectHelper(this, true, RequestCodeDbFilename) { DefaultExtension = _ffp[_fileFormatIndex].DefaultExtension } .StartFileChooser(ioc.Path); return; } Finish(); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == KeePass.ResultOkPasswordGenerator) { String generatedPassword = data.GetStringExtra("keepass2android.password.generated_password"); FindViewById <TextView>(Resource.Id.entry_password).Text = generatedPassword; FindViewById <TextView>(Resource.Id.entry_confpassword).Text = generatedPassword; } if (resultCode == KeePass.ExitFileStorageSelectionOk) { string protocolId = data.GetStringExtra("protocolId"); if (protocolId == "content") { Util.ShowBrowseDialog(this, RequestCodeDbFilename, true, true); } else { FileSelectHelper fileSelectHelper = new FileSelectHelper(this, true, RequestCodeDbFilename) { DefaultExtension = "kdbx" }; fileSelectHelper.OnOpen += (sender, info) => { _ioc = info; UpdateIocView(); }; App.Kp2a.GetFileStorage(protocolId).StartSelectFile( new FileStorageSetupInitiatorActivity(this, OnActivityResult, s => fileSelectHelper.PerformManualFileSelect(s)), true, RequestCodeDbFilename, protocolId); } } if (resultCode == Result.Ok) { if (requestCode == RequestCodeKeyFile) { if (data.Data.Scheme == "content") { if ((int)Build.VERSION.SdkInt >= 19) { //try to take persistable permissions try { Kp2aLog.Log("TakePersistableUriPermission"); var takeFlags = data.Flags & (ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission); this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags); } catch (Exception e) { Kp2aLog.Log(e.ToString()); } } } string filename = Util.IntentToFilename(data, this); if (filename == null) { filename = data.DataString; } _keyfileFilename = ConvertFilenameToIocPath(filename); FindViewById <TextView>(Resource.Id.keyfile_filename).Text = _keyfileFilename; FindViewById(Resource.Id.keyfile_filename).Visibility = ViewStates.Visible; } if (requestCode == RequestCodeDbFilename) { if (data.Data.Scheme == "content") { if ((int)Build.VERSION.SdkInt >= 19) { //try to take persistable permissions try { Kp2aLog.Log("TakePersistableUriPermission"); var takeFlags = data.Flags & (ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission); this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags); } catch (Exception e) { Kp2aLog.Log(e.ToString()); } } } string filename = Util.IntentToFilename(data, this); if (filename == null) { filename = data.DataString; } bool fileExists = data.GetBooleanExtra("group.pals.android.lib.ui.filechooser.FileChooserActivity.result_file_exists", true); if (fileExists) { _ioc = new IOConnectionInfo { Path = ConvertFilenameToIocPath(filename) }; UpdateIocView(); } else { var task = new CreateNewFilename(new ActionOnFinish((success, messageOrFilename) => { if (!success) { Toast.MakeText(this, messageOrFilename, ToastLength.Long).Show(); return; } _ioc = new IOConnectionInfo { Path = ConvertFilenameToIocPath(messageOrFilename) }; UpdateIocView(); }), filename); new ProgressTask(App.Kp2a, this, task).Run(); } } } if (resultCode == (Result)FileStorageResults.FileUsagePrepared) { _ioc = new IOConnectionInfo(); PasswordActivity.SetIoConnectionFromIntent(_ioc, data); UpdateIocView(); } if (resultCode == (Result)FileStorageResults.FileChooserPrepared) { IOConnectionInfo ioc = new IOConnectionInfo(); PasswordActivity.SetIoConnectionFromIntent(ioc, data); new FileSelectHelper(this, true, RequestCodeDbFilename) { DefaultExtension = "kdbx" } .StartFileChooser(ioc.Path); } }