Last active
February 7, 2023 08:42
-
-
Save mreram/d3b691abf753a8be8612d44d0307a89a to your computer and use it in GitHub Desktop.
Fixing full screen issue on webView android - jetpack compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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