mirror of https://github.com/axmolengine/axmol.git
ccx : Cocos2dxActivity extends NativeActivity
This commit is contained in:
parent
3af519a61a
commit
d9c3089f35
|
@ -26,15 +26,12 @@ package org.cocos2dx.lib;
|
||||||
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
|
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.NativeActivity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Message;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
|
|
||||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
public class Cocos2dxActivity extends NativeActivity implements Cocos2dxHelperListener {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Constants
|
// Constants
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
@ -45,8 +42,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||||
// Fields
|
// Fields
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
private Cocos2dxGLSurfaceView mGLSurfaceView;
|
|
||||||
private Cocos2dxHandler mHandler;
|
|
||||||
private static Context sContext = null;
|
private static Context sContext = null;
|
||||||
|
|
||||||
public static Context getContext() {
|
public static Context getContext() {
|
||||||
|
@ -61,20 +56,21 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
sContext = this;
|
sContext = this;
|
||||||
this.mHandler = new Cocos2dxHandler(this);
|
|
||||||
|
|
||||||
this.init();
|
|
||||||
|
|
||||||
Cocos2dxHelper.init(this, this);
|
Cocos2dxHelper.init(this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================
|
// @Override
|
||||||
// Getter & Setter
|
// protected void onDestroy() {
|
||||||
// ===========================================================
|
// super.onDestroy();
|
||||||
|
// }
|
||||||
|
|
||||||
// ===========================================================
|
@Override
|
||||||
// Methods for/from SuperClass/Interfaces
|
protected void onPause() {
|
||||||
// ===========================================================
|
super.onPause();
|
||||||
|
|
||||||
|
Cocos2dxHelper.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWindowFocusChanged(final boolean hasWindowFocus) {
|
public void onWindowFocusChanged(final boolean hasWindowFocus) {
|
||||||
|
@ -88,84 +84,41 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
Cocos2dxHelper.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// protected void onStart() {
|
||||||
|
// super.onStart();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// protected void onStop() {
|
||||||
|
// super.onStop();
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showDialog(final String pTitle, final String pMessage) {
|
public void showDialog(final String pTitle, final String pMessage) {
|
||||||
Message msg = new Message();
|
// NYI
|
||||||
msg.what = Cocos2dxHandler.HANDLER_SHOW_DIALOG;
|
|
||||||
msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage);
|
|
||||||
this.mHandler.sendMessage(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showEditTextDialog(final String pTitle, final String pContent, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) {
|
public void showEditTextDialog(final String pTitle,
|
||||||
Message msg = new Message();
|
final String pContent,
|
||||||
msg.what = Cocos2dxHandler.HANDLER_SHOW_EDITBOX_DIALOG;
|
final int pInputMode,
|
||||||
msg.obj = new Cocos2dxHandler.EditBoxMessage(pTitle, pContent, pInputMode, pInputFlag, pReturnType, pMaxLength);
|
final int pInputFlag,
|
||||||
this.mHandler.sendMessage(msg);
|
final int pReturnType,
|
||||||
|
final int pMaxLength) {
|
||||||
|
// NYI
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runOnGLThread(final Runnable pRunnable) {
|
public void runOnGLThread(final Runnable pRunnable) {
|
||||||
this.mGLSurfaceView.queueEvent(pRunnable);
|
// this.mGLSurfaceView.queueEvent(pRunnable);
|
||||||
}
|
}
|
||||||
|
>>>>>>> ccx : Cocos2dxActivity extends NativeActivity
|
||||||
// ===========================================================
|
|
||||||
// Methods
|
|
||||||
// ===========================================================
|
|
||||||
public void init() {
|
|
||||||
|
|
||||||
// FrameLayout
|
|
||||||
ViewGroup.LayoutParams framelayout_params =
|
|
||||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
|
||||||
ViewGroup.LayoutParams.FILL_PARENT);
|
|
||||||
FrameLayout framelayout = new FrameLayout(this);
|
|
||||||
framelayout.setLayoutParams(framelayout_params);
|
|
||||||
|
|
||||||
// Cocos2dxEditText layout
|
|
||||||
ViewGroup.LayoutParams edittext_layout_params =
|
|
||||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
|
|
||||||
edittext.setLayoutParams(edittext_layout_params);
|
|
||||||
|
|
||||||
// ...add to FrameLayout
|
|
||||||
framelayout.addView(edittext);
|
|
||||||
|
|
||||||
// Cocos2dxGLSurfaceView
|
|
||||||
this.mGLSurfaceView = this.onCreateView();
|
|
||||||
|
|
||||||
// ...add to FrameLayout
|
|
||||||
framelayout.addView(this.mGLSurfaceView);
|
|
||||||
|
|
||||||
// Switch to supported OpenGL (ARGB888) mode on emulator
|
|
||||||
if (isAndroidEmulator())
|
|
||||||
this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
|
|
||||||
|
|
||||||
this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
|
||||||
this.mGLSurfaceView.setCocos2dxEditText(edittext);
|
|
||||||
|
|
||||||
// Set framelayout as the content view
|
|
||||||
setContentView(framelayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cocos2dxGLSurfaceView onCreateView() {
|
|
||||||
return new Cocos2dxGLSurfaceView(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static boolean isAndroidEmulator() {
|
|
||||||
String model = Build.MODEL;
|
|
||||||
Log.d(TAG, "model=" + model);
|
|
||||||
String product = Build.PRODUCT;
|
|
||||||
Log.d(TAG, "product=" + product);
|
|
||||||
boolean isEmulator = false;
|
|
||||||
if (product != null) {
|
|
||||||
isEmulator = product.equals("sdk") || product.contains("_sdk") || product.contains("sdk_");
|
|
||||||
}
|
|
||||||
Log.d(TAG, "isEmulator=" + isEmulator);
|
|
||||||
return isEmulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================
|
|
||||||
// Inner and Anonymous Classes
|
|
||||||
// ===========================================================
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue