mirror of
https://github.com/jellyfin/jellyfin-android.git
synced 2026-09-03 05:10:27 +03:00
Rework fullscreen handling
Allow webapp to draw below the navigation bar (including gesture navigation on Android 10+)
This commit is contained in:
@@ -12,6 +12,8 @@ import android.webkit.*
|
||||
import android.widget.FrameLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import okhttp3.OkHttpClient
|
||||
import org.jellyfin.mobile.bridge.Commands.triggerInputManagerAction
|
||||
import org.jellyfin.mobile.bridge.NativeInterface
|
||||
@@ -50,12 +52,19 @@ class WebappActivity : AppCompatActivity(), WebViewController {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_webapp)
|
||||
|
||||
// Bind player service
|
||||
bindService(Intent(this, RemotePlayerService::class.java), serviceConnection, Service.BIND_AUTO_CREATE)
|
||||
|
||||
// Handle window insets
|
||||
setStableLayoutFlags()
|
||||
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v, insets ->
|
||||
v.updatePadding(top = insets.systemWindowInsets.top)
|
||||
insets
|
||||
}
|
||||
|
||||
// Setup WebView
|
||||
setContentView(R.layout.activity_webapp)
|
||||
webView.initialize()
|
||||
|
||||
// Load content
|
||||
|
||||
@@ -66,7 +66,7 @@ class NativeInterface(private val activity: WebappActivity) {
|
||||
fun disableFullscreen(): Boolean {
|
||||
activity.runOnUiThread {
|
||||
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
activity.disableFullscreen()
|
||||
activity.disableFullscreen(true)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -13,27 +13,35 @@ import androidx.annotation.StringRes
|
||||
inline fun <T : View> Activity.lazyView(@IdRes id: Int) =
|
||||
lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(id) }
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
const val STABLE_LAYOUT_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
const val FULLSCREEN_FLAGS = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
|
||||
fun Activity.setStableLayoutFlags() {
|
||||
window.decorView.systemUiVisibility = STABLE_LAYOUT_FLAGS
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun Activity.isFullscreen() = window.decorView.systemUiVisibility.hasFlag(FULLSCREEN_FLAGS)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun Activity.enableFullscreen() {
|
||||
window.apply {
|
||||
decorView.systemUiVisibility = decorView.systemUiVisibility.withFlag(FULLSCREEN_FLAGS)
|
||||
decorView.systemUiVisibility = FULLSCREEN_FLAGS
|
||||
addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun Activity.disableFullscreen() {
|
||||
fun Activity.disableFullscreen(keepStableLayout: Boolean = false) {
|
||||
window.apply {
|
||||
decorView.systemUiVisibility = decorView.systemUiVisibility.withoutFlag(FULLSCREEN_FLAGS)
|
||||
decorView.systemUiVisibility = if (keepStableLayout) STABLE_LAYOUT_FLAGS else 0
|
||||
clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user