@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
      if (backStack.size() > 1) {
        backStack.remove(backStack.size() - 1);
        wrapFiles();
      } else {
        Intent intent = new Intent();
        setResult(RESULT_CANCELED, intent);
        finish();
      }
      return true;
    }

    return super.onKeyDown(keyCode, event);
  }
  @Override
  public void onItemClick(AdapterView<?> aListView, View aView, int aPosition, long aID) {
    final FileWrapper item = adapter.getItem(aPosition);

    if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) {
      backStack.remove(backStack.size() - 1);
      wrapFiles();
      return;
    } else if (item.dirSelectItem) {
      finishWithPath(listedDirectory.getAbsolutePath());
      return;
    }

    final File selected = item.parentItem ? listedDirectory.getParentFile() : item.file;

    if (selected.isDirectory()) {
      backStack.add(new BackStackItem(selected.getAbsolutePath(), !item.parentItem));
      wrapFiles();
    } else {
      String filePath = selected.getAbsolutePath();
      finishWithPath(filePath);
    }
  }