安卓文件管理器

  • 排序文件

    java 复制代码
    static public void sortFiles(File[] mf, int mode) {
        switch (mode) {
        case FileConst.SORT_NAME:
            Arrays.sort(mf, new Comparator<File>() {
                public int compare(File object1, File object2) {
                    return object1.getName().compareTo(object2.getName());
                }
            });
            break;
        case FileConst.SORT_DATE:
            Arrays.sort(mf, new Comparator<File>() {
                public int compare(File object1, File object2) {
                    if (object1.lastModified() < object2.lastModified()) {
                        return -1;
                    } else if (object1.lastModified() == object2.lastModified()) {
                        return 0;
                    } else
                        return 1;
                }
            });
            break;
        case FileConst.SORT_TYPE:
            Arrays.sort(mf, new Comparator<File>() {
                public int compare(File object1, File object2) {
                    if ( object1.getName().lastIndexOf('.') == -1 )
                        return -1;
                    else if ( object2.getName().lastIndexOf('.') == -1 )
                        return 1;
                    String obj1 = object1.getName().substring(object1.getName().lastIndexOf('.')).toLowerCase();
                    String obj2 = object2.getName().substring(object2.getName().lastIndexOf('.')).toLowerCase();
                    return obj1.compareTo(obj2);
                }
            });
            break;
        case FileConst.SORT_GENRE:
             Arrays.sort(mf, new Comparator<File>() {
                 public int compare(File object1, File object2) {
                    if( object1.isDirectory())
                         return -1;
                    else if(object2.isDirectory())
                         return 1;
                    AudioFile obj1 = new AudioFile(new MtkFile(object1));
                     AudioFile obj2 = new AudioFile(new MtkFile(object2));
                    MetaData mMetaData1 = obj1.getMetaDataInfo();
                    MetaData mMetaData2 = obj2.getMetaDataInfo();
                     if( mMetaData1 == null )
                         return -1;
                     else if( mMetaData2 == null )
                         return 1;
                     String info1 = mMetaData1.getGenre();
                     String info2 = mMetaData2.getGenre();
                     if( info1 == null )
                         return -1;
                     else if( info2 == null )
                         return 1;
                    return info1.compareTo(info2);
                 }
             });
            break;
        case FileConst.SORT_ARTIST:
             Arrays.sort(mf, new Comparator<File>() {
                 public int compare(File object1, File object2) {
                    if( object1.isDirectory())
                         return -1;
                    else if(object2.isDirectory())
                         return 1;
                    AudioFile obj1 = new AudioFile(new MtkFile(object1));
                     AudioFile obj2 = new AudioFile(new MtkFile(object2));
                    MetaData mMetaData1 = obj1.getMetaDataInfo();
                    MetaData mMetaData2 = obj2.getMetaDataInfo();
                     if( mMetaData1 == null )
                         return -1;
                     else if( mMetaData2 == null )
                         return 1;
                     String info1 = mMetaData1.getArtist();
                     String info2 = mMetaData2.getArtist();
                     if( info1 == null )
                         return -1;
                     else if( info2 == null )
                         return 1;
                    return info1.compareTo(info2);
                 }
             });
            break;
        case FileConst.SORT_ALBUM:
            Arrays.sort(mf, new Comparator<File>() {
                public int compare(File object1, File object2) {
                    if( object1.isDirectory())
                            return -1;
                        else if(object2.isDirectory())
                            return 1;
                    AudioFile obj1 = new AudioFile(new MtkFile(object1));
                    AudioFile obj2 = new AudioFile(new MtkFile(object2));
                    MetaData mMetaData1 = obj1.getMetaDataInfo();
                    MetaData mMetaData2 = obj2.getMetaDataInfo();
                     if( mMetaData1 == null )
                         return -1;
                     else if( mMetaData2 == null )
                         return 1;
                    String info1 = mMetaData1.getAlbum();
                     String info2 = mMetaData2.getAlbum();
                     if( info1 == null )
                         return -1;
                     else if( info2 == null )
                         return 1;
                    return info1.compareTo(info2);
                }
            });
            break;
    
        default:
            break;
        }
    }
  • 判断文件类型

java 复制代码
private boolean filterFile(String[] mode) {
   if (mode == null) {
     return false;
   }
   for (String s : mode) {
     if (this.getName().toLowerCase().endsWith(s)) {
       return true;
     }
   }
   return false;
 }
public static final String audioSuffix[] = {
     ".mp3", ".wma", ".m3u",
     ".m3u8", ".wav", ".aif", ".m4a", ".aac", ".ac3", ".ec3", ".pls",
     ".wpl", ".ogg", ".mp2", ".ra", ".flac", ".ape", ".amr", ".ac4"
     ,".awb",".rm"
 };
 public static final String videoSuffix[] = {
     ".rmvb", ".avi", ".mkv",
     ".mp4", ".3gp", ".flv", ".mpg", ".ts", ".wmv", ".vob", ".rm",
     ".mov", ".avs", ".divx", ".asf", ".mpe", ".mpeg", ".dat", ".asx",
     ".m4v", ".tp", ".trp", ".tts", ".m2ts", ".mts", ".m1v", ".m2v",
     ".m4v", ".264", ".vc1", ".flv", ".hlv", ".pvr", ".ogm", ".webm",
     ".ram", ".iso", ".ssif", ".264", ".265", ".avs2", ".heic", ".ivf",
     ".m2t"
 };
public static final String photoSuffix[] = {
     ".png", ".bmp", ".jpg",
     ".PNG", ".jpeg", ".gif", ".webp", ".heif", ".heic"
 };
public boolean isPhotoFile() {

   return filterFile(FileConst.photoSuffix);
 }
相关推荐
2501_9159184125 分钟前
iOS 26 App 性能测试|性能评测|iOS 26 性能对比:实战策略
android·macos·ios·小程序·uni-app·cocoa·iphone
Predestination王瀞潞29 分钟前
IO操作(Num22)
开发语言·c++
瓯雅爱分享1 小时前
Java+Vue构建的采购招投标一体化管理系统,集成招标计划、投标审核、在线竞价、中标公示及合同跟踪功能,附完整源码,助力企业实现采购全流程自动化与规范化
java·mysql·vue·软件工程·源代码管理
宋恩淇要努力2 小时前
C++继承
开发语言·c++
沿着路走到底3 小时前
python 基础
开发语言·python
沐知全栈开发4 小时前
C# 委托(Delegate)
开发语言
mit6.8244 小时前
[C# starter-kit] 命令/查询职责分离CQRS | MediatR |
java·数据库·c#
咋吃都不胖lyh4 小时前
SQL-多对多关系
android·mysql·数据分析
诸神缄默不语4 小时前
Maven用户设置文件(settings.xml)配置指南
xml·java·maven
任子菲阳4 小时前
学Java第三十四天-----抽象类和抽象方法
java·开发语言