Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Adds Input Focus handling on Android to improve pausing/resuming beha…

  • Loading branch information
gabomdq committed Jul 9, 2013
1 parent 2ecee29 commit 0f1e80e1fac63bfc026793bd4f22efd2322b5a4d
Showing with 14 additions and 2 deletions.
  1. +14 −2 android-project/src/org/libsdl/app/SDLActivity.java
@@ -28,7 +28,7 @@
private static final String TAG = "SDL";

// Keep track of the paused state
public static boolean mIsPaused = false, mIsSurfaceReady = false;
public static boolean mIsPaused = false, mIsSurfaceReady = false, mHasFocus = true;

// Main components
protected static SDLActivity mSingleton;
@@ -94,6 +94,18 @@ protected void onResume() {
SDLActivity.handleResume();
}


@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.v("SDL", "onWindowFocusChanged(): " + hasFocus);

SDLActivity.mHasFocus = hasFocus;
if (hasFocus) {
SDLActivity.handleResume();
}
}

@Override
public void onLowMemory() {
Log.v("SDL", "onLowMemory()");
@@ -139,7 +151,7 @@ public static void handlePause() {
* every time we get one of those events, only if it comes after surfaceDestroyed
*/
public static void handleResume() {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady) {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady && SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);

0 comments on commit 0f1e80e

Please sign in to comment.