Fix Android's SDLActivity for devices that may send more than one surfaceChanged

event in a row (ie, the Kindle Fire)
This commit is contained in:
Gabriel Jacobo 2012-06-24 21:10:17 -03:00
parent a3161ce5ae
commit 7a1361b538

View file

@ -26,6 +26,9 @@ import java.lang.*;
*/ */
public class SDLActivity extends Activity { public class SDLActivity extends Activity {
// Keep track of the paused state
public static boolean mIsPaused;
// Main components // Main components
private static SDLActivity mSingleton; private static SDLActivity mSingleton;
private static SDLSurface mSurface; private static SDLSurface mSurface;
@ -61,6 +64,9 @@ public class SDLActivity extends Activity {
// So we can call stuff from static callbacks // So we can call stuff from static callbacks
mSingleton = this; mSingleton = this;
// Keep track of the paused state
mIsPaused = false;
// Set up the surface // Set up the surface
mSurface = new SDLSurface(getApplication()); mSurface = new SDLSurface(getApplication());
setContentView(mSurface); setContentView(mSurface);
@ -160,7 +166,14 @@ public class SDLActivity extends Activity {
mSDLThread.start(); mSDLThread.start();
} }
else { else {
/*
* Some Android variants may send multiple surfaceChanged events, so we don't need to resume every time
* every time we get one of those events, only if it comes after surfaceDestroyed
*/
if (mIsPaused) {
SDLActivity.nativeResume(); SDLActivity.nativeResume();
SDLActivity.mIsPaused = false;
}
} }
} }
@ -435,7 +448,10 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Called when we lose the surface // Called when we lose the surface
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
Log.v("SDL", "surfaceDestroyed()"); Log.v("SDL", "surfaceDestroyed()");
if (!SDLActivity.mIsPaused) {
SDLActivity.mIsPaused = true;
SDLActivity.nativePause(); SDLActivity.nativePause();
}
enableSensor(Sensor.TYPE_ACCELEROMETER, false); enableSensor(Sensor.TYPE_ACCELEROMETER, false);
} }