diff -r 7831c84cc644 -r 33924ff4af50 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java Mon Aug 20 21:05:57 2012 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/FrontendDataUtils.java Wed Aug 22 01:30:56 2012 +0200 @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.hedgewars.hedgeroid.R; import org.hedgewars.hedgeroid.util.FileUtils; @@ -38,9 +39,9 @@ /** * @throws FileNotFoundException if the sdcard isn't available or the Maps directory doesn't exist */ - public static ArrayList getMaps(Context c) throws FileNotFoundException { + public static List getMaps(Context c) throws FileNotFoundException { File[] files = FileUtils.getFilesFromRelativeDir(c,"Maps"); - ArrayList ret = new ArrayList(); + List ret = new ArrayList(); for(File f : files) { boolean isMission = FileUtils.hasFileWithSuffix(f, ".lua"); @@ -56,7 +57,7 @@ */ public static List getGameStyles(Context c) throws FileNotFoundException { File[] files = FileUtils.getFilesFromRelativeDir(c, "Scripts/Multiplayer"); - ArrayList ret = new ArrayList(); + List ret = new ArrayList(); /* * Caution: It is important that the "empty" style has this exact name, because * it will be interpreted as "don't load a script" by the frontlib, and also by @@ -84,23 +85,19 @@ /** * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist */ - public static ArrayList> getGraves(Context c) throws FileNotFoundException { - File gravePath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Graves"); - ArrayList names = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Graves", ".png", true); - ArrayList> data = new ArrayList>(names.size()); + public static List> getGraves(Context c) throws FileNotFoundException { + File gravePath = FileUtils.getDataPathFile(c, "Graphics", "Graves"); + List names = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Graves", ".png", true); + List> data = new ArrayList>(names.size()); for(String s : names){ HashMap map = new HashMap(); map.put("txt", s); Bitmap b = BitmapFactory.decodeFile(new File(gravePath, s + ".png").getAbsolutePath()); int width = b.getWidth(); - if(b.getHeight() > width){//some pictures contain more 'frames' underneath each other, if so we only use the first frame - Bitmap tmp = Bitmap.createBitmap(width, width, b.getConfig()); - int[] pixels = new int[width * width]; - b.getPixels(pixels, 0,width,0,0,width,width); - tmp.setPixels(pixels,0,width,0,0,width,width); - b.recycle(); - b = tmp; + if(b.getHeight() > width){ + // some pictures contain more 'frames' underneath each other, if so we only use the first frame + b = Bitmap.createBitmap(b, 0, 0, width, width); } map.put("img", b); data.add(map); @@ -111,13 +108,13 @@ /** * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist */ - public static ArrayList> getFlags(Context c) throws FileNotFoundException { - File flagsPath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Flags"); - ArrayList names = FileUtils.getFileNamesFromDirWithSuffix(c, "Graphics/Flags", ".png", true); - ArrayList> data = new ArrayList>(names.size()); + public static List> getFlags(Context c) throws FileNotFoundException { + File flagsPath = FileUtils.getDataPathFile(c, "Graphics", "Flags"); + List names = FileUtils.getFileNamesFromDirWithSuffix(c, "Graphics/Flags", ".png", true); + List> data = new ArrayList>(names.size()); for(String s : names){ - HashMap map = new HashMap(); + Map map = new HashMap(); map.put("txt", s); Bitmap b = BitmapFactory.decodeFile(new File(flagsPath, s + ".png").getAbsolutePath()); map.put("img", b); @@ -129,9 +126,9 @@ /** * @throws FileNotFoundException if the sdcard isn't available or the Sounds/voices directory doesn't exist */ - public static ArrayList getVoices(Context c) throws FileNotFoundException { + public static List getVoices(Context c) throws FileNotFoundException { File[] files = FileUtils.getFilesFromRelativeDir(c, "Sounds/voices"); - ArrayList ret = new ArrayList(); + List ret = new ArrayList(); for(File f : files){ if(f.isDirectory()) ret.add(f.getName()); @@ -142,17 +139,17 @@ /** * @throws FileNotFoundException if the sdcard isn't available or the Forts directory doesn't exist */ - public static ArrayList getForts(Context c) throws FileNotFoundException { + public static List getForts(Context c) throws FileNotFoundException { return FileUtils.getFileNamesFromDirWithSuffix(c,"Forts", "L.png", true); } - public static ArrayList> getTypes(Context c){ - ArrayList> data = new ArrayList>(6); + public static List> getTypes(Context c){ + List> data = new ArrayList>(6); String[] levels = {c.getString(R.string.human), c.getString(R.string.bot5), c.getString(R.string.bot4), c.getString(R.string.bot3), c.getString(R.string.bot2), c.getString(R.string.bot1)}; int[] images = {R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1}; for(int i = 0; i < levels.length; i++){ - HashMap map = new HashMap(); + Map map = new HashMap(); map.put("txt", levels[i]); map.put("img", images[i]); map.put("level", i); @@ -166,15 +163,14 @@ /** * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Hats directory doesn't exist */ - public static ArrayList> getHats(Context c) throws FileNotFoundException { - ArrayList files = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Hats", ".png", true); - File hatsPath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Hats"); + public static List> getHats(Context c) throws FileNotFoundException { + List files = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Hats", ".png", true); + File hatsPath = FileUtils.getDataPathFile(c, "Graphics", "Hats"); int size = files.size(); - ArrayList> data = new ArrayList>(size); + List> data = new ArrayList>(size); - HashMap hashmap; for(String s : files){ - hashmap = new HashMap(); + Map hashmap = new HashMap(); hashmap.put("txt", s); Bitmap b = BitmapFactory.decodeFile(new File(hatsPath, s + ".png").getAbsolutePath()); b = Bitmap.createBitmap(b, 0,0,b.getWidth()/2, b.getWidth()/2);