aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/SimpleDirChooser.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/files/SimpleDirChooser.java')
-rw-r--r--main/src/cgeo/geocaching/files/SimpleDirChooser.java33
1 files changed, 25 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java
index cf969dc..e59287d 100644
--- a/main/src/cgeo/geocaching/files/SimpleDirChooser.java
+++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java
@@ -32,17 +32,20 @@ import java.util.List;
* Dialog for choosing a file or directory.
*/
public class SimpleDirChooser extends AbstractListActivity {
+ public static final String EXTRA_CHOOSE_FOR_WRITING = "chooseForWriting";
private static final String PARENT_DIR = ".. ";
private File currentDir;
private FileArrayAdapter adapter;
private Button okButton = null;
private int lastPosition = -1;
+ private boolean chooseForWriting = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle extras = getIntent().getExtras();
currentDir = dirContaining(extras.getString(Intents.EXTRA_START_DIR));
+ chooseForWriting = extras.getBoolean(SimpleDirChooser.EXTRA_CHOOSE_FOR_WRITING, false);
ActivityMixin.setTheme(this);
setContentView(R.layout.simple_dir_chooser);
@@ -85,19 +88,20 @@ public class SimpleDirChooser extends AbstractListActivity {
}
private void fill(File dir) {
+ lastPosition = -1;
EditText path = (EditText) findViewById(R.id.simple_dir_chooser_path);
path.setText(this.getResources().getString(R.string.simple_dir_chooser_current_path) + " " + dir.getAbsolutePath());
final File[] dirs = dir.listFiles(new DirOnlyFilenameFilter());
List<Option> listDirs = new ArrayList<Option>();
try {
for (File currentDir : dirs) {
- listDirs.add(new Option(currentDir.getName(), currentDir.getAbsolutePath()));
+ listDirs.add(new Option(currentDir.getName(), currentDir.getAbsolutePath(), currentDir.canWrite()));
}
- } catch (Exception e) {
+ } catch (RuntimeException e) {
}
Collections.sort(listDirs);
if (dir.getParent() != null) {
- listDirs.add(0, new Option(PARENT_DIR, dir.getParent()));
+ listDirs.add(0, new Option(PARENT_DIR, dir.getParent(), false));
}
this.adapter = new FileArrayAdapter(this, R.layout.simple_dir_item, listDirs);
this.setListAdapter(adapter);
@@ -138,8 +142,13 @@ public class SimpleDirChooser extends AbstractListActivity {
}
CheckBox check = (CheckBox) v.findViewById(R.id.CheckBox);
if (check != null) {
- check.setOnClickListener(new OnCheckBoxClickListener(position));
- check.setChecked(option.isChecked());
+ if (!chooseForWriting || option.isWriteable()) {
+ check.setOnClickListener(new OnCheckBoxClickListener(position));
+ check.setChecked(option.isChecked());
+ check.setEnabled(true);
+ } else {
+ check.setEnabled(false);
+ }
}
}
return v;
@@ -156,7 +165,6 @@ public class SimpleDirChooser extends AbstractListActivity {
@Override
public void onClick(View arg0) {
Option option = adapter.getItem(position);
- lastPosition = -1;
if (option.getName().equals(PARENT_DIR)) {
currentDir = new File(option.getPath());
fill(currentDir);
@@ -197,14 +205,19 @@ public class SimpleDirChooser extends AbstractListActivity {
}
}
+ /**
+ * Note: this class has a natural ordering that is inconsistent with equals.
+ */
public static class Option implements Comparable<Option> {
private final String name;
private final String path;
private boolean checked = false;
+ private boolean writeable = false;
- public Option(String name, String path) {
+ public Option(String name, String path, boolean writeable) {
this.name = name;
this.path = path;
+ this.writeable = writeable;
}
public String getName() {
@@ -223,6 +236,10 @@ public class SimpleDirChooser extends AbstractListActivity {
this.checked = checked;
}
+ public boolean isWriteable() {
+ return writeable;
+ }
+
@Override
public int compareTo(Option other) {
if (other != null && this.name != null) {
@@ -237,7 +254,7 @@ public class SimpleDirChooser extends AbstractListActivity {
@Override
public boolean accept(File dir, String filename) {
File file = new File(dir, filename);
- return file.isDirectory() && file.canWrite();
+ return file.isDirectory() && file.canRead();
}
}