project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java Sat Aug 18 00:22:33 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java Sat Aug 18 00:47:51 2012 +0200
@@ -2,18 +2,20 @@
import java.io.File;
import java.io.FileNotFoundException;
+import java.util.ArrayList;
import java.util.Comparator;
+import java.util.List;
-import org.hedgewars.hedgeroid.Utils;
+import org.hedgewars.hedgeroid.R;
+import org.hedgewars.hedgeroid.util.FileUtils;
import android.content.Context;
-import android.widget.AdapterView.OnItemSelectedListener;
+import android.content.res.Resources;
/**
* Represents a map from the data directory
*/
public final class MapFile {
- public static final String MISSION_PREFIX = "Mission: "; // TODO move text generation to UI to allow translation
public static final String MAP_DIRECTORY = "Maps";
public final String name;
@@ -28,7 +30,7 @@
* @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist.
*/
public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException {
- return new File(new File(Utils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
+ return new File(new File(FileUtils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
}
public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() {
@@ -43,10 +45,23 @@
@Override
public String toString() {
- return (isMission ? MISSION_PREFIX : "") + name;
+ return "MapFile [name=" + name + ", isMission=" + isMission + "]";
}
public File getPreviewFile(Context c) throws FileNotFoundException {
- return new File(new File(new File(Utils.getDataPathFile(c), MAP_DIRECTORY), name), "preview.png");
- };
+ return getPreviewFile(c, name);
+ }
+
+ public static File getPreviewFile(Context c, String mapName) throws FileNotFoundException {
+ return new File(FileUtils.getDataPathFile(c), MAP_DIRECTORY + "/" + mapName + "/" + "preview.png");
+ }
+
+ public static List<String> toDisplayNameList(List<MapFile> mapFiles, Resources res) {
+ String missionPrefix = res.getString(R.string.map_mission_prefix);
+ List<String> result = new ArrayList<String>();
+ for(MapFile mapFile : mapFiles) {
+ result.add((mapFile.isMission ? missionPrefix : "") + mapFile.name);
+ }
+ return result;
+ }
}