implement Cocos2dxHelperListener

This commit is contained in:
minggo 2013-09-17 11:44:33 +08:00
parent e0da2578e1
commit 3072144ad5
1 changed files with 52 additions and 13 deletions

View File

@ -27,7 +27,8 @@ import java.io.UnsupportedEncodingException;
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
@ -72,8 +73,8 @@ public class Cocos2dxHelper {
public static void init(final Activity activity) {
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
Cocos2dxHelper.sActivity = activity;
initListener();
try {
// Get the lib_name from AndroidManifest.xml metadata
ActivityInfo ai =
@ -101,6 +102,51 @@ public class Cocos2dxHelper {
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
Cocos2dxBitmap.setContext(activity);
}
public static void initListener() {
Cocos2dxHelper.sCocos2dxHelperListener = new Cocos2dxHelperListener() {
@Override
public void showEditTextDialog(final String title, final String message,
final int inputMode, final int inputFlag, final int returnType, final int maxLength) {
sActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
new Cocos2dxEditBoxDialog(sActivity,
title,
message,
inputMode,
inputFlag,
returnType,
maxLength).show();
}
});
}
@Override
public void showDialog(final String title, final String message) {
sActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
new AlertDialog.Builder(sActivity)
.setTitle(title)
.setMessage(message)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).create().show();
}
});
}
};
}
public static Activity getActivity() {
return sActivity;
@ -241,12 +287,7 @@ public class Cocos2dxHelper {
try {
final byte[] bytesUTF8 = pResult.getBytes("UTF8");
Cocos2dxHelper.sCocos2dxHelperListener.runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8);
}
});
Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8);
} catch (UnsupportedEncodingException pUnsupportedEncodingException) {
/* Nothing. */
}
@ -342,9 +383,7 @@ public class Cocos2dxHelper {
// ===========================================================
public static interface Cocos2dxHelperListener {
public void showDialog(final String pTitle, final String pMessage);
public void showEditTextDialog(final String pTitle, final String pMessage, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength);
public void runOnGLThread(final Runnable pRunnable);
public void showDialog(final String title, final String message);
public void showEditTextDialog(final String title, final String message, final int inputMode, final int inputFlag, final int returnType, final int maxLength);
}
}