Skip to content

Instantly share code, notes, and snippets.

@mreram
Last active February 7, 2023 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mreram/d3b691abf753a8be8612d44d0307a89a to your computer and use it in GitHub Desktop.
Save mreram/d3b691abf753a8be8612d44d0307a89a to your computer and use it in GitHub Desktop.
Fixing full screen issue on webView android - jetpack compose
/**
* created by Mohammad Reza Eram
*/
class VideoPlayerWebChromeClient(private val activity: Activity) : WebChromeClient() {
private var mCustomView: View? = null
private var mCustomViewCallback: CustomViewCallback? = null
@Suppress("MagicNumber")
override fun getDefaultVideoPoster(): Bitmap? {
return try {
if (mCustomView == null) {
null
} else BitmapFactory.decodeResource(activity.applicationContext.resources, 2130837573)
} catch (ignored: Exception) {
null
}
}
override fun onHideCustomView() {
val window = activity.window
(window.decorView as FrameLayout).removeView(mCustomView)
mCustomView = null
mCustomViewCallback?.onCustomViewHidden()
mCustomViewCallback = null
WindowCompat.setDecorFitsSystemWindows(window, true)
WindowInsetsControllerCompat(window, window.decorView).show(WindowInsetsCompat.Type.systemBars())
}
override fun onShowCustomView(paramView: View, paramCustomViewCallback: CustomViewCallback) {
val window = activity.window
if (mCustomView != null) {
onHideCustomView()
return
}
mCustomView = paramView
mCustomViewCallback = paramCustomViewCallback
(window.decorView as FrameLayout).addView(
mCustomView,
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment