From 50b6d621699265f450c638989e00fe4501186962 Mon Sep 17 00:00:00 2001 From: jmccabe Date: Thu, 5 May 2011 00:10:50 +0800 Subject: [PATCH] Refactor of showFileBrowserActivity to add a couple of extra options to the list of possible file browser intents (ES File Explorer and Blackmoon File Browser) and simplify possible future updates. --- src/com/fsck/k9/helper/FileBrowserHelper.java | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/com/fsck/k9/helper/FileBrowserHelper.java b/src/com/fsck/k9/helper/FileBrowserHelper.java index caf7f55cc..3293a80d0 100644 --- a/src/com/fsck/k9/helper/FileBrowserHelper.java +++ b/src/com/fsck/k9/helper/FileBrowserHelper.java @@ -48,7 +48,7 @@ public class FileBrowserHelper { /** * tries to open known filebrowsers. * If no filebrowser is found and fallback textdialog is shown - * @param c the context as activty + * @param c the context as activity * @param startPath: the default value, where the filebrowser will start. * if startPath = null => the default path is used * @param requestcode: the int you will get as requestcode in onActivityResult @@ -62,27 +62,41 @@ public class FileBrowserHelper { * */ public boolean showFileBrowserActivity(Activity c, File startPath, int requestcode, FileBrowserFailOverCallback callback) { - boolean success = false; - Intent intent = new Intent("org.openintents.action.PICK_DIRECTORY"); - if (startPath == null) - startPath = new File(K9.getAttachmentDefaultPath()); - if (startPath != null) - intent.setData(Uri.fromFile(startPath)); + // A string array that specifies the name of the intent to use, and + // the scheme to use with it when setting the data for the intent. + String[][] intentDetails = + { { "org.openintents.action.PICK_DIRECTORY", "file://" }, // OI File Manager (maybe others) + { "com.androidworkz.action.PICK_DIRECTORY", "file://" }, // SystemExplorer + { "com.estrongs.action.PICK_DIRECTORY", "file://" }, // ES File Explorer + { Intent.ACTION_PICK, "folder://" } }; // Blackmoon File Browser (maybe others) - try { - c.startActivityForResult(intent, requestcode); - success = true; - } catch (ActivityNotFoundException e) { - try { - intent = new Intent("com.androidworkz.action.PICK_DIRECTORY"); + boolean success = false; + + if (startPath == null) { + startPath = new File(K9.getAttachmentDefaultPath()); + } + + int listIndex = 0; + do { + Intent intent = new Intent(intentDetails[listIndex][0]); + if (startPath != null) { + intent.setData(Uri.parse(intentDetails[listIndex][1] + startPath.getPath())); + } + try { c.startActivityForResult(intent, requestcode); success = true; - } catch (ActivityNotFoundException ee) { - //No Filebrowser is installed => show an fallback textdialog - showPathTextInput(c, startPath, callback); - return false; - } + } catch (ActivityNotFoundException e) { + // Try the next intent in the list + listIndex++; + }; + } while (!success && (listIndex < intentDetails.length)); + + if (listIndex == intentDetails.length) { + //No Filebrowser is installed => show a fallback textdialog + showPathTextInput(c, startPath, callback); + success = false; } + return success; }