Search in sources :

Example 1 with LocalFile

use of group.pals.android.lib.ui.filechooser.io.localfile.LocalFile in project FBReaderJ by geometer.

the class FileChooserUtil method runFileChooser.

public static void runFileChooser(Activity activity, int requestCode, String title, String initialDir, String regexp) {
    final Intent intent = new Intent(activity, FileChooserActivity.class);
    intent.putExtra(FileChooserActivity._TextResources, textResources(title));
    intent.putExtra(FileChooserActivity._Rootpath, (Parcelable) new LocalFile(initialDir));
    intent.putExtra(FileChooserActivity._ActionBar, true);
    intent.putExtra(FileChooserActivity._SaveLastLocation, false);
    intent.putExtra(FileChooserActivity._DisplayHiddenFiles, false);
    intent.putExtra(FileChooserActivity._ShowNewFolderButton, false);
    intent.putExtra(FileChooserActivity._FilenameRegExp, regexp);
    intent.putExtra(FileChooserActivity._FilterMode, IFileProvider.FilterMode.FilesOnly);
    activity.startActivityForResult(intent, requestCode);
}
Also used : LocalFile(group.pals.android.lib.ui.filechooser.io.localfile.LocalFile) Intent(android.content.Intent)

Example 2 with LocalFile

use of group.pals.android.lib.ui.filechooser.io.localfile.LocalFile in project FBReaderJ by geometer.

the class LocalFileProvider method listAllFiles.

// listFiles()
@Override
public List<IFile> listAllFiles(IFile dir, final boolean[] hasMoreFiles) throws Exception {
    if (!(dir instanceof File) || !dir.canRead())
        return null;
    if (hasMoreFiles != null && hasMoreFiles.length > 0)
        hasMoreFiles[0] = false;
    final List<IFile> _files = new ArrayList<IFile>();
    try {
        IFile root = dir.parentFile();
        if (root.parentFile() == null && LocalFileProvider.this.accept(root))
            _files.add(root);
        File[] files = ((File) dir).listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                LocalFile file = new LocalFile(pathname);
                if (!LocalFileProvider.this.accept(file))
                    return false;
                if (_files.size() >= getMaxFileCount()) {
                    if (hasMoreFiles != null && hasMoreFiles.length > 0)
                        hasMoreFiles[0] = true;
                    return false;
                }
                _files.add(file);
                return false;
            }
        });
        if (files != null) {
            Collections.sort(_files, new FileComparator(getSortType(), getSortOrder()));
            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) FileComparator(group.pals.android.lib.ui.filechooser.utils.FileComparator) 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 3 with LocalFile

use of group.pals.android.lib.ui.filechooser.io.localfile.LocalFile in project FBReaderJ by geometer.

the class FileChooserUtil method runDirectoryChooser.

public static void runDirectoryChooser(Activity activity, int requestCode, String title, String initialValue, boolean chooseWritableDirsOnly) {
    final Intent intent = new Intent(activity, FileChooserActivity.class);
    intent.putExtra(FileChooserActivity._TextResources, textResources(title));
    intent.putExtra(FileChooserActivity._Rootpath, (Parcelable) new LocalFile(initialValue));
    intent.putExtra(FileChooserActivity._ActionBar, true);
    intent.putExtra(FileChooserActivity._SaveLastLocation, false);
    intent.putExtra(FileChooserActivity._DisplayHiddenFiles, true);
    intent.putExtra(FileChooserActivity._FilterMode, chooseWritableDirsOnly ? IFileProvider.FilterMode.DirectoriesOnly : IFileProvider.FilterMode.AnyDirectories);
    activity.startActivityForResult(intent, requestCode);
}
Also used : LocalFile(group.pals.android.lib.ui.filechooser.io.localfile.LocalFile) Intent(android.content.Intent)

Example 4 with LocalFile

use of group.pals.android.lib.ui.filechooser.io.localfile.LocalFile 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 5 with LocalFile

use of group.pals.android.lib.ui.filechooser.io.localfile.LocalFile 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)

Aggregations

LocalFile (group.pals.android.lib.ui.filechooser.io.localfile.LocalFile)5 IFile (group.pals.android.lib.ui.filechooser.io.IFile)3 IFileFilter (group.pals.android.lib.ui.filechooser.io.IFileFilter)3 ParentFile (group.pals.android.lib.ui.filechooser.io.localfile.ParentFile)3 File (java.io.File)3 FileFilter (java.io.FileFilter)3 ArrayList (java.util.ArrayList)3 Intent (android.content.Intent)2 FileComparator (group.pals.android.lib.ui.filechooser.utils.FileComparator)1