コード例 #1
0
 public static boolean isStorageOrSd(File fi) {
   if (fi == null) return false;
   else if (fi.getPluginPackage() != null)
     return File.isRootPluginFolder(fi.getUri(), ((PluginFileImpl) fi).getPlugin());
   return fi.isSDCardDirectory()
       || fi.isStorageDirectory()
       || (fi.isDocumentTreeFile() && fi.getParent() == null);
 }
コード例 #2
0
  public void setActiveOrAdd(@NonNull Crumb crumb, boolean forceRecreate) {
    if (forceRecreate || !setActive(crumb)) {
      clearCrumbs();
      final List<File> newPathSet = new ArrayList<>();

      newPathSet.add(0, crumb.getFile());

      File p = crumb.getFile();
      if (!isStorageOrSd(p)) {
        while ((p = p.getParent()) != null) {
          newPathSet.add(0, p);
          if (isStorageOrSd(p)) break;
        }
      }

      for (int index = 0; index < newPathSet.size(); index++) {
        final File fi = newPathSet.get(index);
        crumb = new Crumb(fi);

        // Restore scroll positions saved before clearing
        if (mOldCrumbs != null) {
          for (Iterator<Crumb> iterator = mOldCrumbs.iterator(); iterator.hasNext(); ) {
            Crumb old = iterator.next();
            if (old.equals(crumb)) {
              crumb.setScrollPosition(old.getScrollPosition());
              crumb.setScrollOffset(old.getScrollOffset());
              crumb.setQuery(old.getQuery());
              iterator.remove(); // minimize number of linear passes by removing un-used crumbs from
              // history
              break;
            }
          }
        }

        addCrumb(crumb, true);
      }

      // History no longer needed
      mOldCrumbs = null;
    } else {
      if (isStorageOrSd(crumb.getFile())) {
        Crumb c = mCrumbs.get(0);
        while (c != null && !isStorageOrSd(c.getFile())) {
          removeCrumbAt(0);
          if (mCrumbs.size() > 0) c = mCrumbs.get(0);
        }
        updateIndices();
        requestLayout();
      }
    }
  }