Allow deliberate file pickers when browsing for existing files (OI still required for save as)

This commit is contained in:
Philipp Crocoll 2013-04-26 12:43:06 +02:00
parent fa4cd5bf46
commit f025b9cb3d
4 changed files with 33 additions and 31 deletions

View File

@ -614,7 +614,7 @@ namespace keepass2android
case (int)Result.Ok:
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY)
{
String filename = data.DataString;
string filename = Util.IntentToFilename(data);
if (filename != null) {
if (filename.StartsWith("file://")) {
filename = filename.Substring(7);
@ -666,7 +666,7 @@ namespace keepass2android
addBinaryButton.SetCompoundDrawablesWithIntrinsicBounds( Resources.GetDrawable(Android.Resource.Drawable.IcMenuAdd) , null, null, null);
addBinaryButton.Click += (object sender, EventArgs e) =>
{
Util.showBrowseDialog("/mnt/sdcard", this, Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY);
Util.showBrowseDialog("/mnt/sdcard", this, Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY, false);
};
binariesGroup.AddView(addBinaryButton,layoutParams);

View File

@ -267,7 +267,7 @@ namespace keepass2android
break;
case Android.App.Result.Ok:
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE) {
String filename = data.DataString;
string filename = Util.IntentToFilename(data);
if (filename != null) {
if (filename.StartsWith("file://")) {
filename = filename.Substring(7);
@ -431,34 +431,18 @@ namespace keepass2android
ImageButton browse = (ImageButton)FindViewById(Resource.Id.browse_button);
browse.Click += (object sender, EventArgs evt) =>
{
if (Interaction.isIntentAvailable(this, Intents.FILE_BROWSE))
string filename = null;
if (!String.IsNullOrEmpty(mIoConnection.Path))
{
Intent intent = new Intent(Intents.FILE_BROWSE);
if (!String.IsNullOrEmpty(mIoConnection.Path))
File keyfile = new File(mIoConnection.Path);
File parent = keyfile.ParentFile;
if (parent != null)
{
File keyfile = new File(mIoConnection.Path);
File parent = keyfile.ParentFile;
if (parent != null)
{
intent.SetData(Android.Net.Uri.Parse("file://" + parent.AbsolutePath));
}
filename = parent.AbsolutePath;
}
try
{
StartActivityForResult(intent, Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE);
} catch (ActivityNotFoundException)
{
BrowserDialog diag = new BrowserDialog(this);
diag.Show();
}
} else
{
BrowserDialog diag = new BrowserDialog(this);
diag.Show();
}
Util.showBrowseDialog(filename, this, Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE, false);
};
retrieveSettings();

View File

@ -88,12 +88,20 @@ namespace keepass2android
}
public static void showBrowseDialog(string filename, Activity act, int requestCodeBrowse)
public static void showBrowseDialog(string filename, Activity act, int requestCodeBrowse, bool forSaving)
{
if ((!forSaving) && (Interaction.isIntentAvailable(act, Intent.ActionGetContent))) {
Intent i = new Intent(Intent.ActionGetContent);
i.SetType("file/*");
act.StartActivityForResult(i, requestCodeBrowse);
return;
}
if (Interaction.isIntentAvailable(act, Intents.FILE_BROWSE))
{
Intent i = new Intent(Intents.FILE_BROWSE);
i.SetData(Android.Net.Uri.Parse("file://" + filename));
if (filename != null)
i.SetData(Android.Net.Uri.Parse("file://" + filename));
try
{
act.StartActivityForResult(i, requestCodeBrowse);
@ -111,6 +119,14 @@ namespace keepass2android
}
}
public static string IntentToFilename(Intent data)
{
String filename = data.Data.Path;
if (String.IsNullOrEmpty(filename))
filename = data.DataString;
return filename;
}
}
}

View File

@ -194,7 +194,7 @@ namespace keepass2android
browseButton.Click += (sender, evt) => {
string filename = ((EditText)dialog.FindViewById(Resource.Id.file_filename)).Text;
Util.showBrowseDialog(filename, this, requestCodeBrowse);
Util.showBrowseDialog(filename, this, requestCodeBrowse, showCreateButton);
};
@ -415,6 +415,8 @@ namespace keepass2android
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
@ -432,7 +434,7 @@ namespace keepass2android
if ( (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_CREATE
|| requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_OPEN)
&& resultCode == Result.Ok) {
String filename = data.DataString;
string filename = Util.IntentToFilename(data);
if (filename != null) {
if (filename.StartsWith("file://")) {
filename = filename.Substring(7);