use of group.pals.android.lib.ui.filechooser.io.IFile in project FBReaderJ by geometer.
the class LocalFileProvider method listAllFiles.
// listAllFiles()
@Override
public List<IFile> listAllFiles(IFile dir, final IFileFilter filter) {
if (!(dir instanceof File))
return null;
final List<IFile> _res = new ArrayList<IFile>();
try {
IFile root = dir.parentFile();
if (root == null || filter == null || filter.accept(root))
_res.add(root);
File[] files = ((File) dir).listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
LocalFile file = new LocalFile(pathname);
if (filter == null || filter.accept(file))
_res.add(file);
return false;
}
});
if (files != null)
return _res;
return null;
} catch (Throwable t) {
return null;
}
}
use of group.pals.android.lib.ui.filechooser.io.IFile in project FBReaderJ by geometer.
the class LocalFileProvider method listAllFiles.
// listAllFiles()
@Override
public List<IFile> listAllFiles(IFile dir) throws Exception {
if (!(dir instanceof File) || !dir.canRead())
return null;
try {
final List<IFile> _files = new ArrayList<IFile>();
IFile root = dir.parentFile();
if (root.parentFile() == null)
_files.add(root);
File[] files = ((File) dir).listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
_files.add(new LocalFile(pathname));
return false;
}
});
if (files != null)
return _files;
return null;
} catch (Throwable t) {
return null;
}
}
use of group.pals.android.lib.ui.filechooser.io.IFile in project FBReaderJ by geometer.
the class FileUtils method createDeleteFileThread.
/**
* Deletes a file or directory.
*
* @param file
* {@link IFile}
* @param fileProvider
* {@link IFileProvider}
* @param recursive
* if {@code true} and {@code file} is a directory, browses the
* directory and deletes all of its sub files
* @return the thread which is deleting files
*/
public static Thread createDeleteFileThread(final IFile file, final IFileProvider fileProvider, final boolean recursive) {
return new Thread() {
@Override
public void run() {
deleteFile(file);
}
// run()
private void deleteFile(IFile file) {
if (isInterrupted())
return;
if (file.isFile()) {
file.delete();
return;
} else if (!file.isDirectory())
return;
if (!recursive) {
file.delete();
return;
}
try {
List<IFile> files = fileProvider.listAllFiles(file);
if (files == null) {
file.delete();
return;
}
for (IFile f : files) {
if (isInterrupted())
return;
if (f.isFile())
f.delete();
else if (f.isDirectory()) {
if (recursive)
deleteFile(f);
else
f.delete();
}
}
file.delete();
} catch (Throwable t) {
// TODO
}
}
};
}
Aggregations