2023-01-17 02:38:08 +05:30
|
|
|
package com.github.libretube.util
|
|
|
|
|
|
|
|
import android.os.Build
|
|
|
|
import android.view.WindowManager
|
2023-01-21 07:01:28 +05:30
|
|
|
import androidx.core.view.ViewCompat
|
2023-01-17 02:38:08 +05:30
|
|
|
import androidx.core.view.WindowCompat
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
|
import androidx.core.view.WindowInsetsControllerCompat
|
|
|
|
import com.github.libretube.ui.base.BaseActivity
|
|
|
|
|
|
|
|
class WindowHelper(private val activity: BaseActivity) {
|
|
|
|
fun setFullscreen() = activity.apply {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
window.attributes.layoutInDisplayCutoutMode =
|
|
|
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
|
|
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
|
|
|
|
controller.hide(
|
|
|
|
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars()
|
|
|
|
)
|
|
|
|
controller.systemBarsBehavior =
|
|
|
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
|
|
|
}
|
|
|
|
|
|
|
|
window.setFlags(
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun unsetFullscreen() = activity.apply {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
window.attributes.layoutInDisplayCutoutMode =
|
|
|
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, true)
|
|
|
|
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
|
|
|
|
controller.show(
|
|
|
|
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars()
|
|
|
|
)
|
|
|
|
controller.systemBarsBehavior =
|
|
|
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
|
|
|
|
}
|
|
|
|
|
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
|
|
|
|
}
|
2023-01-20 23:19:53 +05:30
|
|
|
|
2023-01-20 23:30:49 +05:30
|
|
|
fun hasCutout(): Boolean {
|
2023-01-21 07:01:28 +05:30
|
|
|
return ViewCompat.getRootWindowInsets(activity.window.decorView)?.displayCutout != null
|
2023-01-20 23:30:49 +05:30
|
|
|
}
|
2023-01-17 02:38:08 +05:30
|
|
|
}
|