Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Adds Input Focus handling on Android to improve pausing/resuming beha…
Browse files Browse the repository at this point in the history
  • Loading branch information
gabomdq committed Jul 9, 2013
1 parent 2ecee29 commit 0f1e80e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -28,7 +28,7 @@ public class SDLActivity extends Activity {
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;
Expand Down Expand Up @@ -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()");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0f1e80e

Please sign in to comment.