@@ -38,6 +38,7 @@ import android.content.pm.PackageManager
3838import android.content.res.Configuration
3939import android.content.res.Resources
4040import android.graphics.Color
41+ import android.graphics.Rect
4142import android.hardware.Sensor
4243import android.hardware.SensorManager
4344import android.os.*
@@ -357,16 +358,29 @@ class Godot private constructor(val context: Context) {
357358 if (enabled) {
358359 ViewCompat .setOnApplyWindowInsetsListener(rootView, null )
359360 rootView.setPadding(0 , 0 , 0 , 0 )
361+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .R ) {
362+ window.addFlags(WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS )
363+ window.addFlags(WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION )
364+ }
360365 } else {
361366 if (rootView.rootWindowInsets != null ) {
362- val windowInsets = WindowInsetsCompat .toWindowInsetsCompat(rootView.rootWindowInsets)
363- val insets = windowInsets.getInsets(getInsetType())
364- rootView.setPadding(insets.left, insets.top, insets.right, insets.bottom)
367+ if (! useImmersive.get() || (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R )) {
368+ val windowInsets = WindowInsetsCompat .toWindowInsetsCompat(rootView.rootWindowInsets)
369+ val insets = windowInsets.getInsets(getInsetType())
370+ rootView.setPadding(insets.left, insets.top, insets.right, insets.bottom)
371+ }
365372 }
366373
367374 ViewCompat .setOnApplyWindowInsetsListener(rootView) { v: View , insets: WindowInsetsCompat ->
368- val windowInsets = insets.getInsets(getInsetType())
369- v.setPadding(windowInsets.left, windowInsets.top, windowInsets.right, windowInsets.bottom)
375+ v.post {
376+ if (useImmersive.get() && Build .VERSION .SDK_INT < Build .VERSION_CODES .R ) {
377+ // Fixes issue where padding remained visible in immersive mode on some devices.
378+ v.setPadding(0 , 0 , 0 , 0 )
379+ } else {
380+ val windowInsets = insets.getInsets(getInsetType())
381+ v.setPadding(windowInsets.left, windowInsets.top, windowInsets.right, windowInsets.bottom)
382+ }
383+ }
370384 WindowInsetsCompat .CONSUMED
371385 }
372386 }
@@ -531,12 +545,18 @@ class Godot private constructor(val context: Context) {
531545 startBottom = ViewCompat .getRootWindowInsets(topView)?.getInsets(WindowInsetsCompat .Type .ime())?.bottom ? : 0
532546 }
533547
534- override fun onStart (animation : WindowInsetsAnimationCompat , bounds : WindowInsetsAnimationCompat .BoundsCompat ): WindowInsetsAnimationCompat .BoundsCompat {
548+ override fun onStart (
549+ animation : WindowInsetsAnimationCompat ,
550+ bounds : WindowInsetsAnimationCompat .BoundsCompat
551+ ): WindowInsetsAnimationCompat .BoundsCompat {
535552 endBottom = ViewCompat .getRootWindowInsets(topView)?.getInsets(WindowInsetsCompat .Type .ime())?.bottom ? : 0
536553 return bounds
537554 }
538555
539- override fun onProgress (windowInsets : WindowInsetsCompat , animationsList : List <WindowInsetsAnimationCompat >): WindowInsetsCompat {
556+ override fun onProgress (
557+ windowInsets : WindowInsetsCompat ,
558+ animationsList : List <WindowInsetsAnimationCompat >
559+ ): WindowInsetsCompat {
540560 // Find the IME animation.
541561 var imeAnimation: WindowInsetsAnimationCompat ? = null
542562 for (animation in animationsList) {
@@ -551,12 +571,20 @@ class Godot private constructor(val context: Context) {
551571 val interpolatedFraction = imeAnimation.interpolatedFraction
552572 // Linear interpolation between start and end values.
553573 val keyboardHeight = startBottom * (1.0f - interpolatedFraction) + endBottom * interpolatedFraction
554- GodotLib .setVirtualKeyboardHeight(keyboardHeight.toInt())
574+ val finalHeight = maxOf(keyboardHeight.toInt() - topView.rootView.paddingBottom, 0 )
575+ GodotLib .setVirtualKeyboardHeight(finalHeight)
555576 }
556577 return windowInsets
557578 }
558579
559- override fun onEnd (animation : WindowInsetsAnimationCompat ) {}
580+ override fun onEnd (animation : WindowInsetsAnimationCompat ) {
581+ // Fixes issue on Android 7 and 8 where immersive mode gets auto disabled after the keyboard is hidden.
582+ if (useImmersive.get() && Build .VERSION .SDK_INT < Build .VERSION_CODES .P ) {
583+ runOnHostThread {
584+ enableImmersiveMode(true , true )
585+ }
586+ }
587+ }
560588 })
561589
562590 renderView?.queueOnRenderThread {
0 commit comments