cn.qqtheme.framework.util.FileUtils Java Examples

The following examples show how to use cn.qqtheme.framework.util.FileUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileAdapter.java    From AndroidPicker with MIT License 4 votes vote down vote up
public void loadData(String path) {
    if (path == null) {
        LogUtils.warn("current directory is null");
        return;
    }
    if (homeIcon == null) {
        homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHOME());
    }
    if (upIcon == null) {
        upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUPDIR());
    }
    if (folderIcon == null) {
        folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFOLDER());
    }
    if (fileIcon == null) {
        fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFILE());
    }
    ArrayList<FileItem> datas = new ArrayList<FileItem>();
    if (rootPath == null) {
        rootPath = path;
    }
    LogUtils.verbose("current directory path: " + path);
    currentPath = path;
    if (showHomeDir) {
        //添加“返回主目录”
        FileItem fileRoot = new FileItem();
        fileRoot.setDirectory(true);
        fileRoot.setIcon(homeIcon);
        fileRoot.setName(DIR_ROOT);
        fileRoot.setSize(0);
        fileRoot.setPath(rootPath);
        datas.add(fileRoot);
    }
    if (showUpDir && !path.equals("/")) {
        //添加“返回上一级目录”
        FileItem fileParent = new FileItem();
        fileParent.setDirectory(true);
        fileParent.setIcon(upIcon);
        fileParent.setName(DIR_PARENT);
        fileParent.setSize(0);
        fileParent.setPath(new File(path).getParent());
        datas.add(fileParent);
    }
    File[] files;
    if (allowExtensions == null) {
        if (onlyListDir) {
            files = FileUtils.listDirs(currentPath);
        } else {
            files = FileUtils.listDirsAndFiles(currentPath);
        }
    } else {
        if (onlyListDir) {
            files = FileUtils.listDirs(currentPath, allowExtensions);
        } else {
            files = FileUtils.listDirsAndFiles(currentPath, allowExtensions);
        }
    }
    if (files != null) {
        for (File file : files) {
            if (!showHideDir && file.getName().startsWith(".")) {
                continue;
            }
            FileItem fileItem = new FileItem();
            boolean isDirectory = file.isDirectory();
            fileItem.setDirectory(isDirectory);
            if (isDirectory) {
                fileItem.setIcon(folderIcon);
                fileItem.setSize(0);
            } else {
                fileItem.setIcon(fileIcon);
                fileItem.setSize(file.length());
            }
            fileItem.setName(file.getName());
            fileItem.setPath(file.getAbsolutePath());
            datas.add(fileItem);
        }
    }
    data.clear();
    data.addAll(datas);
    notifyDataSetChanged();
}