android / codelab-exoplayer-intro

Media Streaming with ExoPlayer codelab
https://codelabs.developers.google.com/codelabs/exoplayer-intro
Apache License 2.0
221 stars 116 forks source link

hideSystemUI method is deprecated ? #55

Open AgungLaksana opened 4 years ago

AgungLaksana commented 4 years ago

I am trying to follow this step in here https://developer.android.com/codelabs/exoplayer-intro#2

but when I implement hideSystemUi method in Kotlin. then code seems deprecated like this https://i.stack.imgur.com/uqAUP.png

@SuppressLint("InlinedApi")
    private fun hideSystemUi() {
        playerView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE
                or View.SYSTEM_UI_FLAG_FULLSCREEN
                or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
    }

how to solve this ?

wax911 commented 3 years ago

You can add a API version check and if you're using API 30+ try out window insets, refer to this video to learn more about window insets and medium post here

I have to admit, insets still feel like a mess and still have a lot of question regarding how to migrate and replace all the window flags with insets. Personally I'd I've managed to achieve the following use-case by doing the following:


/**
 * Hides both status bar and navigation bar
 */
fun FragmentActivity.hideStatusBarAndNavigationBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        WindowCompat.setDecorFitsSystemWindows(window, true)
        val controller = ViewCompat.getWindowInsetsController(window.decorView)

        // swipe in system bars, this is now sticky immersive
        controller?.systemBarsBehavior =
            WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

        // hide status and navigation bar
        controller?.hide(WindowInsets.Type.systemBars())
    } else {
        // Until I figure out how to hide status bar and nav pre android R using insets
        @Suppress("DEPRECATION")
        window.decorView.systemUiVisibility =
            View.SYSTEM_UI_FLAG_LOW_PROFILE or
            View.SYSTEM_UI_FLAG_FULLSCREEN or
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    }
}

As my comments suggestion the insets work for everything except for hiding status bar in pre-android R so instead since I only use insets if the current version is API 30+

Hope this will also help you! :smile:

Be sure to watch the video for more context :wink: