Alex Rivera | Logout

Detect Status Bar Visibility / TYPE_SYSTEM_OVERLAY not resizing automatically

Asked 2012-11-29T17:52:28.297
37

I'm using the well known TYPE_SYSTEM_OVERLAY method to create a full screen overlay that's always on top of other views.

On a Moto Atrix2 API15 and for each AVD from API 10 through 17 the overlay view resizes automatically (expands vertically) when the status bar is hidden by another app. The overlay appears to "stay on top" of all other views, as I think it should. When the status bar is in view again, the overlay reduces it's size automatically again (less vertical pixels, basically subtracting the height of the status bar).

This is the desired behavior and am inclined to think this is not the exception or flawed behavior due to it working on many different emulators as well as at least one device manufacturer (motorola), perhaps more, but I don't have access to addtl devices.

The problem: On a Samsung GS2 (API15) & also tested on Kindle Fire (API10?), the overlay does not automatically resize (fill the space where the status bar once was) when the status bar is hidden by another app (status bar behind full screen app). On these devices, after the view is created the first time I don't get any more events from an onSizeChanged override for the view.

Here's the pertinent code:

params = new WindowManager.LayoutParams( 
    1, WindowManager.LayoutParams.MATCH_PARENT, 
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, 
    PixelFormat.TRANSPARENT);
wm.addView(sizeLayout, params);

sizeLayout has the onSizeChanged override.

I've played around with just about every windowmanager layoutparam I can find, including SYSTEM_ALERT, FLAG_LAYOUT_IN_SCREEN, etc. I won't sleep until I can figure this out!

Edit 11/30/12

Edit
Report

1 Answer

3

Hopefully i understand what you are after here but, in my app (TEAM BatteryBar) i had a similar problem. ( no root minimal permissions )

I couldn't detect a full screen on anything below API11 (and intermittent on some (Samsung mostly) devices above API11). So i made a custom listener for it by adding a second layout to the WindowManager with a different layout param then overrode the onLayout to check if the statusBar is still there or not by checking the window size. from there you can do what ever you need to to your main view.

I was going to tidy it up but it worked so i didn't :P code is over a year old and is from when i first started coding for android so yeah. Food for thought tho. hope it helps.

here is the code in a repo at my github with a copy paste straight out of my app on how i am using it. small snippet here

wm.addView(sizeLayout, params);// add your view

// then add the next one
Screendetect mDetector;
mDetector = new Screendetect(this);
mDetector.setOnFullScreenListener(new OnFullScreenListener() {
            @Override
            public void fsChanged(boolean FS_Bool) {
                // TODO rethink this to be better.... bit hacky...
                if (FS_Bool) {
                    Log.d("battbardetect", "Statusbar hidden");
                    FS_vissible(); // do what ever you need to
                } else if (!FS_Bool) {
                    Log.d("battbardetect", "Statusbar Vissible"); 
                    FS_hidden(); // do what ever you need to
                }
            }
        });
wm.addView(mDetector, params);
answered 2013-01-07T09:51:58.310

Your Answer