a
554325746@qq.com
2019-12-24 570a73851c26d810c2597596a8acc8a8d4cde211
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.obsez.android.lib.filechooser.internals;
import java.io.File;
import java.io.FileFilter;
/**
 * Created by coco on 6/7/15.
 */
public class ExtFileFilter implements FileFilter {
    boolean m_allowHidden;
    boolean m_onlyDirectory;
    String[] m_ext;
    public ExtFileFilter() {
        this(false, false);
    }
    public ExtFileFilter(String... ext_list) {
        this(false, false, ext_list);
    }
    public ExtFileFilter(boolean dirOnly, boolean hidden, String... ext_list) {
        m_allowHidden = hidden;
        m_onlyDirectory = dirOnly;
        m_ext = ext_list;
    }
    @Override
    public boolean accept(File pathname) {
        if (!m_allowHidden) {
            if (pathname.isHidden()) {
                return false;
            }
        }
        if (m_onlyDirectory) {
            if (!pathname.isDirectory()) {
                return false;
            }
        }
        if (m_ext == null) {
            return true;
        }
        if (pathname.isDirectory()) {
            return true;
        }
        String ext = FileUtil.getExtensionWithoutDot(pathname);
        for (String e : m_ext) {
            if (ext.equalsIgnoreCase(e)) {
                return true;
            }
        }
        return false;
    }
}