update
parent
c65a56a37d
commit
6c841a629f
@ -0,0 +1,75 @@
|
||||
package com.rookiedev.hexapod
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowInsetsController
|
||||
|
||||
/**
|
||||
* Behaviors of immersive mode.
|
||||
*/
|
||||
enum class BehaviorOption(
|
||||
val title: String,
|
||||
val value: Int
|
||||
) {
|
||||
// Swipe from the edge to show a hidden bar. Gesture navigation works regardless of visibility
|
||||
// of the navigation bar.
|
||||
Default(
|
||||
"BEHAVIOR_DEFAULT",
|
||||
WindowInsetsController.BEHAVIOR_DEFAULT
|
||||
),
|
||||
// "Sticky immersive mode". Swipe from the edge to temporarily reveal the hidden bar.
|
||||
ShowTransientBarsBySwipe(
|
||||
"BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE",
|
||||
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of system bars to hide or show.
|
||||
*/
|
||||
enum class TypeOption(
|
||||
val title: String,
|
||||
val value: Int
|
||||
) {
|
||||
// Both the status bar and the navigation bar
|
||||
SystemBars(
|
||||
"systemBars()",
|
||||
WindowInsets.Type.systemBars()
|
||||
),
|
||||
// The status bar only.
|
||||
StatusBar(
|
||||
"statusBars()",
|
||||
WindowInsets.Type.statusBars()
|
||||
),
|
||||
// The navigation bar only
|
||||
NavigationBar(
|
||||
"navigationBars()",
|
||||
WindowInsets.Type.navigationBars()
|
||||
)
|
||||
}
|
||||
|
||||
class ControlActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_control)
|
||||
|
||||
controlWindowInsets(true)
|
||||
}
|
||||
|
||||
private fun controlWindowInsets(hide: Boolean) {
|
||||
// WindowInsetsController can hide or show specified system bars.
|
||||
val insetsController = window.decorView.windowInsetsController ?: return
|
||||
// The behavior of the immersive mode.
|
||||
val behavior = BehaviorOption.values()[1].value
|
||||
// The type of system bars to hide or show.
|
||||
val type = TypeOption.values()[0].value
|
||||
insetsController.systemBarsBehavior = behavior
|
||||
if (hide) {
|
||||
insetsController.hide(type)
|
||||
} else {
|
||||
insetsController.show(type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ControlActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue