# HG changeset patch # User Xeli # Date 1312472173 -7200 # Node ID a68f900c4e8cfe561a810d9a7935c8e1ecf18edc # Parent 081bc0170623697e4be3b21acd1741af78a446c3 Utility functions which are context wide, mostly SD methods right now diff -r 081bc0170623 -r a68f900c4e8c project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Utils.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Utils.java Thu Aug 04 17:35:42 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Utils.java Thu Aug 04 17:36:13 2011 +0200 @@ -5,6 +5,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import android.content.Context; import android.content.res.TypedArray; @@ -43,7 +44,7 @@ } /** - * Return a File array if all the files from dirName + * Return a File array with all the files from dirName * @param c * @param dirName * @return @@ -57,7 +58,7 @@ } /** - * Checks if this directory has a lua file + * Checks if this directory has a file with suffix suffix * @param f - directory * @return */ @@ -72,6 +73,13 @@ } } + /** + * Gives back all dirs which contain a file with suffix fileSuffix + * @param c + * @param path + * @param fileSuffix + * @return + */ public static String[] getDirsWithFileSuffix(Context c, String path, String fileSuffix){ File[] files = getFilesFromRelativeDir(c,path); String[] validFiles = new String[files.length]; @@ -85,6 +93,26 @@ return ret; } + /** + * Get all files from directory dir which have the given suffix + * @param c + * @param dir + * @param suffix + * @param removeSuffix + * @return + */ + public static ArrayList getFilesFromDirWithSuffix(Context c, String dir, String suffix, boolean removeSuffix){ + String[] files = Utils.getFileNamesFromRelativeDir(c, dir); + ArrayList ret = new ArrayList(); + for(String s : files){ + if(s.endsWith(suffix)){ + if(removeSuffix) ret.add(s.substring(0, s.length()-suffix.length())); + else ret.add(s); + } + } + return ret; + } + /** * Moves resources pointed to by sourceResId (from @res/raw/) to the app's private data directory * @param c