-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render below status bar in portrait on devices with a display cutout
- Loading branch information
1 parent
e16f793
commit 49279ea
Showing
1 changed file
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |