13Poker by gametower unlimited gems v0.4版本的 MD5 值为:51324fc0f195c34821074948ab266846

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


package com.millennialmedia.android;

import android.content.ActivityNotFoundException;
import android.net.Uri;
import android.text.TextUtils;
import com.millennialmedia.android.MMSDK;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
class MMCommand implements Runnable {
    private Map<String, String> arguments;
    private String callback;
    private Class cls;
    private Method method;
    private WeakReference<MMWebView> webViewRef;

    public boolean isResizeCommand() {
        if (this.method != null) {
            return "resize".equals(this.method.getName());
        }
        return false;
    }

    public MMCommand(MMWebView webView, String uriString) {
        String[] components;
        this.webViewRef = new WeakReference<>(webView);
        try {
            Uri uri = Uri.parse(uriString);
            String[] components2 = uri.getHost().split("\\.");
            if (components2.length >= 2) {
                String className = components2[components2.length - 2];
                String methodName = components2[components2.length - 1];
                this.arguments = new HashMap();
                String queryString = uriString.substring(uriString.indexOf(63) + 1);
                for (String param : queryString.split("&")) {
                    String[] subComponents = param.split("=");
                    if (subComponents.length >= 2) {
                        this.arguments.put(Uri.decode(subComponents[0]), Uri.decode(subComponents[1]));
                        if (subComponents[0].equalsIgnoreCase("callback")) {
                            this.callback = Uri.decode(subComponents[1]);
                        }
                    }
                }
                this.cls = Class.forName("com.millennialmedia.android.Bridge" + className);
                this.method = this.cls.getMethod(methodName, this.arguments.getClass());
            }
        } catch (Exception e) {
            MMSDK.Log.e("Exception while executing javascript call %s %s", uriString, e.getMessage());
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        MMJSResponse response;
        final MMWebView webViewCallback;
        if (this.cls != null && this.method != null) {
            try {
                MMWebView webView = this.webViewRef.get();
                if (webView != null) {
                    MMJSObject receiver = (MMJSObject) this.cls.newInstance();
                    receiver.setContext(webView.getContext());
                    receiver.setMMWebView(webView);
                    webView.updateArgumentsWithSettings(this.arguments);
                    try {
                        response = (MMJSResponse) this.method.invoke(receiver, this.arguments);
                    } catch (InvocationTargetException ite) {
                        Throwable t = ite.getCause();
                        if (t != null && t.getClass() == ActivityNotFoundException.class) {
                            response = MMJSResponse.responseWithError("Activity not found");
                        } else {
                            response = MMJSResponse.responseWithError();
                        }
                    }
                    if (this.callback != null && this.callback.length() > 0 && (webViewCallback = this.webViewRef.get()) != null) {
                        if (response == null) {
                            response = MMJSResponse.responseWithError(this.method.getName());
                        }
                        if (response.methodName == null) {
                            response.methodName = this.method.getName();
                        }
                        if (response.className == null) {
                            response.className = getBridgeStrippedClassName();
                        }
                        final String call = String.format("javascript:%s(%s);", this.callback, response.toJSONString());
                        MMSDK.Log.v("Executing JS bridge callback: " + call);
                        MMSDK.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (MMCommand.this.method.getName().equals("expandWithProperties")) {
                                    webViewCallback.isExpanding = true;
                                }
                                webViewCallback.loadUrl(call);
                            }
                        });
                    }
                }
            } catch (Exception e) {
                MMSDK.Log.e("Exception while executing javascript call %s %s", this.method.toString(), e.getMessage());
                e.printStackTrace();
            }
        } else if (!TextUtils.isEmpty(this.callback)) {
            MMJSResponse failedResponse = MMJSResponse.responseWithError("No class or method found");
            final String call2 = String.format("javascript:%s(%s);", this.callback, failedResponse.toJSONString());
            MMSDK.Log.v("Executing JS bridge failed callback: " + call2);
            final MMWebView webViewCallback2 = this.webViewRef.get();
            MMSDK.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    webViewCallback2.loadUrl(call2);
                }
            });
        }
    }

    private String getBridgeStrippedClassName() {
        String preStripped = this.cls.getSimpleName();
        return preStripped.replaceFirst("Bridge", "");
    }
}