Search in sources :

Example 16 with LifecycleListener

use of com.badlogic.gdx.LifecycleListener in project libgdx by libgdx.

the class LwjglAWTCanvas method stop.

public void stop() {
    if (!running)
        return;
    running = false;
    setGlobals();
    Array<LifecycleListener> listeners = lifecycleListeners;
    // To allow destroying of OpenGL textures during disposal.
    if (canvas.isDisplayable()) {
        makeCurrent();
    } else {
        error(logTag, "OpenGL context destroyed before application listener has had a chance to dispose of textures.");
    }
    synchronized (listeners) {
        for (LifecycleListener listener : listeners) {
            listener.pause();
            listener.dispose();
        }
    }
    listener.pause();
    listener.dispose();
    Gdx.app = null;
    Gdx.graphics = null;
    if (audio != null) {
        audio.dispose();
        Gdx.audio = null;
    }
    if (files != null)
        Gdx.files = null;
    if (net != null)
        Gdx.net = null;
    instanceCount--;
    stopped();
}
Also used : LifecycleListener(com.badlogic.gdx.LifecycleListener)

Example 17 with LifecycleListener

use of com.badlogic.gdx.LifecycleListener in project Catacomb-Snatch by Catacomb-Snatch.

the class AndroidLauncher method initialize.

@Override
public /**
     * {@inheritDoc}
     */
void initialize(ApplicationListener listener, AndroidApplicationConfiguration config) {
    if (this.getVersion() < MINIMUM_SDK) {
        throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later.");
    }
    //Reordered to make using Gdx.app, Gdx.graphics etc possible (due to AndroidBackend.getGdxInput)
    graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
    audio = new AndroidAudio(this, config);
    // workaround for Android bug #10515463
    this.getFilesDir();
    files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
    net = new AndroidNet(this);
    this.listener = listener;
    this.handler = new Handler();
    this.useImmersiveMode = config.useImmersiveMode;
    this.hideStatusBar = config.hideStatusBar;
    // Add a specialized audio lifecycle listener
    addLifecycleListener(new LifecycleListener() {

        @Override
        public void resume() {
        // No need to resume audio here
        }

        @Override
        public void pause() {
        //audio.pause(); //screw it, world shall explode as I can't change it...
        }

        @Override
        public void dispose() {
            audio.dispose();
        }
    });
    Gdx.app = this;
    Gdx.audio = this.getAudio();
    Gdx.files = this.getFiles();
    Gdx.graphics = this.getGraphics();
    Gdx.net = this.getNet();
    input = (Ouya.isRunningOnOuya() ? new OuyaInput(this, this, graphics.getView(), config) : AndroidInputFactory.newAndroidInput(this, this, graphics.getView(), config));
    Gdx.input = this.getInput();
    try {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    } catch (Exception ex) {
        log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", ex);
    }
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    setContentView(graphics.getView(), createLayoutParams());
    createWakeLock(config.useWakelock);
    hideStatusBar(this.hideStatusBar);
    useImmersiveMode(this.useImmersiveMode);
    if (this.useImmersiveMode && getVersion() >= 19) {
        try {
            Class<?> vlistener = Class.forName("com.badlogic.gdx.backends.android.AndroidVisibilityListener");
            Object o = vlistener.newInstance();
            Method method = vlistener.getDeclaredMethod("createListener", AndroidApplicationBase.class);
            method.invoke(o, this);
        } catch (Exception e) {
            log("AndroidApplication", "Failed to create AndroidVisibilityListener", e);
        }
    }
}
Also used : AndroidFiles(com.badlogic.gdx.backends.android.AndroidFiles) FillResolutionStrategy(com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy) AndroidNet(com.badlogic.gdx.backends.android.AndroidNet) Handler(android.os.Handler) LifecycleListener(com.badlogic.gdx.LifecycleListener) Method(java.lang.reflect.Method) AndroidAudio(com.badlogic.gdx.backends.android.AndroidAudio) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) AndroidGraphics(com.badlogic.gdx.backends.android.AndroidGraphics)

Aggregations

LifecycleListener (com.badlogic.gdx.LifecycleListener)17 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)5 Handler (android.os.Handler)4 FillResolutionStrategy (com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy)4 Method (java.lang.reflect.Method)3 Application (com.badlogic.gdx.Application)1 ApplicationType (com.badlogic.gdx.Application.ApplicationType)1 AndroidAudio (com.badlogic.gdx.backends.android.AndroidAudio)1 AndroidFiles (com.badlogic.gdx.backends.android.AndroidFiles)1 AndroidGraphics (com.badlogic.gdx.backends.android.AndroidGraphics)1 AndroidNet (com.badlogic.gdx.backends.android.AndroidNet)1 OpenALAudio (com.badlogic.gdx.backends.lwjgl3.audio.OpenALAudio)1 Array (com.badlogic.gdx.utils.Array)1 LWJGLException (org.lwjgl.LWJGLException)1