mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-17 15:05:03 -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.
|
* tries to open known filebrowsers.
|
||||||
* If no filebrowser is found and fallback textdialog is shown
|
* 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.
|
* @param startPath: the default value, where the filebrowser will start.
|
||||||
* if startPath = null => the default path is used
|
* if startPath = null => the default path is used
|
||||||
* @param requestcode: the int you will get as requestcode in onActivityResult
|
* @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) {
|
public boolean showFileBrowserActivity(Activity c, File startPath, int requestcode, FileBrowserFailOverCallback callback) {
|
||||||
boolean success = false;
|
// A string array that specifies the name of the intent to use, and
|
||||||
Intent intent = new Intent("org.openintents.action.PICK_DIRECTORY");
|
// the scheme to use with it when setting the data for the intent.
|
||||||
if (startPath == null)
|
String[][] intentDetails =
|
||||||
startPath = new File(K9.getAttachmentDefaultPath());
|
{ { "org.openintents.action.PICK_DIRECTORY", "file://" }, // OI File Manager (maybe others)
|
||||||
if (startPath != null)
|
{ "com.androidworkz.action.PICK_DIRECTORY", "file://" }, // SystemExplorer
|
||||||
intent.setData(Uri.fromFile(startPath));
|
{ "com.estrongs.action.PICK_DIRECTORY", "file://" }, // ES File Explorer
|
||||||
|
{ Intent.ACTION_PICK, "folder://" } }; // Blackmoon File Browser (maybe others)
|
||||||
|
|
||||||
|
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 {
|
try {
|
||||||
c.startActivityForResult(intent, requestcode);
|
c.startActivityForResult(intent, requestcode);
|
||||||
success = true;
|
success = true;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
try {
|
// Try the next intent in the list
|
||||||
intent = new Intent("com.androidworkz.action.PICK_DIRECTORY");
|
listIndex++;
|
||||||
c.startActivityForResult(intent, requestcode);
|
};
|
||||||
success = true;
|
} while (!success && (listIndex < intentDetails.length));
|
||||||
} catch (ActivityNotFoundException ee) {
|
|
||||||
//No Filebrowser is installed => show an fallback textdialog
|
if (listIndex == intentDetails.length) {
|
||||||
|
//No Filebrowser is installed => show a fallback textdialog
|
||||||
showPathTextInput(c, startPath, callback);
|
showPathTextInput(c, startPath, callback);
|
||||||
return false;
|
success = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user