diff options
| author | rsudev <rasch@munin-soft.de> | 2012-10-27 00:17:31 +0200 |
|---|---|---|
| committer | rsudev <rasch@munin-soft.de> | 2012-11-03 23:24:18 +0100 |
| commit | f5343eac8a433b198d47057a112e4c92486906b3 (patch) | |
| tree | f4eda41be808315c30768ffc362689dec62fda72 /main/src/cgeo/geocaching/utils | |
| parent | c942e65f13579e96ef528f8a7641f3571ce963dd (diff) | |
| download | cgeo-f5343eac8a433b198d47057a112e4c92486906b3.zip cgeo-f5343eac8a433b198d47057a112e4c92486906b3.tar.gz cgeo-f5343eac8a433b198d47057a112e4c92486906b3.tar.bz2 | |
Implements #1676, custom themes
- Adds the selection of a base folder for map themes to settings
- Reworks the map menu to allow selection of a custom theme
- Implements a reusable version of listDir to get a list of files
Diffstat (limited to 'main/src/cgeo/geocaching/utils')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/FileUtils.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/FileUtils.java b/main/src/cgeo/geocaching/utils/FileUtils.java new file mode 100644 index 0000000..6fefc02 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/FileUtils.java @@ -0,0 +1,64 @@ +package cgeo.geocaching.utils; + +import org.apache.commons.lang3.ArrayUtils; + +import android.os.Handler; +import android.os.Message; + +import java.io.File; +import java.util.List; + +/** + * Utiliy class for files + * + * @author rsudev + * + */ +public class FileUtils { + + public static void listDir(List<File> result, File directory, FileSelector chooser, Handler feedBackHandler) { + + if (directory == null || !directory.isDirectory() || !directory.canRead() + || result == null + || chooser == null) { + return; + } + + final File[] files = directory.listFiles(); + + if (ArrayUtils.isNotEmpty(files)) { + for (File file : files) { + if (chooser.shouldEnd()) { + return; + } + if (!file.canRead()) { + continue; + } + String name = file.getName(); + if (file.isFile()) { + if (chooser.isSelected(file)) { + result.add(file); // add file to list + } + } else if (file.isDirectory()) { + if (name.charAt(0) == '.') { + continue; // skip hidden directories + } + if (name.length() > 16) { + name = name.substring(0, 14) + '…'; + } + if (feedBackHandler != null) { + feedBackHandler.sendMessage(Message.obtain(feedBackHandler, 0, name)); + } + + listDir(result, file, chooser, feedBackHandler); // go deeper + } + } + } + } + + public static abstract class FileSelector { + public abstract boolean isSelected(File file); + + public abstract boolean shouldEnd(); + } +} |
