Android Open Source - file-browser File Info






From Project

Back to project page file-browser.

License

The source code is released under:

Copyright (c) 2014, Hyusein Gyulyustan All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are m...

If you think the Android project file-browser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hglstn.filebrowser;
/*from   w  ww . j  av a2 s.  co  m*/
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FileInfo {

  private static final java.text.DateFormat dateFormat = SimpleDateFormat
      .getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);

  private final String filePath;
  private final boolean isDirectory;
  private final String permissions;
  private final Calendar lastModifiedTime;
  private final int itemsCount;
  private final long size;

  public FileInfo(String filePath, String permissions,
      Calendar lastModifiedTime, boolean isDirectory, int itemsCount,
      long size) {
    if (!filePath.startsWith("/")) {
      throw new IllegalArgumentException("Must specify an absolute path");
    }
    if (lastModifiedTime == null) {
      throw new IllegalArgumentException(
          "Must specify last modified time");
    }

    if (permissions == null) {
      permissions = "---";
    }

    this.filePath = filePath;
    this.isDirectory = isDirectory;
    this.permissions = permissions;
    this.lastModifiedTime = lastModifiedTime;
    this.itemsCount = itemsCount;
    this.size = size;
  }

  public String getFilePath() {
    return filePath;
  }

  boolean isDirectory() {
    return isDirectory;
  }

  public String getParent() {
    return getParent(filePath);
  }

  public static String getParent(String filePath) {
    if (filePath.equals("/")) {
      return null;
    }
    int pos = filePath.lastIndexOf('/');
    if (pos == 0) {
      return "/";
    }
    // pos can't be -1
    return filePath.substring(0, pos);
  }

  public String getDisplayName() {
    int pos = filePath.lastIndexOf("/");
    int endpos = filePath.length() - 1;

    if (pos < endpos) {
      return filePath.substring(pos + 1);
    }
    return filePath;
  }

  public int getIconResource() {
    int res = R.drawable.default_file;
    if (isDirectory) {
      return res = R.drawable.folder_256;
    }
    return res;
  }

  public String getSizeInfo() {
    return isDirectory ? String.valueOf(itemsCount) + " Items" : String
        .valueOf(size / 1024) + " KB";
  }

  public String getPermissions() {
    return permissions;
  }

  public String getModificationTime() {
    return dateFormat.format(lastModifiedTime.getTime());
  }
}




Java Source Code List

com.hglstn.filebrowser.FileBrowserFragment.java
com.hglstn.filebrowser.FileInfoAdapter.java
com.hglstn.filebrowser.FileInfo.java
com.hglstn.filebrowser.FileSystem.java
com.hglstn.filebrowser.LocalFileSystem.java
com.hglstn.filebrowser.MainActivity.java