Esempio n. 1
0
 public static Drawable getIconForFile(Context c, String mimeType, File f) {
   if (f.isDirectory()) {
     return getFolderIcon(c);
   } else {
     MimeTypes mimeTypes = ((FileManagerApplication) c.getApplicationContext()).getMimeTypes();
     return mimeTypes.getIcon(c, mimeType);
   }
 }
Esempio n. 2
0
  /**
   * @param root Folder to start search from.
   * @param filter The FilenameFilter to use for matching.
   * @param mimeTypes Initialized MimeTypes instance.
   * @param context A context.
   * @param recursive Whether to recursively follow the paths.
   * @param maxLevel How many levels below the current we're allowed to recurse.
   * @return A list of FileHolders found in root and matching filter.
   */
  public static List<FileHolder> searchIn(
      File root,
      FilenameFilter filter,
      MimeTypes mimeTypes,
      Context context,
      boolean recursive,
      int maxLevel) {
    ArrayList<FileHolder> result = new ArrayList<>(10);

    File[] filteredFiles = root.listFiles(filter);
    if (filteredFiles != null) {
      for (File f : filteredFiles) {
        String mimeType = mimeTypes.getMimeType(f.getName());

        result.add(new FileHolder(f, mimeType, getIconForFile(context, mimeType, f)));
      }
    }

    File[] files = root.listFiles();
    if (files != null) {
      if (recursive && (maxLevel-- != 0)) {
        for (File f : files) {
          // Prevent trying to search invalid folders
          if (f.isDirectory() && f.canRead()) {
            result.addAll(searchIn(f, filter, mimeTypes, context, true, maxLevel));
          }
        }
      }
    }

    return result;
  }