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

add setImmersiveFullscreen to toggle navbar in android #380

Open
wants to merge 1 commit into
base: master
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
36 changes: 34 additions & 2 deletions app/src/main/java/org/koreader/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import android.view.*
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import org.koreader.launcher.device.Device
import org.koreader.launcher.dialog.LightDialog
import org.koreader.launcher.extensions.*
Expand Down Expand Up @@ -564,7 +566,8 @@ class MainActivity : NativeActivity(), LuaInterface,

override fun isFullscreen(): Boolean {
return if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2 ||
Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
fullscreen
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
isFullscreenDeprecated()
Expand Down Expand Up @@ -681,12 +684,39 @@ class MainActivity : NativeActivity(), LuaInterface,
}
}

fun setFullscreenImmersive(enabled: Boolean) {
val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView) ?: return

val cd = CountDownLatch(1)
runOnUiThread {
try {
if (enabled) {
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
} else {
windowInsetsController.show(WindowInsetsCompat.Type.navigationBars())
}
} catch (e: Exception) {
e.printStackTrace()
}
cd.countDown()
}

try {
cd.await()
fullscreen = enabled
} catch (ex: InterruptedException) {
ex.printStackTrace()
}
}

override fun setFullscreen(enabled: Boolean) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2 ||
Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
fullscreen = enabled
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
setFullscreenDeprecated(enabled)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setFullscreenImmersive(enabled)
}
}

Expand Down Expand Up @@ -811,13 +841,15 @@ class MainActivity : NativeActivity(), LuaInterface,
private fun setFullscreenLayout() {
val decorView = window.decorView
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ->
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT -> {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
setFullscreenImmersive(fullscreen)
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN ->
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_LOW_PROFILE
Expand Down