Search in sources :

Example 11 with IFile

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;
    }
}
Also used : LocalFile(group.pals.android.lib.ui.filechooser.io.localfile.LocalFile) IFile(group.pals.android.lib.ui.filechooser.io.IFile) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) IFileFilter(group.pals.android.lib.ui.filechooser.io.IFileFilter) LocalFile(group.pals.android.lib.ui.filechooser.io.localfile.LocalFile) IFile(group.pals.android.lib.ui.filechooser.io.IFile) File(java.io.File) ParentFile(group.pals.android.lib.ui.filechooser.io.localfile.ParentFile)

Example 12 with IFile

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;
    }
}
Also used : LocalFile(group.pals.android.lib.ui.filechooser.io.localfile.LocalFile) IFile(group.pals.android.lib.ui.filechooser.io.IFile) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) IFileFilter(group.pals.android.lib.ui.filechooser.io.IFileFilter) LocalFile(group.pals.android.lib.ui.filechooser.io.localfile.LocalFile) IFile(group.pals.android.lib.ui.filechooser.io.IFile) File(java.io.File) ParentFile(group.pals.android.lib.ui.filechooser.io.localfile.ParentFile)

Example 13 with IFile

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
            }
        }
    };
}
Also used : IFile(group.pals.android.lib.ui.filechooser.io.IFile)

Aggregations

IFile (group.pals.android.lib.ui.filechooser.io.IFile)13 ArrayList (java.util.ArrayList)6 File (java.io.File)5 IFileFilter (group.pals.android.lib.ui.filechooser.io.IFileFilter)4 LocalFile (group.pals.android.lib.ui.filechooser.io.localfile.LocalFile)3 ParentFile (group.pals.android.lib.ui.filechooser.io.localfile.ParentFile)3 FileFilter (java.io.FileFilter)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 IFileProvider (group.pals.android.lib.ui.filechooser.services.IFileProvider)2 FileComparator (group.pals.android.lib.ui.filechooser.utils.FileComparator)2 LoadingDialog (group.pals.android.lib.ui.filechooser.utils.ui.LoadingDialog)2 ComponentName (android.content.ComponentName)1 ServiceConnection (android.content.ServiceConnection)1 IBinder (android.os.IBinder)1 Editable (android.text.Editable)1