西瓜看球 v2.9.13版本的 MD5 值为:755288f3c36852638c41cf20ae0d004e
以下内容为反编译后的 WXDCWeb.java 源代码,内容仅作参考
package io.dcloud.feature.weex.adapter.webview;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.annotation.Component;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.ui.component.WXComponentProp;
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.ui.component.WXWeb;
import com.taobao.weex.ui.view.IWebView;
import com.taobao.weex.utils.WXResourceUtils;
import io.dcloud.common.DHInterface.IApp;
import io.dcloud.common.DHInterface.IWebview;
import io.dcloud.common.adapter.ui.AdaWebview;
import io.dcloud.common.adapter.ui.webview.WebViewFactory;
import io.dcloud.common.adapter.util.PlatformUtil;
import io.dcloud.feature.internal.sdk.SDK;
import io.dcloud.feature.weex.WeexInstanceMgr;
import java.util.HashMap;
import java.util.Map;
import org.cybergarage.soap.SOAP;
@Component(lazyload = false)
public class WXDCWeb extends WXWeb {
IDCWebView mDCWebView;
private JSONObject mWebStyles;
public interface OnDCMessageListener {
void onMessage(Map<String, Object> params, int type);
}
public WXDCWeb(WXSDKInstance instance, WXVContainer parent, boolean isLazy, BasicComponentData basicComponentData) {
super(instance, parent, isLazy, basicComponentData);
}
@Override
protected void createWebView() {
Object newInstance;
String str = null;
try {
Uri parse = Uri.parse(WXSDKManager.getInstance().getSDKInstance(getInstanceId()).getBundleUrl());
String scheme = parse.getScheme();
String authority = parse.getAuthority();
if (!TextUtils.isEmpty(scheme) && !TextUtils.isEmpty(authority)) {
str = scheme + "://" + authority;
}
} catch (Exception unused) {
}
if (WebViewFactory.isIsOtherInitSuccess() && (newInstance = PlatformUtil.newInstance("io.dcloud.feature.x5.DCWXX5WebView", new Class[]{Context.class, String.class, WXDCWeb.class}, new Object[]{getInstance().getUIContext(), str, this})) != null && (newInstance instanceof IWebView)) {
IDCWebView iDCWebView = (IDCWebView) newInstance;
this.mDCWebView = iDCWebView;
this.mWebView = iDCWebView;
}
if (this.mWebView == null) {
DCWXWebView dCWXWebView = new DCWXWebView(getInstance().getUIContext(), str, this);
this.mDCWebView = dCWXWebView;
this.mWebView = dCWXWebView;
}
}
@Override
protected View initComponentHostView(Context context) {
PlatformUtil.invokeMethod(this.mWebView, "setOnDCMessageListener", new Class[]{OnDCMessageListener.class}, new OnDCMessageListener() {
@Override
public void onMessage(Map<String, Object> params, int type) {
WXSDKInstance findWXSDKInstance;
if (type == 1) {
WXDCWeb.this.fireEvent("onPostMessage", params);
} else if (type == 2 && (findWXSDKInstance = WeexInstanceMgr.self().findWXSDKInstance("__uniapp__service")) != null) {
params.put("ref", WXDCWeb.this.getRef());
params.put("id", WXDCWeb.this.getInstance().getInstanceId());
findWXSDKInstance.fireGlobalEventCallback("WebviewPostMessage", params);
}
}
});
this.mWebView.setOnErrorListener(new IWebView.OnErrorListener() {
@Override
public void onError(String type, Object message) {
WXDCWeb.this.fireEvent(type, message);
}
});
this.mWebView.setOnPageListener(new IWebView.OnPageListener() {
@Override
public void onReceivedTitle(String title) {
if (WXDCWeb.this.getEvents().contains(Constants.Event.RECEIVEDTITLE)) {
HashMap hashMap = new HashMap();
hashMap.put("title", title);
HashMap hashMap2 = new HashMap();
hashMap2.put(SOAP.DETAIL, hashMap);
WXDCWeb.this.fireEvent(Constants.Event.RECEIVEDTITLE, (Map<String, Object>) hashMap2);
}
}
@Override
public void onPageStart(String url) {
if (WXDCWeb.this.getEvents().contains(Constants.Event.PAGESTART)) {
HashMap hashMap = new HashMap();
hashMap.put("url", url);
HashMap hashMap2 = new HashMap();
hashMap2.put(SOAP.DETAIL, hashMap);
WXDCWeb.this.fireEvent(Constants.Event.PAGESTART, (Map<String, Object>) hashMap2);
}
}
@Override
public void onPageFinish(String url, boolean canGoBack, boolean canGoForward) {
if (WXDCWeb.this.getEvents().contains(Constants.Event.PAGEFINISH)) {
HashMap hashMap = new HashMap();
hashMap.put("url", url);
hashMap.put("canGoBack", Boolean.valueOf(canGoBack));
hashMap.put("canGoForward", Boolean.valueOf(canGoForward));
HashMap hashMap2 = new HashMap();
hashMap2.put(SOAP.DETAIL, hashMap);
WXDCWeb.this.fireEvent(Constants.Event.PAGEFINISH, (Map<String, Object>) hashMap2);
}
}
});
this.mWebView.setOnMessageListener(new IWebView.OnMessageListener() {
@Override
public void onMessage(Map<String, Object> params) {
HashMap hashMap = new HashMap();
hashMap.put(SOAP.DETAIL, params);
WXDCWeb.this.fireEvent("message", (Map<String, Object>) hashMap);
}
});
View view = this.mWebView.getView();
if (!TextUtils.isEmpty(AdaWebview.sCustomUserAgent)) {
this.mDCWebView.setUserAgent(AdaWebview.sCustomUserAgent, true);
} else {
IWebview findWebview = WeexInstanceMgr.self().findWebview(getInstance());
if (findWebview != null) {
this.mDCWebView.setUserAgent(findWebview.obtainApp().obtainConfigProperty(IApp.ConfigProperty.CONFIG_USER_AGENT), !Boolean.parseBoolean(findWebview.obtainApp().obtainConfigProperty(IApp.ConfigProperty.CONFIG_CONCATENATE)));
}
}
return view;
}
public void fireEvent(String type, Object message) {
if (getEvents().contains("error")) {
HashMap hashMap = new HashMap();
hashMap.put("type", type);
hashMap.put("errorMsg", message);
Map<String, Object> hashMap2 = new HashMap<>();
hashMap2.put(SOAP.DETAIL, hashMap);
fireEvent("error", hashMap2);
}
}
@JSMethod
public void evalJs(String js) {
if (this.mWebView != null) {
if (!js.startsWith("javascript:(function(){")) {
js = "javascript:(function(){" + js + ";})();";
}
this.mWebView.loadUrl(js);
}
}
@JSMethod
public void evalJS(String js) {
evalJs(js);
}
@Override
public void loadUrl(String url) {
if (!TextUtils.isEmpty(url) && url.startsWith("asset:///")) {
url = url.replace("asset:///", SDK.ANDROID_ASSET);
}
super.loadUrl(url);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (this.mWebView != null) {
this.mWebView.onActivityResult(requestCode, resultCode, data);
}
}
@WXComponentProp(name = "webviewStyles")
public void webviewStyles(String styles) {
if (this.mWebStyles == null) {
this.mWebStyles = new JSONObject();
}
JSONObject parseObject = JSON.parseObject(styles);
if (parseObject == null || !parseObject.containsKey("progress")) {
return;
}
Object obj = parseObject.get("progress");
if (obj instanceof Boolean) {
this.mWebStyles.put("isProgress", (Object) Boolean.valueOf(((Boolean) obj).booleanValue()));
} else if (obj instanceof JSONObject) {
JSONObject jSONObject = (JSONObject) obj;
this.mWebStyles.put("isProgress", (Object) true);
if (jSONObject.containsKey("color")) {
this.mWebStyles.put("progressColor", (Object) jSONObject.getString("color"));
}
}
}
public JSONObject getWebStyles() {
if (this.mWebStyles == null) {
JSONObject jSONObject = new JSONObject();
this.mWebStyles = jSONObject;
jSONObject.put("isProgress", (Object) true);
}
return this.mWebStyles;
}
@Override
public void setBackgroundColor(String color) {
super.setBackgroundColor(color);
if (TextUtils.isEmpty(color) || this.mDCWebView == null) {
return;
}
int color2 = WXResourceUtils.getColor(color);
if (this.mDCWebView.getWebView() != null) {
this.mDCWebView.getWebView().setBackgroundColor(color2);
}
}
@Override
public void destroy() {
super.destroy();
this.mDCWebView = null;
}
}