android/testproject/jni/app-android.cpp
changeset 4715 9bb98766eed0
parent 4714 0f05f2f16fad
child 4716 f2c2a33a1a38
     1.1 --- a/android/testproject/jni/app-android.cpp	Tue Jul 27 09:58:17 2010 +0200
     1.2 +++ b/android/testproject/jni/app-android.cpp	Tue Jul 27 10:20:22 2010 +0200
     1.3 @@ -38,22 +38,29 @@
     1.4  extern "C" int SDL_main();
     1.5  extern "C" int Android_OnKeyDown(int keycode);
     1.6  extern "C" int Android_OnKeyUp(int keycode);
     1.7 +extern "C" int SDL_SendQuit();
     1.8 +
     1.9 +//If we're not the active app, don't try to render
    1.10 +bool bRenderingEnabled = false;
    1.11  
    1.12  /*******************************************************************************
    1.13                   Functions called by JNI
    1.14  *******************************************************************************/	
    1.15  
    1.16 -extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv*  env, jobject obj )
    1.17 -{    
    1.18 -	__android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: NativeInit");
    1.19 +extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env, 
    1.20 +                                                                jobject obj ){ 
    1.21 +                                                                   
    1.22 +	__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");
    1.23  
    1.24  	mEnv = env;
    1.25  
    1.26 +	bRenderingEnabled = true;
    1.27 +
    1.28      SDL_main();
    1.29  }
    1.30  
    1.31 -extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
    1.32 -{
    1.33 +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
    1.34 +
    1.35      JNIEnv* env = NULL;
    1.36      jint result = -1;
    1.37  
    1.38 @@ -85,6 +92,7 @@
    1.39      int r = Android_OnKeyDown(keycode);
    1.40      __android_log_print(ANDROID_LOG_INFO, "SDL", 
    1.41                          "SDL: native key down %d, %d\n", keycode, r);
    1.42 +                        
    1.43  }
    1.44  
    1.45  extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv*  env, 
    1.46 @@ -93,13 +101,28 @@
    1.47      int r = Android_OnKeyUp(keycode);
    1.48      __android_log_print(ANDROID_LOG_INFO, "SDL", 
    1.49                          "SDL: native key up %d, %d\n", keycode, r);
    1.50 +                        
    1.51  }
    1.52  
    1.53  extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv*  env, 
    1.54                 jobject obj, jint action, jfloat x, jfloat y, jfloat p){
    1.55 +
    1.56      __android_log_print(ANDROID_LOG_INFO, "SDL", 
    1.57                          "SDL: native touch event %d @ %f/%f, pressure %f\n", 
    1.58                          action, x, y, p);
    1.59 +                        
    1.60 +}
    1.61 +
    1.62 +extern "C" void Java_org_libsdl_android_SDLActivity_nativeQuit( JNIEnv*  env, 
    1.63 +                                                                jobject obj ){    
    1.64 +
    1.65 +    //Stop rendering as we're no longer in the foreground
    1.66 +	bRenderingEnabled = false;
    1.67 +
    1.68 +    //Inject a SDL_QUIT event
    1.69 +    int r = SDL_SendQuit();
    1.70 +
    1.71 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native quit %d", r);        
    1.72  }
    1.73  
    1.74  
    1.75 @@ -110,17 +133,18 @@
    1.76  extern "C" void sdl_create_context(){
    1.77  	__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
    1.78  
    1.79 +	bRenderingEnabled = true;
    1.80 +
    1.81      mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext ); 
    1.82 -    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context() return\n");
    1.83 -
    1.84 -   // exit(1);
    1.85  }
    1.86  
    1.87  extern "C" void sdl_render(){
    1.88  
    1.89 -    //When we get here, we've accumulated a full frame
    1.90 -   //__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_render()");
    1.91 -    
    1.92 +    if(!bRenderingEnabled){
    1.93 +        return;
    1.94 +    }
    1.95 +
    1.96 +    //When we get here, we've accumulated a full frame    
    1.97      mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers ); 
    1.98  }
    1.99