/* 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 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.º 4
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();
  }
Exemplo n.º 5
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    adpt = new GalleryAdapter(this);
    pics = new Vector<Image>();

    previews = (Gallery) findViewById(R.id.gallery1);
    Main = (ImageView) findViewById(R.id.PictureView);
    hist = (Histogram) findViewById(R.id.histogram);
    saturation = (SeekBar) findViewById(R.id.saturation);
    contrast = (SeekBar) findViewById(R.id.contrast);
    exposure = (SeekBar) findViewById(R.id.exposure);
    saveButton = (Button) findViewById(R.id.save);

    contrast.setProgress(50);
    exposure.setProgress(50);
    saturation.setProgress(100);

    handler = new UIHandler(Main, hist);
    tm = new ThreadManager(handler);
    save = new Save();
    save.setContainer(Main);

    PinchyZoomy pz = new PinchyZoomy();

    Main.setOnTouchListener(pz);
    Main.setDrawingCacheEnabled(true);
    Main.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

    File folder = new File("/sdcard");

    for (int i = 0; i < folder.listFiles().length; i++) {
      String name = folder.listFiles()[i].getName();
      if (folder.listFiles()[i].isFile()) {
        String extension = name.substring(name.length() - 3);
        if (extension.equals("NEF") || extension.equals("dng")) {
          Image temp = new Image(folder.listFiles()[i].getAbsolutePath());
          pics.add(temp);
        }
      }
    }

    for (int i = 0; i < pics.size(); i++) {
      System.out.println("Pulling thumb for: " + pics.elementAt(i).path);
      adpt.addImage(pics.elementAt(i).getThumb());
    }

    previews.setAdapter(adpt);
    previews.setSpacing(3);

    previews.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Main.setImageBitmap(adpt.getItemAt(position));
            Main.setAlpha(100);

            if (current != null) current.free();

            current = pics.elementAt(position);
            handler.setImage(current);
            tm.pic = current;
            save.setImage(current);

            contrast.setProgress(50);
            exposure.setProgress(50);
            saturation.setProgress(100);

            LoadImageThread t = new LoadImageThread(current, handler);
            t.start();
          }
        });

    saturation.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {

          @Override
          public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {

            if (current.colors != null) tm.setSaturation(saturation.getProgress());
          }

          @Override
          public void onStartTrackingTouch(SeekBar arg0) {}

          @Override
          public void onStopTrackingTouch(SeekBar arg0) {}
        });
    contrast.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (current.colors != null) tm.setContrast(contrast.getProgress());
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

          }
        });
    exposure.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (current.colors != null) tm.setExposure(exposure.getProgress());
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

          }
        });

    saveButton.setOnClickListener(save);
  }