From d300f1c0494fd8898aa60e0a738844e47b98a621 Mon Sep 17 00:00:00 2001 From: youlookwhat <770413277@qq.com> Date: Fri, 24 Sep 2021 22:28:04 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8Dh5=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=A0=E6=95=85=E7=AB=96=E5=B1=8F=E6=88=96=E6=A8=AA=E5=B1=8F?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/jingbin/web/ByWebChromeClient.java | 21 ++++++++++++++++--- .../main/java/me/jingbin/web/ByWebView.java | 17 +++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ByWebView/src/main/java/me/jingbin/web/ByWebChromeClient.java b/ByWebView/src/main/java/me/jingbin/web/ByWebChromeClient.java index 41d0371..a672e3e 100644 --- a/ByWebView/src/main/java/me/jingbin/web/ByWebChromeClient.java +++ b/ByWebView/src/main/java/me/jingbin/web/ByWebChromeClient.java @@ -11,7 +11,6 @@ import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; import android.text.TextUtils; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.webkit.PermissionRequest; @@ -42,6 +41,10 @@ public class ByWebChromeClient extends WebChromeClient { private CustomViewCallback mCustomViewCallback; private ByFullscreenHolder videoFullView; private OnTitleProgressCallback onByWebChromeCallback; + // 修复可能部分h5无故横屏问题 + private boolean isFixScreenLandscape = false; + // 修复可能部分h5无故竖屏问题 + private boolean isFixScreenPortrait = false; ByWebChromeClient(Activity activity, ByWebView byWebView) { mActivityWeakReference = new WeakReference(activity); @@ -52,6 +55,14 @@ void setOnByWebChromeCallback(OnTitleProgressCallback onByWebChromeCallback) { this.onByWebChromeCallback = onByWebChromeCallback; } + public void setFixScreenLandscape(boolean fixScreenLandscape) { + isFixScreenLandscape = fixScreenLandscape; + } + + public void setFixScreenPortrait(boolean fixScreenPortrait) { + isFixScreenPortrait = fixScreenPortrait; + } + /** * 播放网络视频时全屏会被调用的方法 */ @@ -60,7 +71,9 @@ void setOnByWebChromeCallback(OnTitleProgressCallback onByWebChromeCallback) { public void onShowCustomView(View view, CustomViewCallback callback) { Activity mActivity = this.mActivityWeakReference.get(); if (mActivity != null && !mActivity.isFinishing()) { - mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + if (!isFixScreenLandscape) { + mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } mByWebView.getWebView().setVisibility(View.INVISIBLE); // 如果一个视图已经存在,那么立刻终止并新建一个 @@ -93,7 +106,9 @@ public void onHideCustomView() { return; } // 还原到之前的屏幕状态 - mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + if (!isFixScreenPortrait) { + mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } mCustomView.setVisibility(View.GONE); if (videoFullView != null) { diff --git a/ByWebView/src/main/java/me/jingbin/web/ByWebView.java b/ByWebView/src/main/java/me/jingbin/web/ByWebView.java index e1def17..41d3e85 100644 --- a/ByWebView/src/main/java/me/jingbin/web/ByWebView.java +++ b/ByWebView/src/main/java/me/jingbin/web/ByWebView.java @@ -305,6 +305,23 @@ public static Builder with(@NonNull Activity activity) { return new Builder(activity); } + /** + * 修复可能部分h5无故竖屏问题,如果h5里有视频全屏播放请禁用 + */ + public void setFixScreenPortrait(boolean fixScreenPortrait) { + if (mWebChromeClient != null) { + mWebChromeClient.setFixScreenPortrait(fixScreenPortrait); + } + } + + /** + * 修复可能部分h5无故横屏问题,如果h5里有视频全屏播放请禁用 + */ + public void setFixScreenLandscape(boolean fixScreenLandscape) { + if (mWebChromeClient != null) { + mWebChromeClient.setFixScreenLandscape(fixScreenLandscape); + } + } public static class Builder { private Activity mActivity;