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) {
Charles
  • 50,943
  • 13
  • 104
  • 142
Max
  • 6,286
  • 5
  • 44
  • 86
  • @payeli, please refrain from needlessly "improving" tags. We already have *two* tags for kitkat, we did not need a third. – Charles Dec 18 '13 at 07:13

3 Answers3

4

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

jspurlock
  • 1,466
  • 10
  • 7
  • If I do that way then when I press volume button immersive mode is lost. Display.getRealSize will still give give the screen size. – Max Dec 23 '13 at 10:18
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 )))

Tema
  • 1,338
  • 13
  • 27
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.

Kiran Kumar
  • 1,192
  • 8
  • 10
  • 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. – mmathieum Mar 13 '14 at 15:02