tusharjoshi / jmonkeyengine

Automatically exported from code.google.com/p/jmonkeyengine
0 stars 0 forks source link

Patch for /trunk/engine/src/android/com/jme3/app/AndroidHarness.java #593

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We need controll over the onPause behavior of the AndroidHarness because when a 
transparent activity is displayed infront of the AndroidHarness it should not 
execute its default onPause behavior. Overriding the normal onPause method is 
not allowed by android because for onpause onresume etc the super. version 
always has to be called, but this simple fix allows to prevent pausing the game 
when it is not wanted. so please please just change it like this:

    @Override
    protected void onPause() {
        onPauseCalled();
    }

    protected void onPauseCalled() {
        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;
    }

thanks alot :)

Original issue reported on code.google.com by simon.heinen on 25 Apr 2013 at 12:29

Attachments:

GoogleCodeExporter commented 8 years ago
The app pause/resume code has been moved to the loseFocus/gainFocus public 
methods in AndroidHarness.  If you want to change when the app stops/resumes 
override onPause/onResume and remove the call to loseFocus/gainFocus.  You can 
then call these methods in some other method (like onStop/onStart).

Original comment by iwgeric on 11 May 2013 at 4:13

GoogleCodeExporter commented 8 years ago

Original comment by iwgeric on 11 May 2013 at 4:16