安卓文件管理器

时间:2024-03-09 22:09:45
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; } }