Wolves Themes v1.0版本的 MD5 值为:cddc92b47f6b7c4a195c9625507eb51c

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


package com.tapjoy;

import android.annotation.TargetApi;
import android.os.AsyncTask;
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 c = new ConcurrentLinkedQueue();
    private boolean d;

    public TJWebViewJSInterface(WebView w, TJWebViewJSInterfaceListener l) {
        this.a = w;
        this.b = l;
    }

    @JavascriptInterface
    public void dispatchMethod(String params) {
        TapjoyLog.d("TJWebViewJSInterface", "dispatchMethod params: " + params);
        try {
            JSONObject jSONObject = new JSONObject(params);
            String string = jSONObject.getJSONObject("data").getString("method");
            TapjoyLog.d("TJWebViewJSInterface", "method: " + string);
            if (this.b != null) {
                this.b.onDispatchMethod(string, jSONObject);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void callback(ArrayList arrayList, String methodName, String callbackID) {
        try {
            callbackToJavaScript(new JSONArray((Collection) arrayList), methodName, callbackID);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

    public void callbackToJavaScript(Object arguments, String methodName, String callbackID) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(TJAdUnitConstants.String.ARGUMENTS, arguments);
            if (methodName != null && methodName.length() > 0) {
                jSONObject.put("method", methodName);
            }
            JSONObject jSONObject2 = new JSONObject();
            if (callbackID != null && callbackID.length() > 0) {
                jSONObject2.put(TJAdUnitConstants.String.CALLBACK_ID, callbackID);
            }
            jSONObject2.put("data", jSONObject);
            String str = "javascript:if(window.AndroidWebViewJavascriptBridge) AndroidWebViewJavascriptBridge._handleMessageFromAndroid('" + jSONObject2 + "');";
            if (!this.d) {
                this.c.add(str);
            } else {
                new a(this.a).execute(str);
            }
        } 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 str = (String) this.c.poll();
            if (str != null) {
                new a(this.a).execute(str);
            } else {
                this.d = true;
                return;
            }
        }
    }

    @TargetApi(19)
    public class a extends AsyncTask {
        WebView a;

        @Override
        protected final Object doInBackground(Object[] objArr) {
            return ((String[]) objArr)[0];
        }

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

        public a(WebView webView) {
            this.a = webView;
        }
    }
}