Procházet zdrojové kódy

Fixed dumpDirecories to use dumpPath cache to speed up load time and fixed ok alert and part of ok cancel alert

Tim Newell před 12 roky
rodič
revize
aa0b84cc14

+ 48 - 28
engine/compilers/android/src/com/garagegames/torque2d/FileWalker.java

@@ -19,6 +19,7 @@ public class FileWalker
 	public static Hashtable<String,Vector<String>> files = new Hashtable<String,Vector<String>>();
 	public static Vector<String> dumpPathVec = new Vector<String>();
 	public static Vector<String> dumpDirVec = new Vector<String>();
+	public static Vector<String> dumpDirList = new Vector<String>();
 	
 	public static void InitDirList(Context context, String dir)
 	{
@@ -31,17 +32,15 @@ public class FileWalker
 			if (files.containsKey(dir))
 				files.remove(dir);
 			files.put(dir, new Vector<String>());
-			//Log.i("torque2d", "PARENT DIRECTORY: " + dir);
+			
 			for(String asset: assets) {
 				if (asset.indexOf('.') == -1)
 				{
 					directories.get(dir).add(asset);
-					//Log.i("torque2d", "DIRECTORY ASSET: " + asset);
 				}
 				else
 				{
 					files.get(dir).add(asset);
-					//Log.i("torque2d", "FILE ASSET: " + asset);
 				}
 			}
 		} catch (IOException e) {
@@ -51,7 +50,7 @@ public class FileWalker
 	
 	public static String[] DumpDirectories(Context context, String basePath, String path, boolean depth, boolean noBasePath)
 	{
-
+		double time = System.currentTimeMillis();
 	    dumpPathVec.clear();
 		dumpDirVec.clear();
 		
@@ -75,13 +74,11 @@ public class FileWalker
 		   
 	    }
 	   
-		//Log.i("torque2d", "Dump first dir: " + dirPath);
 		DumpDir2(context, dirPath);
 		
 		while (depth && dumpDirVec.size() > 0)
 		{
 			String newdir = dumpDirVec.remove(0);
-			//Log.i("torque2d", "Dump dir again: " + newdir);
 			DumpDir2(context,newdir);
 		}
 		
@@ -97,43 +94,57 @@ public class FileWalker
 				s = s.replace(basePath + "/", "");
 			retStringArray[cnt] = "/" + s;
 		}
+		Log.i("torque2d", "time in dir java: " + (System.currentTimeMillis() - time) );
+		
 		return retStringArray;
 	}
 	
 	public static void DumpDir2(Context context, String dir)
 	{
-		AssetManager assetMgr = context.getAssets();
-		try {
-			String[] assets = assetMgr.list(dir);
-			for (String asset : assets)
+		for (String d : dumpDirList)
+		{
+			String d2 = d.substring(1);
+			if (d2.equals(dir))
+				continue;
+			
+			if (d2.length() < dir.length())
+				continue;
+			
+			String newdir = "";
+			if (dir.equals(""))
 			{
-				if (asset.equals(".") || asset.equals(".."))
-					continue;
-				
-				if (!asset.contains("."))
+				if (!d2.contains("/"))
 				{
-					if (dir.equals(""))
-						dumpPathVec.add(asset);
-					else
-						dumpPathVec.add(dir + "/" + asset);
-					
-					String newdir = asset;
-					if (!dir.equals(""))
-						newdir = dir + "/" + asset;
-					
-					dumpDirVec.add(newdir);
+					dumpPathVec.add(d2);
+					newdir = d2;
+				}
+			}
+			else
+			{
+				if (d2.startsWith(dir))
+				{
+					String asset = d2.replace(dir, "").substring(1);
+					if (!asset.contains("/"))
+					{
+						dumpPathVec.add(d2);
+						newdir = d2;
+					}
 				}
 			}
-				
-		} catch (IOException e) {
 			
+			
+			if (!newdir.equals("")) {
+				dumpDirVec.add(newdir);
+			}
 		}
 	}
 	
 	public static String[] DumpPath(Context context, String dirPath, boolean depth)
 	{
+		double time = System.currentTimeMillis();
 		dumpPathVec.clear();
 		dumpDirVec.clear();
+		dumpDirList.clear();
 		
 		String dir = dirPath;
 		
@@ -143,13 +154,11 @@ public class FileWalker
 		if (dir.endsWith("/"))
 	    	dir = dir.substring(0,dir.length()-1);
 	   
-		//Log.i("torque2d", "Dump first dir: " + dir);
 		DumpDir(context, dir);
 		
 		while (depth && dumpDirVec.size() > 0)
 		{
 			String newdir = dumpDirVec.remove(0);
-			//Log.i("torque2d", "Dump dir again: " + newdir);
 			DumpDir(context,newdir);
 		}
 		
@@ -163,6 +172,7 @@ public class FileWalker
 			String s = dumpPathVec.remove(0);
 			retStringArray[cnt] = "/" + s;
 		}
+		Log.i("torque2d", "time in java: " + (System.currentTimeMillis() - time) );
 		return retStringArray;
 	}
 	
@@ -191,6 +201,12 @@ public class FileWalker
 				if (asset.equals(".") || asset.equals(".."))
 					continue;
 				
+				if (dir.equals(""))
+				{
+					if (asset.equals("images") || asset.equals("webkit") || asset.equals("sounds") || asset.equals("kioskmode"))
+						continue;
+				}
+				
 				if (asset.contains("."))
 				{
 					if (dir.equals(""))
@@ -205,6 +221,10 @@ public class FileWalker
 						newdir = dir + "/" + asset;
 					
 					dumpDirVec.add(newdir);
+					if (newdir.startsWith("/"))
+						dumpDirList.add(newdir);
+					else
+						dumpDirList.add("/" + newdir);
 						
 				}
 			}

+ 44 - 39
engine/compilers/android/src/com/garagegames/torque2d/T2DUtilities.java

@@ -1,10 +1,12 @@
 package com.garagegames.torque2d;
 
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.net.Uri;
+import android.util.Log;
 
 public class T2DUtilities {
 		
@@ -14,51 +16,54 @@ public class T2DUtilities {
 		context.startActivity(browserIntent);
 	}
 	
-	public static void DisplayAlertOK(Context context, String title, String message)
+	public static void DisplayAlertOK(final Context context, final String title, final String message)
 	{
-		AlertDialog.Builder builder = new AlertDialog.Builder(context);
-		builder.setMessage(message);
-		builder.setTitle(title);
-		builder.setCancelable(false);
-		builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
-		           public void onClick(DialogInterface dialog, int id) {
-		                
-		           }
-		       });
-		AlertDialog alert = builder.create();
-		alert.show();
+		Log.i("torque2d", "DisplayAlertOK");
+		final Activity activity = (Activity)context;
+		activity.runOnUiThread(new Runnable() {			
+			@Override
+				public void run() {
+					AlertDialog.Builder builder = new AlertDialog.Builder(context);
+					builder.setMessage(message);
+					builder.setTitle(title);
+					builder.setCancelable(false);
+					builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
+					           public void onClick(DialogInterface dialog, int id) {
+					                
+					           }
+					       });
+					AlertDialog alert = builder.create();
+					alert.show();
+				}
+		});
 	}
 	
 	private static boolean retValue = false;
 	
-	public static boolean DisplayAlertOKCancel(Context context, String title, String message)
+	public static void DisplayAlertOKCancel(final Context context, final String title, final String message)
 	{
-		AlertDialog.Builder builder = new AlertDialog.Builder(context);
-		builder.setMessage(message);
-		builder.setTitle(title);
-		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
-	           public void onClick(DialogInterface dialog, int id) {
-	                retValue = true;
-	           }
-	       });
-		builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
-	           public void onClick(DialogInterface dialog, int id) {
-	                retValue = false;
-	           }
-	       });
-		AlertDialog alert = builder.create();
-		alert.show();
-		
-		while(alert.isShowing())
-		{
-			try {
-				Thread.sleep(64);
-			} catch (InterruptedException e) {
-			}
-		}
-		
-		return retValue;
-		
+		Log.i("torque2d", "DisplayAlertOKCancel");
+		final Activity activity = (Activity)context;
+		activity.runOnUiThread(new Runnable() {			
+			@Override
+				public void run() {
+					AlertDialog.Builder builder = new AlertDialog.Builder(context);
+					builder.setMessage(message);
+					builder.setTitle(title);
+					builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+				           public void onClick(DialogInterface dialog, int id) {
+				                retValue = true;
+				           }
+				       });
+					builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+				           public void onClick(DialogInterface dialog, int id) {
+				                retValue = false;
+				           }
+				       });
+					AlertDialog alert = builder.create();
+					alert.show();
+				}
+		});
 	}
 	
 	public static boolean DisplayAlertRetry(Context context, String title, String message)

+ 2 - 2
engine/source/platformAndroid/AndroidAlerts.cpp

@@ -32,12 +32,12 @@ extern bool android_AlertYesNo(const char *title, const char *message);
 //-----------------------------------------------------------------------------
 void Platform::AlertOK(const char *windowTitle, const char *message)
 {
-	//android_AlertOK(windowTitle, message);
+	android_AlertOK(windowTitle, message);
 }
 //-----------------------------------------------------------------------------
 bool Platform::AlertOKCancel(const char *windowTitle, const char *message)
 {
-	//return android_AlertOKCancel(windowTitle, message);
+	android_AlertOKCancel(windowTitle, message);
 	return false;
 }
 

+ 8 - 7
engine/source/platformAndroid/T2DActivity.cpp

@@ -1243,6 +1243,8 @@ bool android_DumpDirectoriesExtra(Vector<StringTableEntry> &directoryVector)
 	return ret;
 }
 
+static Vector<Platform::FileInfo> dumpPathBackup;
+
 bool android_DumpDirectories(const char *basePath, const char *path, Vector<StringTableEntry> &directoryVector, S32 depth, bool noBasePath)
 {
 	// Attaches the current thread to the JVM.
@@ -1334,8 +1336,6 @@ bool android_DumpDirectories(const char *basePath, const char *path, Vector<Stri
 	return ret;
 }
 
-static Vector<Platform::FileInfo> dumpPathBackup;
-
 bool android_DumpPathExtra(Vector<Platform::FileInfo>& fileVector)
 {
 	// Attaches the current thread to the JVM.
@@ -1477,7 +1477,7 @@ bool android_DumpPath(const char* dir, Vector<Platform::FileInfo>& fileVector, U
 	if (lResult == JNI_ERR) {
 		return false;
 	}
-
+	double time = timeGetTime();
 	// Retrieves NativeActivity.
 	jobject lNativeActivity = engine.app->activity->clazz;
 	jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
@@ -1555,7 +1555,7 @@ bool android_DumpPath(const char* dir, Vector<Platform::FileInfo>& fileVector, U
 		lJavaVM->DetachCurrentThread();
 		ret = false;
 	}
-
+	adprintf("time to parse paths: %g", timeGetTime() - time);
 	return ret;
 
 }
@@ -1984,14 +1984,15 @@ bool android_AlertOKCancel(const char *title, const char *message)
 	jclass T2DUtilitiesClass = (jclass)lJNIEnv->CallObjectMethod(cls, findClass, strClassName);
 	jstring strTitle = lJNIEnv->NewStringUTF(title);
 	jstring strMessage = lJNIEnv->NewStringUTF(message);
-	jmethodID MethodT2DUtilities = lJNIEnv->GetStaticMethodID(T2DUtilitiesClass, "DisplayAlertOKCancel", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Z");
-	jboolean jret = lJNIEnv->CallStaticBooleanMethod(T2DUtilitiesClass, MethodT2DUtilities, lNativeActivity, strTitle, strMessage);
+	jmethodID MethodT2DUtilities = lJNIEnv->GetStaticMethodID(T2DUtilitiesClass, "DisplayAlertOKCancel", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V");
+	lJNIEnv->CallStaticVoidMethod(T2DUtilitiesClass, MethodT2DUtilities, lNativeActivity, strTitle, strMessage);
 
 	lJNIEnv->DeleteLocalRef(strClassName);
 	lJNIEnv->DeleteLocalRef(strTitle);
 	lJNIEnv->DeleteLocalRef(strMessage);
 
-	bool ret = jret;
+	//TODO: return needs to come from popup
+	bool ret = true;
 
 		// Finished with the JVM.
 	lJavaVM->DetachCurrentThread();