Merge remote branch 'origin/master'

This commit is contained in:
Walzer 2011-04-26 14:51:53 +08:00
commit 6c8efba1e2
7 changed files with 88 additions and 5 deletions

View File

@ -28,6 +28,28 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
setFocusableInTouchMode(true);
setRenderer(mRenderer);
}
public void onPause(){
queueEvent(new Runnable() {
@Override
public void run() {
mRenderer.handleOnPause();
}
});
super.onPause();
}
public void onResume(){
super.onResume();
queueEvent(new Runnable() {
@Override
public void run() {
mRenderer.handleOnResume();
}
});
}
public boolean onTouchEvent(final MotionEvent event) {
// these data are used in ACTION_MOVE and ACTION_CANCEL

View File

@ -64,6 +64,14 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
nativeKeyDown(keyCode);
}
public void handleOnPause(){
nativeOnPause();
}
public void handleOnResume(){
nativeOnResume();
}
public static void setAnimationInterval(double interval){
animationInterval = (long)(interval * NANOSECONDSPERSECOND);
}
@ -72,7 +80,9 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
private static native void nativeTouchesEnd(int id, float x, float y);
private static native void nativeTouchesMove(int[] id, float[] x, float[] y);
private static native void nativeTouchesCancel(int[] id, float[] x, float[] y);
private static native boolean nativeKeyDown(int keyCode);
private static native boolean nativeKeyDown(int keyCode);
private static native void nativeRender();
private static native void nativeInit(int w, int h);
private static native void nativeOnPause();
private static native void nativeOnResume();
}

View File

@ -29,7 +29,8 @@ THE SOFTWARE.
#include "CCTouchDispatcher.h"
#include "CCFileUtils.h"
#include "CCGeometry.h"
#include "platform/android/CCAccelerometer_android.h"
#include "CCAccelerometer.h"
#include "CCApplication.h"
#include <android/log.h>
#if 0
@ -172,6 +173,20 @@ extern "C"
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->getDelegate()->touchesCancelled(&set, NULL);
}
// handle onPause and onResume
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause()
{
CCApplication::sharedApplication().applicationDidEnterBackground();
}
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume()
{
// Shared OpenGL View instance doesn't exist yet when Activity.onResume is first called
if (CCDirector::sharedDirector()->getOpenGLView())
CCApplication::sharedApplication().applicationWillEnterForeground();
}
#define KEYCODE_BACK 0x04
#define KEYCODE_MENU 0x52

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#if CC_ENABLE_PROFILERS
#include <string.h>
#include <string>
#include "CCObject.h"
#include "platform/platform.h"

View File

@ -28,6 +28,28 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
setFocusableInTouchMode(true);
setRenderer(mRenderer);
}
public void onPause(){
queueEvent(new Runnable() {
@Override
public void run() {
mRenderer.handleOnPause();
}
});
super.onPause();
}
public void onResume(){
super.onResume();
queueEvent(new Runnable() {
@Override
public void run() {
mRenderer.handleOnResume();
}
});
}
public boolean onTouchEvent(final MotionEvent event) {
// these data are used in ACTION_MOVE and ACTION_CANCEL

View File

@ -64,6 +64,14 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
nativeKeyDown(keyCode);
}
public void handleOnPause(){
nativeOnPause();
}
public void handleOnResume(){
nativeOnResume();
}
public static void setAnimationInterval(double interval){
animationInterval = (long)(interval * NANOSECONDSPERSECOND);
}
@ -72,7 +80,9 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
private static native void nativeTouchesEnd(int id, float x, float y);
private static native void nativeTouchesMove(int[] id, float[] x, float[] y);
private static native void nativeTouchesCancel(int[] id, float[] x, float[] y);
private static native boolean nativeKeyDown(int keyCode);
private static native boolean nativeKeyDown(int keyCode);
private static native void nativeRender();
private static native void nativeInit(int w, int h);
private static native void nativeOnPause();
private static native void nativeOnResume();
}

View File

@ -30,13 +30,17 @@ public class TestsDemo extends Cocos2dxActivity{
}
@Override
protected void onPause() {
protected void onPause() {
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}
protected void onDestroy()