List of usage examples for com.badlogic.gdx LifecycleListener LifecycleListener
LifecycleListener
From source file:com.badlogic.gdx.backends.android.CardBoardAndroidApplication.java
License:Apache License
private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) { if (this.getVersion() < MINIMUM_SDK) { throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later."); }//from w ww. j a va 2 s .c o m graphics = new CardBoardGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy); input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config); audio = new AndroidAudio(this, config); this.getFilesDir(); // workaround for Android bug #10515463 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(); } @Override public void dispose() { audio.dispose(); } }); Gdx.app = this; Gdx.input = this.getInput(); Gdx.audio = this.getAudio(); Gdx.files = this.getFiles(); Gdx.graphics = this.getGraphics(); Gdx.net = this.getNet(); if (!isForView) { 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()); setCardboardView((CardboardView) graphics.getView()); } createWakeLock(config.useWakelock); hideStatusBar(this.hideStatusBar); useImmersiveMode(this.useImmersiveMode); if (this.useImmersiveMode && getVersion() >= Build.VERSION_CODES.KITKAT) { 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); } } }
From source file:de.hochschuletrier.gdw.ws1415.game.utils.MyControllers.java
License:Apache License
static private void initialize(boolean update) { if (!update)/*from ww w .j a v a 2 s.c o m*/ if (managers.containsKey(Gdx.app)) return; String className = null; ApplicationType type = Gdx.app.getType(); ControllerManager manager = null; if (type == ApplicationType.Android) { if (Gdx.app.getVersion() >= 12) { className = "com.badlogic.gdx.controllers.android.AndroidControllers"; } else { Gdx.app.log(TAG, "No controller manager is available for Android versions < API level 12"); manager = new ControllerManagerStub(); } } else if (type == ApplicationType.Desktop) { className = "com.badlogic.gdx.controllers.desktop.DesktopControllerManager"; } else if (type == ApplicationType.WebGL) { className = "com.badlogic.gdx.controllers.gwt.GwtControllers"; } else { Gdx.app.log(TAG, "No controller manager is available for: " + Gdx.app.getType()); manager = new ControllerManagerStub(); } if (manager == null) { try { Class controllerManagerClass = ClassReflection.forName(className); manager = (ControllerManager) ClassReflection.newInstance(controllerManagerClass); } catch (Throwable ex) { throw new GdxRuntimeException("Error creating controller manager: " + className, ex); } } managers.put(Gdx.app, manager); final Application app = Gdx.app; Gdx.app.addLifecycleListener(new LifecycleListener() { @Override public void resume() { } @Override public void pause() { } @Override public void dispose() { managers.remove(app); Gdx.app.log(TAG, "removed manager for application, " + managers.size + " managers active"); } }); Gdx.app.log(TAG, "added manager for application, " + managers.size + " managers active"); }
From source file:org.gearvrf.plugins.widget.GVRWidgetPluginActivity.java
License:Apache License
private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView, EGLContext sharedcontext) {//from ww w .j a v a2s. com // if (this.getVersion() < MINIMUM_SDK) { // throw new GdxRuntimeException("LibGDX requires Android API Level " + // MINIMUM_SDK + " or later."); // } mGraphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy, sharedcontext); mInputDispatcher.setInput(AndroidInputFactory.newAndroidInput(this, this, mGraphics.getView(), config)); mAudio = new AndroidAudio(this, config); this.getFilesDir(); // workaround for Android bug #10515463 mFiles = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath()); mNet = new AndroidNet(this); this.mListener = listener; this.mHandler = new Handler(); this.mUseImmersiveMode = config.useImmersiveMode; this.mHideStatusBar = 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() { mAudio.pause(); } @Override public void dispose() { mAudio.dispose(); } }); Gdx.app = this; Gdx.input = this.getInput(); Gdx.audio = this.getAudio(); Gdx.files = this.getFiles(); Gdx.graphics = this.getGraphics(); Gdx.net = this.getNet(); if (!isForView) { 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(mGraphics.getView(), createLayoutParams()); } createWakeLock(config.useWakelock); hideStatusBar(this.mHideStatusBar); useImmersiveMode(this.mUseImmersiveMode); if (this.mUseImmersiveMode && getVersion() >= Build.VERSION_CODES.KITKAT) { 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); } } }
From source file:rx.libgdx.sources.GdxLifecycleEventSource.java
License:Apache License
public static Observable<LifecycleEvent> fromLifecycle() { return create(new Observable.OnSubscribe<LifecycleEvent>() { @Override// w ww . ja v a 2 s . co m public void call(final Subscriber<? super LifecycleEvent> subscriber) { final LifecycleListener listener = new LifecycleListener() { @Override public void pause() { if (!subscriber.isUnsubscribed()) { subscriber.onNext(new PauseEvent()); } } @Override public void resume() { if (!subscriber.isUnsubscribed()) { subscriber.onNext(new ResumeEvent()); } } @Override public void dispose() { if (!subscriber.isUnsubscribed()) { subscriber.onNext(new DisposeEvent()); } } }; subscriber.add(Subscriptions.create(new Action0() { @Override public void call() { Gdx.app.removeLifecycleListener(listener); } })); Gdx.app.addLifecycleListener(listener); } }); }