Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed accessing external Android FileExplorers, creating file and directory selection by own Android Dialog (creation of file or directory not implemented)
- Loading branch information
Showing
18 changed files
with
234 additions
and
935 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
Android_GUI/src/de/cachebox_test/Android_FileExplorer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package de.cachebox_test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.slf4j.LoggerFactory; | ||
|
||
import CB_UI_Base.Events.PlatformConnector.IgetFileReturnListener; | ||
import CB_UI_Base.Events.PlatformConnector.IgetFolderReturnListener; | ||
import CB_Utils.fileProvider.File; | ||
import CB_Utils.fileProvider.FileFactory; | ||
import CB_Utils.fileProvider.FilenameFilter; | ||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.content.DialogInterface; | ||
import android.content.DialogInterface.OnClickListener; | ||
import android.os.Environment; | ||
|
||
public class Android_FileExplorer { | ||
final static org.slf4j.Logger log = LoggerFactory.getLogger(Android_FileExplorer.class); | ||
private static final String PARENT_DIR = ".."; | ||
// private final String TAG = getClass().getName(); | ||
private String[] fileList; | ||
private File currentPath; | ||
|
||
private IgetFileReturnListener CB_FileReturnListener; | ||
private IgetFolderReturnListener CB_FolderReturnListener; | ||
private final Activity activity; | ||
private boolean selectDirectoryOption; | ||
private String fileEndsWith; | ||
private final String TitleText; | ||
private final String ButtonText; | ||
|
||
/** | ||
* @param activity | ||
* @param initialPath | ||
*/ | ||
public Android_FileExplorer(Activity activity, File initialPath, String TitleText, String ButtonText) { | ||
this(activity, initialPath, TitleText, ButtonText, null); | ||
} | ||
|
||
public Android_FileExplorer(Activity activity, File initialPath, String TitleText, String ButtonText, String fileEndsWith) { | ||
this.activity = activity; | ||
setFileEndsWith(fileEndsWith); | ||
if (!initialPath.exists()) | ||
initialPath = FileFactory.createFile(Environment.getExternalStorageDirectory().getAbsolutePath()); | ||
currentPath = initialPath; | ||
this.TitleText = TitleText; | ||
if (ButtonText == null || ButtonText.length() == 0) { | ||
this.ButtonText = "Ok"; | ||
} else { | ||
this.ButtonText = ButtonText; | ||
} | ||
} | ||
|
||
public void setFileReturnListener(IgetFileReturnListener returnListener) { | ||
CB_FileReturnListener = returnListener; | ||
} | ||
|
||
public void setFolderReturnListener(IgetFolderReturnListener returnListener) { | ||
CB_FolderReturnListener = returnListener; | ||
} | ||
|
||
/** | ||
* @return file dialog | ||
*/ | ||
private Dialog createFileDialog() { | ||
Dialog dialog = null; | ||
|
||
try { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(activity); | ||
|
||
loadFileList(currentPath); | ||
|
||
if (TitleText == null || TitleText.length() == 0) { | ||
builder.setTitle(currentPath.getPath()); | ||
} else { | ||
builder.setTitle(TitleText + "\n" + currentPath.getPath()); | ||
} | ||
|
||
if (selectDirectoryOption) { | ||
builder.setPositiveButton(ButtonText, new OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
CB_FolderReturnListener.getFolderReturn(currentPath.getAbsolutePath()); | ||
} | ||
}); | ||
} | ||
|
||
builder.setItems(fileList, new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
String fileChosen = fileList[which]; | ||
File chosenFile = getChosenFile(fileChosen); | ||
if (chosenFile.isDirectory()) { | ||
loadFileList(chosenFile); | ||
dialog.cancel(); | ||
dialog.dismiss(); | ||
showDialog(); | ||
} else { | ||
log.info("selected toString: " + chosenFile.toString()); | ||
log.info("selected getPath: " + chosenFile.getPath()); | ||
log.info("selected getAbsolutePath: " + chosenFile.getAbsolutePath()); | ||
CB_FileReturnListener.getFileReturn(chosenFile.getAbsolutePath()); | ||
} | ||
} | ||
}); | ||
|
||
dialog = builder.show(); | ||
|
||
} catch (Exception e) { | ||
log.error(e.getLocalizedMessage()); | ||
} | ||
|
||
return dialog; | ||
} | ||
|
||
public void setSelectDirectoryOption(boolean selectDirectoryOption) { | ||
this.selectDirectoryOption = selectDirectoryOption; | ||
} | ||
|
||
/** | ||
* Show file dialog | ||
*/ | ||
public void showDialog() { | ||
try { | ||
activity.runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
createFileDialog().show(); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
log.error(e.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
private void loadFileList(File path) { | ||
this.currentPath = path; | ||
List<String> r = new ArrayList<String>(); | ||
if (path.exists()) { | ||
if (path.getParentFile() != null) | ||
r.add(PARENT_DIR); | ||
FilenameFilter filter = new FilenameFilter() { | ||
@Override | ||
public boolean accept(File dir, String filename) { | ||
File sel = FileFactory.createFile(dir, filename); | ||
if (!sel.canRead()) | ||
return false; | ||
if (selectDirectoryOption) | ||
return sel.isDirectory(); | ||
else { | ||
boolean endsWith = fileEndsWith != null ? filename.toLowerCase().endsWith(fileEndsWith) : true; | ||
return endsWith || sel.isDirectory(); | ||
} | ||
} | ||
}; | ||
String[] fileList1 = path.list(filter); | ||
for (String file : fileList1) { | ||
r.add(file); | ||
} | ||
} | ||
fileList = r.toArray(new String[] {}); | ||
} | ||
|
||
private File getChosenFile(String fileChosen) { | ||
if (fileChosen.equals(PARENT_DIR)) | ||
return currentPath.getParentFile(); | ||
else | ||
return FileFactory.createFile(currentPath, fileChosen); | ||
} | ||
|
||
private void setFileEndsWith(String fileEndsWith) { | ||
this.fileEndsWith = fileEndsWith != null ? fileEndsWith.toLowerCase() : fileEndsWith; | ||
} | ||
|
||
} |
63 changes: 0 additions & 63 deletions
63
Android_GUI/src/de/cachebox_test/Android_FileExplorer_ES.java
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
Android_GUI/src/de/cachebox_test/Android_FileExplorer_OI.java
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
Android_GUI/src/de/cachebox_test/Android_FileExplorer_XPlore.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.