Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Adds Input Focus handling on Android to improve pausing/resuming beha…
- Loading branch information
Showing
with
14 additions
and
2 deletions.
-
+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); |
|
|