|
@@ -9,6 +9,7 @@ import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.webkit.GeolocationPermissions;
|
|
|
import android.webkit.ValueCallback;
|
|
|
import android.webkit.WebChromeClient;
|
|
@@ -28,12 +29,14 @@ import com.cooleshow.base.constanst.LoginStatusConstants;
|
|
|
import com.cooleshow.base.event.LoginStatusEvent;
|
|
|
import com.cooleshow.base.ui.fragment.BaseFragment;
|
|
|
import com.cooleshow.base.utils.LOG;
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
import com.cooleshow.base.utils.ToastUtil;
|
|
|
import com.cooleshow.base.utils.helper.LogUploadManager;
|
|
|
import com.cooleshow.base.widgets.HttpsServerCertWebViewClient;
|
|
|
import com.cooleshow.teacher.databinding.FgScHomeWebBinding;
|
|
|
import com.cooleshow.teacher.widgets.LollipopFixedWebView;
|
|
|
import com.cooleshow.teacher.widgets.helper.JsInterfaceUtils;
|
|
|
+import com.cooleshow.teacher.widgets.helper.ScHtmlJsInterfaceUtils;
|
|
|
import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
@@ -45,7 +48,7 @@ import org.json.JSONObject;
|
|
|
/**
|
|
|
* Author by pq, Date on 2024/12/30.
|
|
|
*/
|
|
|
-public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements JsInterfaceUtils.onGetMethodsListener {
|
|
|
+public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements ScHtmlJsInterfaceUtils.OnEventListener {
|
|
|
|
|
|
private WebView webView;
|
|
|
private boolean isNeedRefresh = false;
|
|
@@ -135,8 +138,8 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
|
|
|
webSettings.setTextZoom(100);//设置字体默认的缩放比例,以避免手机系统的字体修改对页面字体及布局造成影响。
|
|
|
webView.setHorizontalScrollBarEnabled(false);
|
|
|
webView.setVerticalScrollBarEnabled(false);
|
|
|
- JsInterfaceUtils jsInterfaceUtils = new JsInterfaceUtils(getActivity());
|
|
|
- jsInterfaceUtils.setOnItemClickListener(this);
|
|
|
+ ScHtmlJsInterfaceUtils jsInterfaceUtils = new ScHtmlJsInterfaceUtils(getActivity());
|
|
|
+ jsInterfaceUtils.setOnEventListener(this);
|
|
|
webView.setWebViewClient(new WebClient());
|
|
|
webView.setWebChromeClient(new MyWebChromeClient());
|
|
|
webView.addJavascriptInterface(jsInterfaceUtils, WebConstants.WEB_JS_INTERFACE);
|
|
@@ -174,7 +177,9 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
|
|
|
}
|
|
|
|
|
|
private void showWebView() {
|
|
|
- mViewBinding.viewParent.setVisibility(View.VISIBLE);
|
|
|
+ if (mViewBinding != null) {
|
|
|
+ mViewBinding.viewParent.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void hideErrorView() {
|
|
@@ -211,7 +216,7 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
|
|
|
}
|
|
|
|
|
|
public void onSendMessage(String message) {
|
|
|
- Log.i("pq", "post message:" + message);
|
|
|
+ LOG.i("pq", "post message:" + message);
|
|
|
webView.evaluateJavascript("postMessage('" + message + "','*')", new ValueCallback<String>() {
|
|
|
@Override
|
|
|
public void onReceiveValue(String s) {
|
|
@@ -332,6 +337,25 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
|
|
|
notifyWebViewOnResume();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onHomeStatisticsHeight(int height) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //为了规避H5页面的错误状态页比如404页面显示在了首页,所以这里在收到相应回调后更高布局样式
|
|
|
+ changeWebViewParentHeight();
|
|
|
+ showWebView();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeWebViewParentHeight() {
|
|
|
+ if (mViewBinding != null) {
|
|
|
+ FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mViewBinding.viewParent.getLayoutParams();
|
|
|
+ layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
+ layoutParams.topMargin =SizeUtils.dp2px(12);
|
|
|
+ mViewBinding.viewParent.setLayoutParams(layoutParams);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private class WebClient extends HttpsServerCertWebViewClient {
|
|
|
//页面开始载入时调用
|
|
|
|
|
@@ -348,7 +372,8 @@ public class ScHtmlFragment extends BaseFragment<FgScHomeWebBinding> implements
|
|
|
super.onPageFinished(view, url);
|
|
|
if (!isLoadError) {
|
|
|
isLoadCompleted = true;
|
|
|
- showWebView();
|
|
|
+ LOG.i("onPageFinished:url" + url);
|
|
|
+// showWebView();
|
|
|
}
|
|
|
}
|
|
|
|