Search in sources :

Example 1 with FillResolutionStrategy

use of com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy in project libgdx by libgdx.

the class AndroidLiveWallpaper method initialize.

public void initialize(ApplicationListener listener, AndroidApplicationConfiguration config) {
    if (this.getVersion() < MINIMUM_SDK) {
        throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later.");
    }
    setApplicationLogger(new AndroidApplicationLogger());
    graphics = new AndroidGraphicsLiveWallpaper(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
    // factory in use, but note: AndroidInputFactory causes exceptions when obfuscated: java.lang.RuntimeException: Couldn't
    // construct AndroidInput, this should never happen, proguard deletes constructor used only by reflection
    input = AndroidInputFactory.newAndroidInput(this, this.getService(), graphics.view, config);
    // input = new AndroidInput(this, this.getService(), null, config);
    audio = new AndroidAudio(this.getService(), config);
    // added initialization of android local storage: /data/data/<app package>/files/
    // workaround for Android bug #10515463
    this.getService().getFilesDir();
    files = new AndroidFiles(this.getService().getAssets(), this.getService().getFilesDir().getAbsolutePath());
    net = new AndroidNet(this);
    this.listener = listener;
    clipboard = new AndroidClipboard(this.getService());
    // Unlike activity, fragment and daydream applications there's no need for a specialized audio listener.
    // See description in onPause method.
    Gdx.app = this;
    Gdx.input = input;
    Gdx.audio = audio;
    Gdx.files = files;
    Gdx.graphics = graphics;
    Gdx.net = net;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FillResolutionStrategy(com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy)

Example 2 with FillResolutionStrategy

use of com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy in project libgdx by libgdx.

the class AndroidDaydream method init.

private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) {
    setApplicationLogger(new AndroidApplicationLogger());
    graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
    input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);
    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.clipboard = new AndroidClipboard(this);
    // Add a specialized audio lifecycle listener
    addLifecycleListener(new LifecycleListener() {

        @Override
        public void resume() {
            audio.resume();
        }

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

        @Override
        public void dispose() {
            audio.dispose();
            audio = null;
        }
    });
    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) {
        setFullscreen(true);
        setContentView(graphics.getView(), createLayoutParams());
    }
    createWakeLock(config.useWakelock);
    hideStatusBar(config);
}
Also used : FillResolutionStrategy(com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy) Handler(android.os.Handler) LifecycleListener(com.badlogic.gdx.LifecycleListener)

Example 3 with FillResolutionStrategy

use of com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy in project libgdx by libgdx.

the class AndroidFragmentApplication method initializeForView.

/** This method has to be called in the
	 * {@link Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)} method. It sets up all
	 * the things necessary to get input, render via OpenGL and so on. You can configure other aspects of the application with the
	 * rest of the fields in the {@link AndroidApplicationConfiguration} instance.
	 * <p/>
	 * Note: you have to return the returned view from
	 * {@link Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)}
	 * 
	 * @param listener the {@link ApplicationListener} implementing the program logic
	 * @param config the {@link AndroidApplicationConfiguration}, defining various settings of the application (use accelerometer,
	 *           etc.).
	 * @return the GLSurfaceView of the application */
public View initializeForView(ApplicationListener listener, AndroidApplicationConfiguration config) {
    if (this.getVersion() < MINIMUM_SDK) {
        throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later.");
    }
    setApplicationLogger(new AndroidApplicationLogger());
    graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
    input = AndroidInputFactory.newAndroidInput(this, getActivity(), graphics.view, config);
    audio = new AndroidAudio(getActivity(), config);
    files = new AndroidFiles(getResources().getAssets(), getActivity().getFilesDir().getAbsolutePath());
    net = new AndroidNet(this);
    this.listener = listener;
    this.handler = new Handler();
    this.clipboard = new AndroidClipboard(getActivity());
    // Add a specialized audio lifecycle listener
    addLifecycleListener(new LifecycleListener() {

        @Override
        public void resume() {
            audio.resume();
        }

        @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();
    createWakeLock(config.useWakelock);
    useImmersiveMode(config.useImmersiveMode);
    if (config.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);
        }
    }
    return graphics.getView();
}
Also used : FillResolutionStrategy(com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy) Handler(android.os.Handler) LifecycleListener(com.badlogic.gdx.LifecycleListener) Method(java.lang.reflect.Method) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 4 with FillResolutionStrategy

use of com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy in project libgdx by libgdx.

the class AndroidApplication method init.

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.");
    }
    setApplicationLogger(new AndroidApplicationLogger());
    graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
    input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);
    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;
    this.clipboard = new AndroidClipboard(this);
    // 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());
    }
    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);
        }
    }
}
Also used : FillResolutionStrategy(com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy) Handler(android.os.Handler) LifecycleListener(com.badlogic.gdx.LifecycleListener) Method(java.lang.reflect.Method) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 5 with FillResolutionStrategy

use of com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy 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

FillResolutionStrategy (com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy)5 Handler (android.os.Handler)4 LifecycleListener (com.badlogic.gdx.LifecycleListener)4 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 Method (java.lang.reflect.Method)3 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