mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
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.
This commit is contained in:
parent
bb4da9a8ba
commit
50b6d62169
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user