From 0ff86728d8ec0e94ca0647de44121c47c9c5bc0d Mon Sep 17 00:00:00 2001 From: "iwg..om" Date: Sat, 11 May 2013 03:53:09 +0000 Subject: [PATCH] Android: Moved some code from onPause/onResume to loseFocus/gainFocus to address issues/patches 593, 566, 564. Users can now override loseFocus/gainFocus in MainActivity if they do not want to pause/resume the app based on Android's lifecycle methods onPause/onResume. https://code.google.com/p/jmonkeyengine/issues/detail?id=593 https://code.google.com/p/jmonkeyengine/issues/detail?id=564 https://code.google.com/p/jmonkeyengine/issues/detail?id=566 (Yes, there were 3 patch requests for the same thing) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10607 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../android/com/jme3/app/AndroidHarness.java | 109 +++++++++--------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/engine/src/android/com/jme3/app/AndroidHarness.java b/engine/src/android/com/jme3/app/AndroidHarness.java index 0be380190..9102c16b3 100644 --- a/engine/src/android/com/jme3/app/AndroidHarness.java +++ b/engine/src/android/com/jme3/app/AndroidHarness.java @@ -243,67 +243,16 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt protected void onResume() { logger.fine("onResume"); super.onResume(); - if (view != null) { - view.onResume(); - } - if (app != null) { - //resume the audio - AudioRenderer result = app.getAudioRenderer(); - if (result != null) { - if (result instanceof AndroidAudioRenderer) { - AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; - renderer.resumeAll(); - } - } - //resume the sensors (aka joysticks) - if (app.getContext() != null) { - JoyInput joyInput = app.getContext().getJoyInput(); - if (joyInput != null) { - if (joyInput instanceof AndroidSensorJoyInput) { - AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; - androidJoyInput.resumeSensors(); - } - } - } - } - - isGLThreadPaused = false; gainFocus(); } @Override protected void onPause() { + logger.fine("onPause"); loseFocus(); - logger.fine("onPause"); super.onPause(); - if (view != null) { - view.onPause(); - } - - if (app != null) { - //pause the audio - AudioRenderer result = app.getAudioRenderer(); - if (result != null) { - logger.log(Level.FINE, "pause: {0}", result.getClass().getSimpleName()); - if (result instanceof AndroidAudioRenderer) { - AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; - renderer.pauseAll(); - } - } - //pause the sensors (aka joysticks) - if (app.getContext() != null) { - JoyInput joyInput = app.getContext().getJoyInput(); - if (joyInput != null) { - if (joyInput instanceof AndroidSensorJoyInput) { - AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; - androidJoyInput.pauseSensors(); - } - } - } - } - isGLThreadPaused = true; } @Override @@ -524,14 +473,70 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt } public void gainFocus() { + logger.fine("gainFocus"); + if (view != null) { + view.onResume(); + } + + if (app != null) { + //resume the audio + AudioRenderer result = app.getAudioRenderer(); + if (result != null) { + if (result instanceof AndroidAudioRenderer) { + AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; + renderer.resumeAll(); + } + } + //resume the sensors (aka joysticks) + if (app.getContext() != null) { + JoyInput joyInput = app.getContext().getJoyInput(); + if (joyInput != null) { + if (joyInput instanceof AndroidSensorJoyInput) { + AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; + androidJoyInput.resumeSensors(); + } + } + } + } + + isGLThreadPaused = false; + if (app != null) { app.gainFocus(); } } public void loseFocus() { + logger.fine("loseFocus"); if (app != null) { app.loseFocus(); } + + if (view != null) { + view.onPause(); + } + + if (app != null) { + //pause the audio + AudioRenderer result = app.getAudioRenderer(); + if (result != null) { + logger.log(Level.FINE, "pause: {0}", result.getClass().getSimpleName()); + if (result instanceof AndroidAudioRenderer) { + AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; + renderer.pauseAll(); + } + } + //pause the sensors (aka joysticks) + if (app.getContext() != null) { + JoyInput joyInput = app.getContext().getJoyInput(); + if (joyInput != null) { + if (joyInput instanceof AndroidSensorJoyInput) { + AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; + androidJoyInput.pauseSensors(); + } + } + } + } + isGLThreadPaused = true; } }