Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void fill(File f)
- {
- File[]dirs = f.listFiles();
- this.setTitle("Current Dir: "+f.getName());
- List<Item>dir = new ArrayList<Item>();
- List<Item>fls = new ArrayList<Item>();
- try{
- for(File ff: dirs)
- {
- Date lastModDate = new Date(ff.lastModified());
- final Calendar c = Calendar.getInstance();
- int time = Integer.parseInt(Time1);
- c.add(Calendar.MINUTE, - time);
- SimpleDateFormat dfDate = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- String currentDate = dfDate.format(c.getTime());
- String Date = dfDate.format(lastModDate);
- if(ff.isDirectory()){
- File[] fbuf = ff.listFiles();
- int buf = 0;
- if(fbuf != null){
- buf = fbuf.length;
- }
- else buf = 0;
- String num_item = String.valueOf(buf);
- if(buf == 0) num_item = num_item + " item";
- else num_item = num_item + " items";
- if (CheckDates(Date, currentDate)) {
- dir.add(new Item(ff.getName(), num_item, Date, ff.getAbsolutePath(), "directory_icon", Uri.fromFile(ff)));
- }
- }
- else
- {
- if (CheckDates(Date, currentDate)) {
- String name = ff.getName();
- String image;
- String extension = ff.getAbsolutePath().substring(ff.getAbsolutePath().lastIndexOf("."));
- if (extension.equals(".jpg") || extension.equals(".png") || extension.equals(".jpeg")) image = "file_image";
- else if (extension.equals(".pdf")) image = "file_pdf";
- else if (extension.equals(".pptx")) image = "file_powerpoint";
- else image = "file";
- fls.add(new Item(name , getSize(ff), Date, ff.getAbsolutePath(), image, Uri.fromFile(ff)));
- }
- }
- }
- }catch(Exception e)
- {
- }
- Collections.sort(dir);
- Collections.sort(fls);
- dir.addAll(fls);
- if(!f.getName().equalsIgnoreCase("sdcard"))
- dir.add(0,new Item("...","Parent Directory","",f.getParent(),"arrow", Uri.fromFile(f)));
- adapter = new FileArrayAdapter(FileChooser.this,R.layout.file_view,dir);
- this.setListAdapter(adapter);
- }
- private static boolean CheckDates(String startDate, String endDate) {
- if (startDate.compareTo(endDate)>0) {return true;}
- else {return false;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement