安卓文件管理器
-
排序文件
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; } }
-
判断文件类型
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);
}
原文地址:https://blog.csdn.net/qq_44203816/article/details/136528673
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!