Android, GL, screen size in IMMERSIVE MODE

3k views Asked by At

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) {
3

There are 3 answers

1
Tema On BEST ANSWER

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 )))

1
jspurlock On

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

1
Kiran Kumar On

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.