This commit is contained in:
18401019693 2023-11-30 14:34:45 +08:00
parent 1f8025599b
commit 33bce43737
3 changed files with 48 additions and 4 deletions

View File

@ -0,0 +1,39 @@
package com.yunbao.common.utils;
import android.app.Activity;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
public class JavascriptInterfacePlayLetUtils {
private Activity mContext;
private WebView mWebView;
private static JavascriptInterfacePlayLetUtils sInstance;
public static JavascriptInterfacePlayLetUtils getInstance() {
synchronized (JavascriptInterfacePlayLetUtils.class) {
sInstance = new JavascriptInterfacePlayLetUtils();
return sInstance;
}
}
public JavascriptInterfacePlayLetUtils setmContext(Activity mContext, WebView mWebView) {
this.mContext = mContext;
this.mWebView = mWebView;
return this;
}
@JavascriptInterface
public void postEvent(String name, String data) {
Log.e("TAG", "postEvent name==" + name);
Log.e("TAG", "postEvent data==" + data);
}
@JavascriptInterface
public void postWeakBalance(String data) {
Log.e("TAG", "postWeakBalance data==" + data);
}
}

View File

@ -8,6 +8,7 @@ import android.app.Activity;
import android.app.Dialog;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
@ -676,4 +677,5 @@ public class JavascriptInterfaceUtils {
}
});
}
}

View File

@ -34,16 +34,17 @@ import com.yunbao.common.HtmlConfig;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.event.JavascriptInterfaceEvent;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.JavascriptInterfacePlayLetUtils;
import com.yunbao.common.utils.JavascriptInterfaceUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.LiveRoomCheckLivePresenter;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.utils.LiveRoomCheckLivePresenter;
import com.yunbao.live.views.LoadingView;
import com.yunbao.main.R;
import com.yunbao.main.activity.MainActivity;
@ -93,7 +94,7 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView = new WebView(mContext);
int aa = BottomBarUtil.getNavigationBarHeightIfRoom(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = DpUtil.dp2px(1);
mWebView.setLayoutParams(params);
mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
@ -114,7 +115,9 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(nowMainActivity, mWebView), "androidObject");
//短剧
mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(nowMainActivity, mWebView), "jsBridge");
mWebView.getSettings().setSupportMultipleWindows(true);
rootView.addView(mWebView);
mWebView.setWebViewClient(new WebViewClient() {