Perfume Of Love v2.14.9版本的 MD5 值为:16011aefc5a55805771706ce3b259b4e

以下内容为反编译后的 TJWebViewJSInterface.java 源代码,内容仅作参考


package com.tapjoy;

import android.os.Build;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import com.tapjoy.TJAdUnitConstants;
import com.tapjoy.TapjoyErrorMessage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.json.JSONArray;
import org.json.JSONObject;
public class TJWebViewJSInterface {
    WebView a;
    TJWebViewJSInterfaceListener b;
    private final ConcurrentLinkedQueue<String> c = new ConcurrentLinkedQueue<>();
    private boolean d;

    public TJWebViewJSInterface(WebView webView, TJWebViewJSInterfaceListener tJWebViewJSInterfaceListener) {
        this.a = webView;
        this.b = tJWebViewJSInterfaceListener;
    }

    @JavascriptInterface
    public void dispatchMethod(String str) {
        TapjoyLog.d("TJWebViewJSInterface", "dispatchMethod params: ".concat(String.valueOf(str)));
        try {
            JSONObject jSONObject = new JSONObject(str);
            String string = jSONObject.getJSONObject("data").getString("method");
            TapjoyLog.d("TJWebViewJSInterface", "method: ".concat(String.valueOf(string)));
            TJWebViewJSInterfaceListener tJWebViewJSInterfaceListener = this.b;
            if (tJWebViewJSInterfaceListener == null || this.a == null) {
                return;
            }
            tJWebViewJSInterfaceListener.onDispatchMethod(string, jSONObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void callback(ArrayList<?> arrayList, String str, String str2) {
        try {
            callbackToJavaScript(new JSONArray((Collection) arrayList), str, str2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void callback(Map<?, ?> map, String str, String str2) {
        try {
            JSONArray jSONArray = new JSONArray();
            jSONArray.put(new JSONObject(map));
            callbackToJavaScript(jSONArray, str, str2);
        } catch (Exception e) {
            TapjoyLog.e("TJWebViewJSInterface", "Exception in callback to JS: " + e.toString());
            e.printStackTrace();
        }
    }

    public void callbackToJavaScript(Object obj, String str, String str2) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(TJAdUnitConstants.String.ARGUMENTS, obj);
            if (str != null && str.length() > 0) {
                jSONObject.put("method", str);
            }
            JSONObject jSONObject2 = new JSONObject();
            if (str2 != null && str2.length() > 0) {
                jSONObject2.put(TJAdUnitConstants.String.CALLBACK_ID, str2);
            }
            jSONObject2.put("data", jSONObject);
            String str3 = "javascript:if(window.AndroidWebViewJavascriptBridge) AndroidWebViewJavascriptBridge._handleMessageFromAndroid('" + jSONObject2 + "');";
            if (!this.d) {
                this.c.add(str3);
                return;
            }
            WebView webView = this.a;
            if (webView != null) {
                TapjoyUtil.runOnMainThread(new a(webView, str3));
            } else {
                TapjoyLog.w("TJWebViewJSInterface", "No available webview to execute js");
            }
        } catch (Exception e) {
            TapjoyLog.e("TJWebViewJSInterface", "Exception in callback to JS: " + e.toString());
            e.printStackTrace();
        }
    }

    public void flushMessageQueue() {
        if (this.d) {
            return;
        }
        while (true) {
            String poll = this.c.poll();
            if (poll != null) {
                WebView webView = this.a;
                if (webView != null) {
                    TapjoyUtil.runOnMainThread(new a(webView, poll));
                }
            } else {
                this.d = true;
                return;
            }
        }
    }

    public class a implements Runnable {
        WebView a;
        String b;

        public a(WebView webView, String str) {
            this.a = webView;
            this.b = str;
        }

        @Override
        public final void run() {
            if (this.a != null) {
                if (this.b.startsWith("javascript:") && Build.VERSION.SDK_INT >= 19) {
                    try {
                        String replaceFirst = this.b.replaceFirst("javascript:", "");
                        this.b = replaceFirst;
                        WebView webView = this.a;
                        if (webView == null) {
                            return;
                        }
                        webView.evaluateJavascript(replaceFirst, null);
                        return;
                    } catch (Exception e) {
                        TapjoyErrorMessage.ErrorType errorType = TapjoyErrorMessage.ErrorType.INTERNAL_ERROR;
                        TapjoyLog.e("TJWebViewJSInterface", new TapjoyErrorMessage(errorType, "Exception in evaluateJavascript. Device not supported. " + e.toString()));
                        return;
                    }
                }
                try {
                    this.a.loadUrl(this.b);
                } catch (Exception e2) {
                    TapjoyErrorMessage.ErrorType errorType2 = TapjoyErrorMessage.ErrorType.INTERNAL_ERROR;
                    TapjoyLog.e("TJWebViewJSInterface", new TapjoyErrorMessage(errorType2, "Exception in loadUrl. Device not supported. " + e2.toString()));
                }
            }
        }
    }
}