com.badlogic.gdx.LifecycleListener Java Examples

The following examples show how to use com.badlogic.gdx.LifecycleListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OculusImplementation.java    From gdx-vr with Apache License 2.0 6 votes vote down vote up
public OculusImplementation() {
	VirtualReality.implementation = this;

	VirtualReality.head = new Head();
	VirtualReality.body = new Body();
	VirtualReality.renderer = new VirtualRealityRenderer();

	OvrLibrary.INSTANCE.ovr_Initialize();
	hmd = OvrLibrary.INSTANCE.ovrHmd_CreateDebug(0);
	VirtualReality.headMountedDisplay = new OculusHMD(hmd);

	Gdx.app.addLifecycleListener(new LifecycleListener() {
		@Override
		public void resume() {
		}

		@Override
		public void pause() {
		}

		@Override
		public void dispose() {
			OvrLibrary.INSTANCE.ovr_Shutdown();
		}
	});
}
 
Example #2
Source File: CardboardImplementation.java    From gdx-vr with Apache License 2.0 5 votes vote down vote up
public CardboardImplementation(Activity activity) {
	VirtualReality.implementation = this;

	VirtualReality.head = new Head();
	VirtualReality.body = new Body();
	VirtualReality.renderer = new VirtualRealityRenderer();

	headTracker = new HeadTracker(activity);
	headTracker.startTracking();

	HeadMountedDisplay hmd = new HeadMountedDisplay(activity.getWindowManager().getDefaultDisplay());
	VirtualReality.headMountedDisplay = new CardboardHMD(hmd);

	VirtualReality.distortionRenderer = new CardboardDistortionRenderer(hmd, new DistortionRenderer());

	Gdx.app.addLifecycleListener(new LifecycleListener() {
		@Override
		public void resume() {
		}

		@Override
		public void pause() {
		}

		@Override
		public void dispose() {
			headTracker.stopTracking();
		}
	});
}
 
Example #3
Source File: IOSMini2DxGraphics.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public void resume () {
	if (!appPaused) return;
	appPaused = false;

	Array<LifecycleListener> listeners = app.lifecycleListeners;
	synchronized (listeners) {
		for (LifecycleListener listener : listeners) {
			listener.resume();
		}
	}
	app.listener.resume();
}
 
Example #4
Source File: IOSMini2DxGraphics.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public void pause () {
	if (appPaused) return;
	appPaused = true;

	Array<LifecycleListener> listeners = app.lifecycleListeners;
	synchronized (listeners) {
		for (LifecycleListener listener : listeners) {
			listener.pause();
		}
	}
	app.listener.pause();
}
 
Example #5
Source File: DesktopMini2DxGame.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
private void cleanupWindows() {
	synchronized (lifecycleListeners) {
		for(LifecycleListener lifecycleListener : lifecycleListeners){
			lifecycleListener.pause();
			lifecycleListener.dispose();
		}
	}
	for (Lwjgl3Mini2DxWindow window : windows) {
		window.dispose();
	}
	windows.clear();
}
 
Example #6
Source File: GdxDemoActivity.java    From thunderboard-android with Apache License 2.0 4 votes vote down vote up
private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) {
    if (this.getVersion() < 8) {
        throw new GdxRuntimeException("LibGDX requires Android API Level 8 or later.");
    } else {
        this.setApplicationLogger(new AndroidApplicationLogger());
        this.graphics = new AndroidGraphics(this, config, (ResolutionStrategy) (config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy));
        this.input = AndroidInputFactory.newAndroidInput(this, this, this.graphics.view, config);
        this.audio = new AndroidAudio(this, config);
        this.getFilesDir();
        this.files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
        this.net = new AndroidNet(this);
        this.listener = listener;
        this.handler = new Handler();
        this.useImmersiveMode = config.useImmersiveMode;
        this.hideStatusBar = config.hideStatusBar;
        this.clipboard = new AndroidClipboard(this);
        this.addLifecycleListener(new LifecycleListener() {
            public void resume() {
            }

            public void pause() {
                audio.pause();
            }

            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 {
                this.requestWindowFeature(1);
            } catch (Exception var8) {
                this.log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", var8);
            }

            this.getWindow().setFlags(1024, 1024);
            this.getWindow().clearFlags(2048);
            this.setContentView(this.graphics.getView(), this.createLayoutParams());
        }

        this.createWakeLock(config.useWakelock);
        this.hideStatusBar(this.hideStatusBar);
        this.useImmersiveMode(this.useImmersiveMode);
        if (this.useImmersiveMode && this.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 var7) {
                this.log("AndroidApplication", "Failed to create AndroidVisibilityListener", var7);
            }
        }

    }
}
 
Example #7
Source File: GdxDemoActivity.java    From thunderboard-android with Apache License 2.0 4 votes vote down vote up
public void addLifecycleListener(LifecycleListener listener) {
    synchronized (this.lifecycleListeners) {
        this.lifecycleListeners.add(listener);
    }
}
 
Example #8
Source File: GdxDemoActivity.java    From thunderboard-android with Apache License 2.0 4 votes vote down vote up
public void removeLifecycleListener(LifecycleListener listener) {
    synchronized (this.lifecycleListeners) {
        this.lifecycleListeners.removeValue(listener, true);
    }
}
 
Example #9
Source File: GdxDemoActivity.java    From thunderboard-android with Apache License 2.0 4 votes vote down vote up
public SnapshotArray<LifecycleListener> getLifecycleListeners() {
    return this.lifecycleListeners;
}
 
Example #10
Source File: AndroidLauncher.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate (Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
  config.useAccelerometer        = false;
  config.useGyroscope            = false;
  config.useCompass              = false;
  config.useRotationVectorSensor = false;
  config.maxSimultaneousSounds   = 16;

  FileHandle home = new FileHandle(getContext().getExternalFilesDir(null));
  final Client client = new Client(home, 360);
  initialize(client, config);

  Cvars.Client.Display.StatusBar.addStateListener(new CvarStateAdapter<Boolean>() {
    @Override
    public void onChanged(Cvar<Boolean> cvar, Boolean from, final Boolean to) {
      getHandler().post(new Runnable() {
        @Override
        public void run() {
          if (to.booleanValue()) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
          } else {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          }
        }
      });
    }
  });

  final ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      Rect visibleDisplayFrame = new Rect();
      getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleDisplayFrame);
      int height = /*content.getRootView().getHeight() -*/ Gdx.graphics.getHeight() - visibleDisplayFrame.height();
      client.updateScreenBounds(0, height, 0, 0); // TODO: other params are unused for now
    }
  };
  final View content = getWindow().getDecorView().findViewById(android.R.id.content);
  content.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener);
  Gdx.app.addLifecycleListener(new LifecycleListener() {
    @Override
    public void pause() {}

    @Override
    public void resume() {}

    @Override
    public void dispose() {
      content.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener);
    }
  });
}
 
Example #11
Source File: DesktopMini2DxGame.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
@Override
public void addLifecycleListener(LifecycleListener listener) {
	synchronized (lifecycleListeners) {
		lifecycleListeners.add(listener);
	}
}
 
Example #12
Source File: DesktopMini2DxGame.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
@Override
public void removeLifecycleListener(LifecycleListener listener) {
	synchronized (lifecycleListeners) {
		lifecycleListeners.removeValue(listener, true);
	}
}