含羞草 v2.1.6版本的 MD5 值为:6eb49dcd42f2b660ff6f51c70f543d8b
以下内容为反编译后的 BridgeUtil.java 源代码,内容仅作参考
package com.github.lzyzsd.jsbridge;
import android.content.Context;
import android.webkit.WebView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class BridgeUtil {
static final String CALLBACK_ID_FORMAT = "JAVA_CB_%s";
static final String EMPTY_STR = "";
public static final String JAVASCRIPT_STR = "javascript:";
static final String JS_FETCH_QUEUE_FROM_JAVA = "javascript:WebViewJavascriptBridge._fetchQueue();";
static final String JS_HANDLE_MESSAGE_FROM_JAVA = "javascript:WebViewJavascriptBridge._handleMessageFromNative('%s');";
static final String SPLIT_MARK = "/";
static final String UNDERLINE_STR = "_";
static final String YY_FETCH_QUEUE = "yy://return/_fetchQueue/";
static final String YY_OVERRIDE_SCHEMA = "yy://";
static final String YY_RETURN_DATA = "yy://return/";
public static String parseFunctionName(String str) {
return str.replace("javascript:WebViewJavascriptBridge.", "").replaceAll("\\(.*\\);", "");
}
public static String getDataFromReturnUrl(String str) {
if (str.startsWith(YY_FETCH_QUEUE)) {
return str.replace(YY_FETCH_QUEUE, "");
}
String[] split = str.replace(YY_RETURN_DATA, "").split(SPLIT_MARK);
if (split.length < 2) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 1; i < split.length; i++) {
sb.append(split[i]);
}
return sb.toString();
}
public static String getFunctionFromReturnUrl(String str) {
String[] split = str.replace(YY_RETURN_DATA, "").split(SPLIT_MARK);
if (split.length >= 1) {
return split[0];
}
return null;
}
public static void webViewLoadJs(WebView webView, String str) {
webView.loadUrl(JAVASCRIPT_STR + (("var newscript = document.createElement(\"script\");newscript.src=\"" + str + "\";") + "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);"));
}
public static void webViewLoadLocalJs(WebView webView, String str) {
webView.loadUrl(JAVASCRIPT_STR + assetFile2Str(webView.getContext(), str));
}
public static String assetFile2Str(Context context, String str) {
InputStream inputStream;
String readLine;
InputStream inputStream2 = null;
try {
inputStream = context.getAssets().open(str);
try {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
do {
readLine = bufferedReader.readLine();
if (readLine != null && !readLine.matches("^\\s*\\/\\/.*")) {
sb.append(readLine);
}
} while (readLine != null);
bufferedReader.close();
inputStream.close();
String sb2 = sb.toString();
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused) {
}
}
return sb2;
} catch (Exception e) {
e = e;
e.printStackTrace();
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused2) {
}
}
return null;
}
} catch (Throwable th) {
th = th;
inputStream2 = inputStream;
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (IOException unused3) {
}
}
throw th;
}
} catch (Exception e2) {
e = e2;
inputStream = null;
} catch (Throwable th2) {
th = th2;
if (inputStream2 != null) {
}
throw th;
}
}
}