mirror of https://github.com/axmolengine/axmol.git
implement Cocos2dxHelperListener
This commit is contained in:
parent
e0da2578e1
commit
3072144ad5
|
@ -27,7 +27,8 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
|
@ -72,8 +73,8 @@ public class Cocos2dxHelper {
|
||||||
public static void init(final Activity activity) {
|
public static void init(final Activity activity) {
|
||||||
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||||
|
|
||||||
Cocos2dxHelper.sActivity = activity;
|
initListener();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the lib_name from AndroidManifest.xml metadata
|
// Get the lib_name from AndroidManifest.xml metadata
|
||||||
ActivityInfo ai =
|
ActivityInfo ai =
|
||||||
|
@ -101,6 +102,51 @@ public class Cocos2dxHelper {
|
||||||
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
|
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
|
||||||
Cocos2dxBitmap.setContext(activity);
|
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() {
|
public static Activity getActivity() {
|
||||||
return sActivity;
|
return sActivity;
|
||||||
|
@ -241,12 +287,7 @@ public class Cocos2dxHelper {
|
||||||
try {
|
try {
|
||||||
final byte[] bytesUTF8 = pResult.getBytes("UTF8");
|
final byte[] bytesUTF8 = pResult.getBytes("UTF8");
|
||||||
|
|
||||||
Cocos2dxHelper.sCocos2dxHelperListener.runOnGLThread(new Runnable() {
|
Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (UnsupportedEncodingException pUnsupportedEncodingException) {
|
} catch (UnsupportedEncodingException pUnsupportedEncodingException) {
|
||||||
/* Nothing. */
|
/* Nothing. */
|
||||||
}
|
}
|
||||||
|
@ -342,9 +383,7 @@ public class Cocos2dxHelper {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
public static interface Cocos2dxHelperListener {
|
public static interface Cocos2dxHelperListener {
|
||||||
public void showDialog(final String pTitle, final String pMessage);
|
public void showDialog(final String title, final String message);
|
||||||
public void showEditTextDialog(final String pTitle, final String pMessage, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength);
|
public void showEditTextDialog(final String title, final String message, final int inputMode, final int inputFlag, final int returnType, final int maxLength);
|
||||||
|
|
||||||
public void runOnGLThread(final Runnable pRunnable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue