/* Scan the files in the new directory, and store them in the filelist.
   * Update the UI by refreshing the list adapter.
   */
  private void loadDirectory(String newdirectory) {
    if (newdirectory.equals("../")) {
      try {
        directory = new File(directory).getParent();
      } catch (Exception e) {
      }
    } else {
      directory = newdirectory;
    }
    SharedPreferences.Editor editor = getPreferences(0).edit();
    editor.putString("lastBrowsedDirectory", directory);
    editor.commit();
    directoryView.setText(directory);

    filelist = new ArrayList<FileUri>();
    ArrayList<FileUri> sortedDirs = new ArrayList<FileUri>();
    ArrayList<FileUri> sortedFiles = new ArrayList<FileUri>();
    if (!newdirectory.equals(rootdir)) {
      String parentDirectory = new File(directory).getParent() + "/";
      Uri uri = Uri.parse("file://" + parentDirectory);
      sortedDirs.add(new FileUri(uri, parentDirectory));
    }
    try {
      File dir = new File(directory);
      File[] files = dir.listFiles();
      if (files != null) {
        for (File file : files) {
          if (file == null) {
            continue;
          }
          String filename = file.getName();
          if (file.isDirectory()) {
            Uri uri = Uri.parse("file://" + file.getAbsolutePath() + "/");
            FileUri fileuri = new FileUri(uri, uri.getPath());
            sortedDirs.add(fileuri);
          } else if (filename.endsWith(".mid")
              || filename.endsWith(".MID")
              || filename.endsWith(".midi")
              || filename.endsWith(".MIDI")) {

            Uri uri = Uri.parse("file://" + file.getAbsolutePath());
            FileUri fileuri = new FileUri(uri, uri.getLastPathSegment());
            sortedFiles.add(fileuri);
          }
        }
      }
    } catch (Exception e) {
    }

    if (sortedDirs.size() > 0) {
      Collections.sort(sortedDirs, sortedDirs.get(0));
    }
    if (sortedFiles.size() > 0) {
      Collections.sort(sortedFiles, sortedFiles.get(0));
    }
    filelist.addAll(sortedDirs);
    filelist.addAll(sortedFiles);
    adapter = new IconArrayAdapter<FileUri>(this, android.R.layout.simple_list_item_1, filelist);
    this.setListAdapter(adapter);
  }
Exemplo n.º 2
0
  private void deleteLocation(LocationInfo info) {
    if (NavigineApp.Navigation == null) return;

    if (info != null) {
      try {
        (new File(info.archiveFile)).delete();
        info.localVersion = -1;
        info.localModified = false;

        String locationDir = LocationLoader.getLocationDir(mContext, info.title);
        File dir = new File(locationDir);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) files[i].delete();
        dir.delete();

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }

        mAdapter.updateList();
      } catch (Throwable e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }
  }
  private void getAvailableMissionList() {
    try {
      File missionFolder = new File(Environment.getExternalStorageDirectory() + "/Mission Files");
      // gets a list of the files
      File[] sdDirList = missionFolder.listFiles();

      String missionTitle;
      String missionDesc;
      String pBest;
      File fileToHandle;
      for (int i = 0; i < sdDirList.length; i++) {
        fileToHandle =
            new File(
                Environment.getExternalStorageDirectory()
                    + "/Mission Files/"
                    + sdDirList[i].getName());
        String params = ReadFileContents(fileToHandle);
        String[] tokenized = params.split("\n");
        missionTitle = tokenized[0];
        missionDesc = tokenized[1];
        pBest = "N/K";
        availableMissions.add(
            new MissionSummary(missionTitle, missionDesc, pBest, fileToHandle.getName(), this));
      }
    } catch (NullPointerException e) {
      availableMissions.add(
          new MissionSummary(
              "No missions found", "Click here to download new missions", "", "N/A", this));
    }
  }
 private String[] filesAtPath(String path) {
   File directory = new File(path);
   directory.mkdir();
   ArrayList<String> filesNames = new ArrayList<String>();
   for (File file : directory.listFiles()) filesNames.add(file.getName());
   String[] filesNamesArray = new String[filesNames.size()];
   return filesNames.toArray(filesNamesArray);
 }
Exemplo n.º 5
0
  private void wrapFiles() {
    listedDirectory = new File(backStack.get(backStack.size() - 1).path);

    if (!listedDirectory.isDirectory()) {
      throw new IllegalArgumentException("Directory is not valid.");
    }

    adapter.clear();
    setTitle(listedDirectory.getAbsolutePath());

    if (isDirectoryTarget) adapter.add(new FileWrapper(null, FileWrapper.DIRSELECT, true));

    if (listedDirectory.getParentFile() != null)
      adapter.add(new FileWrapper(null, FileWrapper.PARENT, true));

    // Copy new items
    final File[] files = listedDirectory.listFiles();
    if (files != null) {
      for (File file : files) {
        String path = file.getName();

        boolean allowFile = file.isDirectory() || (filterPath(path) && !isDirectoryTarget);

        if (allowFile)
          adapter.add(new FileWrapper(file, FileWrapper.FILE, file.isDirectory() || true));
      }
    }

    // Sort items
    adapter.sort(
        new Comparator<FileWrapper>() {
          @Override
          public int compare(FileWrapper aLeft, FileWrapper aRight) {
            return aLeft.compareTo(aRight);
          };
        });

    // Update
    adapter.notifyDataSetChanged();
  }