eddym
eddym

Reputation: 758

How to check if my application in edge-to-edge mode above api level 30?

I was trying to solve some fullscreen problems past few days, finally I discover: WindowCompat.setDecorFitsSystemWindows(window, false)

so I create an extension function:

fun Activity.fullScreen(isLightStatusBar: Boolean? = null) {

    if (window == null) {
        return
    }

    WindowCompat.setDecorFitsSystemWindows(window, false)

//    // light / dark status bar
//    if (isLightStatusBar != null) {
//        val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
//        windowInsetsController.isAppearanceLightStatusBars = isLightStatusBar
//
//    }
//
//    // status bar color
//    if (Build.VERSION.SDK_INT >= 21) {
//        window.statusBarColor = Color.TRANSPARENT
//    }
}
fun Activity.undoFullScreen(isLightStatusBar: Boolean? = null) {

    if (window == null) {
        return
    }

    WindowCompat.setDecorFitsSystemWindows(window, true)
    // status bar color options etc.
}

which was seems like really promising. But I couldn't find out any way to check through android api if I'm in edge-to-edge AKA fullscreen mode. And now it's just another kind of pain. I have a insetListener like following:

window.decorView.setOnApplyWindowInsetsListener { v, insets ->
    val isFullScreen = hasFlag(window.decorView.systemUiVisibility, View.SYSTEM_UI_FLAG_FULLSCREEN) ||
            hasFlag(window.decorView.systemUiVisibility, View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
    val navigationBarInsetsVisibility = WindowInsetsCompat.toWindowInsetsCompat(insets).isVisible(WindowInsetsCompat.Type.navigationBars())


    Log.d("EDDY", "window.attributes.flags=${window.attributes.flags} - window.decorView.systemUiVisibility=${window.decorView.systemUiVisibility}")

//            if (isFullScreen.not()) {
//                binding.content.dispatchApplyWindowInsets(insets)
//            }

    return@setOnApplyWindowInsetsListener insets
}

I'm changing setDecorFitsSystemWindows value while switching fragments. And according to this listener navigationBarInsetsVisibility is always true, which is make sense but also useless. isFullScreen is always false because there is no flag changes. How I'm supposed to know if my content is under the navbar or not?

The necessity of this information is: just because I want to add bottom padding to my content only if it is in fullscreen mode. But I can't detect it. Only solutin come to mind is setting SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN along the setDecorFitsSystemWindowsmethod but docs saying:

Please note: using the View.setSystemUiVisibility(int) API in your app can conflict with this method. Please discontinue use of View.setSystemUiVisibility(int).

So I'm confused and tired. How can I check if my app is in fullscreen mode?

PS: flags are being set below api 30. So I can check them but not 30 and above.

I tried to log flags but seems like no change. Also check navigation visibility but also doesnt change. And fun fact: navigation visibility showing confusing results on api 29. like, showing visible while in full screen and not visible while not in fullscreen. I was expecting other way around.

UPDATE:
ok I find out that adding setOnApplyWindowInsetsListenerto a windows.decorview is really a bad idea. I'm actually bypass'in all system's calls for "onApplyWindowInsets" But the question still remains, actually it's getting worse in this case:
if I can't get any event on undo-Fullscreen and if there isn't any variable to check for fullscreen mode. How am I supposed to control the custom paddings of my application?

Upvotes: 2

Views: 584

Answers (0)

Related Questions