Android, GL, screen size in IMMERSIVE MODE
Asked Answered
A

3

5

I am developing with Nexus 4 KitKat 4.4 and trying to add IMMERSIVE MODE to my game. I need screen height to set glViewport correctly.

Previously I used

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static int getScreenHeight() {
    if (Main.m_activity == null)
        return -1;
    Display display = Main.m_activity.getWindowManager()
            .getDefaultDisplay();
    int height = -1;

    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
        //width = display.getWidth(); // deprecated
        height = display.getHeight(); // deprecated
    }else{
        Point size = new Point();
        display.getSize(size);
        height = size.y;
    }
    return height;

}

It does not return the real height of screen in IMMERSIVE MODE.

So I started to use values from

private static class Renderer implements GLSurfaceView.Renderer {
    public void onSurfaceChanged(GL10 gl, int width, int height) {

and it worked fine when app starts. If I press home button and return to home screen and then back to game onSurfaceChanged get called again but with old wrong values (non-immersive mode screen size, smaller, regular)

IMMERSIVE SCREEN size is 800x1280 REGULAR size is 800x1184

When I get regular size and set it in glViewport then I get black line in top of screen.

PS Also IMMERSIVE MODE is lost when I press volume buttons.

PS2

I have following method impl. It does not help to handle screen/window resize.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
Adequate answered 12/12, 2013 at 21:54 Comment(1)
@payeli, please refrain from needlessly "improving" tags. We already have two tags for kitkat, we did not need a third.Indomitable
A
4

Good article but still not enough. http://developer.android.com/training/system-ui/immersive.html

Right now we get screen size with

public void onSurfaceChanged(GL10 gl, int width, int height) {

and if height decreased then we enable immersive mode again with 1 second delay. This works but hacky and I look for canonical solution myself.

I am afraid it is just buggy in KitKat. I do not any famous title that implemented immersive mode. (except our app of course )))

Aesthetic answered 22/12, 2013 at 22:50 Comment(1)
I do not like such delayed calls in general.Adequate
B
4

Use Display.getRealSize to return the screen bounds without system windows.

Boracic answered 17/12, 2013 at 15:47 Comment(1)
If I do that way then when I press volume button immersive mode is lost. Display.getRealSize will still give give the screen size.Adequate
A
4

Good article but still not enough. http://developer.android.com/training/system-ui/immersive.html

Right now we get screen size with

public void onSurfaceChanged(GL10 gl, int width, int height) {

and if height decreased then we enable immersive mode again with 1 second delay. This works but hacky and I look for canonical solution myself.

I am afraid it is just buggy in KitKat. I do not any famous title that implemented immersive mode. (except our app of course )))

Aesthetic answered 22/12, 2013 at 22:50 Comment(1)
I do not like such delayed calls in general.Adequate
R
4

You can use View.OnSystemUiVisibilityChangeListener to get a callback when immersive mode is disabled/enabled. Using this, you can figure out the actual height of the screen.

Renee answered 29/12, 2013 at 10:14 Comment(1)
Does it work when the user change the device volume with hardware buttons and the dialog appears above the app? In my tests, if the first thing the user does after opening the immersive app is changing the volume with hardware buttons, the app visibility is not changed.Compact

© 2022 - 2024 — McMap. All rights reserved.