From d5a2e55d48bb79f390988589b252ab4a91658e55 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Sat, 10 May 2014 18:24:39 -0300 Subject: [PATCH] Improve handling of focus behaviour on Android. Patch by Alexey Petruchik --- android-project/src/org/libsdl/app/SDLActivity.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index c5714eeea..2b9cf7203 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -190,7 +190,7 @@ public class SDLActivity extends Activity { if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady && SDLActivity.mHasFocus) { SDLActivity.mIsPaused = false; SDLActivity.nativeResume(); - mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); + mSurface.handleResume(); } } @@ -550,6 +550,15 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, mWidth = 1.0f; mHeight = 1.0f; } + + public void handleResume() { + setFocusable(true); + setFocusableInTouchMode(true); + requestFocus(); + setOnKeyListener(this); + setOnTouchListener(this); + enableSensor(Sensor.TYPE_ACCELEROMETER, true); + } public Surface getNativeSurface() { return getHolder().getSurface();