Skip to content

Commit

Permalink
svn 3015:
Browse files Browse the repository at this point in the history
removed accessing external Android FileExplorers, creating file and directory selection by own Android Dialog (creation of file or directory not implemented)
  • Loading branch information
arbor95 committed Feb 20, 2017
1 parent 5d20453 commit b2902c8
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 935 deletions.
8 changes: 8 additions & 0 deletions Android_GUI/.classpath
Expand Up @@ -25,5 +25,13 @@
<classpathentry exported="true" kind="lib" path="libs/androidsvg-1.2.1.jar"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="C:/_Programme/Android-SDK/platforms/android-10/android.jar">
<attributes>
<attribute name="javadoc_location" value="http://developer.android.com/reference/"/>
</attributes>
<accessrules>
<accessrule kind="nonaccessible" pattern="com/android/internal/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion Android_GUI/AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.cachebox_test" android:installLocation="auto"
android:versionCode="20170218" android:versionName="20170218(Test)">
android:versionCode="20170220" android:versionName="20170220(Test)">
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
Expand Down
178 changes: 178 additions & 0 deletions Android_GUI/src/de/cachebox_test/Android_FileExplorer.java
@@ -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 Android_GUI/src/de/cachebox_test/Android_FileExplorer_ES.java

This file was deleted.

65 changes: 0 additions & 65 deletions Android_GUI/src/de/cachebox_test/Android_FileExplorer_OI.java

This file was deleted.

59 changes: 0 additions & 59 deletions Android_GUI/src/de/cachebox_test/Android_FileExplorer_XPlore.java

This file was deleted.

0 comments on commit b2902c8

Please sign in to comment.