Utility functions which are context wide, mostly SD methods right now hedgeroid
authorXeli
Thu, 04 Aug 2011 17:36:13 +0200
branchhedgeroid
changeset 5473 a68f900c4e8c
parent 5471 081bc0170623
child 5475 06a87ff38ffb
Utility functions which are context wide, mostly SD methods right now
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<String> getFilesFromDirWithSuffix(Context c, String dir, String suffix, boolean removeSuffix){
+		String[] files = Utils.getFileNamesFromRelativeDir(c, dir);
+		ArrayList<String> ret = new ArrayList<String>();
+		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