Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render below status bar in portrait orientation on devices with a display cutout #319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions app/src/main/java/app/grapheneos/pdfviewer/ktx/View.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
package app.grapheneos.pdfviewer.ktx

import android.content.res.Configuration
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowInsetsController
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat

private val systemBars = WindowInsetsCompat.Type.statusBars()

fun View.hideSystemUi(window: Window) {
val controller = WindowCompat.getInsetsController(window, this)
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.hide(systemBars)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
controller?.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
if (window.decorView.rootWindowInsets.displayCutout == null) {
controller?.hide(systemBars)
} else if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
controller?.hide(systemBars)
}
} else {
val controller = WindowCompat.getInsetsController(window, this)
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) && (window.decorView.rootWindowInsets.displayCutout == null)) {
controller.hide(systemBars)
} else if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
controller.hide(systemBars)
}
}
}

fun View.showSystemUi(window: Window) {
WindowCompat.getInsetsController(window, this).show(systemBars)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
controller?.show(systemBars)
} else {
val controller = WindowCompat.getInsetsController(window, this)
controller.show(systemBars)
}
}