Search in sources :

Example 6 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXStreamModule method sendHttp.

/**
   * send HTTP request
   *
   * @param params   {method:POST/GET/PUT/DELETE/HEAD/PATCH,url:http://xxx,header:{key:value},
   *                 body:{key:value}}
   * @param callback formate:handler(err, response)
   */
@Deprecated
@JSMethod(uiThread = false)
public void sendHttp(String params, final String callback) {
    JSONObject paramsObj = JSON.parseObject(params);
    String method = paramsObj.getString("method");
    String url = paramsObj.getString("url");
    JSONObject headers = paramsObj.getJSONObject("header");
    String body = paramsObj.getString("body");
    int timeout = paramsObj.getIntValue("timeout");
    if (method != null)
        method = method.toUpperCase();
    Options.Builder builder = new Options.Builder().setMethod(!"GET".equals(method) && !"POST".equals(method) && !"PUT".equals(method) && !"DELETE".equals(method) && !"HEAD".equals(method) && !"PATCH".equals(method) ? "GET" : method).setUrl(url).setBody(body).setTimeout(timeout);
    extractHeaders(headers, builder);
    sendRequest(builder.createOptions(), new ResponseCallback() {

        @Override
        public void onResponse(WXResponse response, Map<String, String> headers) {
            if (callback != null && mWXSDKInstance != null)
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, (response == null || response.originalData == null) ? "{}" : readAsString(response.originalData, headers != null ? getHeader(headers, "Content-Type") : ""));
        }
    }, null);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WXResponse(com.taobao.weex.common.WXResponse) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 7 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXAnimationModule method transition.

@JSMethod
public void transition(@Nullable String ref, @Nullable String animation, @Nullable String callBack) {
    if (!TextUtils.isEmpty(ref) && !TextUtils.isEmpty(animation)) {
        Message msg = Message.obtain();
        WXDomTask task = new WXDomTask();
        task.instanceId = mWXSDKInstance.getInstanceId();
        task.args = new ArrayList<>();
        task.args.add(ref);
        task.args.add(animation);
        task.args.add(callBack);
        msg.what = WXDomHandler.MsgType.WX_ANIMATION;
        msg.obj = task;
        //Due to animation module rely on the result of the css-layout and the batch mechanism of
        //css-layout, the animation.transition must be delayed the batch time.
        WXSDKManager.getInstance().getWXDomManager().sendMessageDelayed(msg, WXDomHandler.DELAY_TIME);
    }
}
Also used : Message(android.os.Message) WXDomTask(com.taobao.weex.dom.WXDomTask) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 8 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXMetaModule method setViewport.

@JSMethod(uiThread = false)
public void setViewport(String param) {
    if (!TextUtils.isEmpty(param)) {
        try {
            param = URLDecoder.decode(param, "utf-8");
            JSONObject jsObj = JSON.parseObject(param);
            if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) {
                mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext()));
            } else {
                int width = jsObj.getInteger(WIDTH);
                if (width > 0) {
                    mWXSDKInstance.setViewPortWidth(width);
                }
            }
        } catch (Exception e) {
            WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 9 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXModalUIModule method alert.

@JSMethod(uiThread = true)
public void alert(String param, final JSCallback callback) {
    if (mWXSDKInstance.getContext() instanceof Activity) {
        String message = "";
        String okTitle = OK;
        if (!TextUtils.isEmpty(param)) {
            try {
                param = URLDecoder.decode(param, "utf-8");
                JSONObject jsObj = JSON.parseObject(param);
                message = jsObj.getString(MESSAGE);
                okTitle = jsObj.getString(OK_TITLE);
            } catch (Exception e) {
                WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
            }
        }
        if (TextUtils.isEmpty(message)) {
            message = "";
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext());
        builder.setMessage(message);
        final String okTitle_f = TextUtils.isEmpty(okTitle) ? OK : okTitle;
        builder.setPositiveButton(okTitle_f, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callback != null) {
                    callback.invoke(okTitle_f);
                }
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
        tracking(alertDialog);
    } else {
        WXLogUtils.e("[WXModalUIModule] when call alert mWXSDKInstance.getContext() must instanceof Activity");
    }
}
Also used : AlertDialog(android.app.AlertDialog) JSONObject(com.alibaba.fastjson.JSONObject) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 10 with JSMethod

use of com.taobao.weex.annotation.JSMethod in project weex-example by KalicyZhou.

the class WXModalUIModule method confirm.

@JSMethod(uiThread = true)
public void confirm(String param, final JSCallback callback) {
    if (mWXSDKInstance.getContext() instanceof Activity) {
        String message = "";
        String okTitle = OK;
        String cancelTitle = CANCEL;
        if (!TextUtils.isEmpty(param)) {
            try {
                param = URLDecoder.decode(param, "utf-8");
                JSONObject jsObj = JSON.parseObject(param);
                message = jsObj.getString(MESSAGE);
                okTitle = jsObj.getString(OK_TITLE);
                cancelTitle = jsObj.getString(CANCEL_TITLE);
            } catch (Exception e) {
                WXLogUtils.e("[WXModalUIModule] confirm param parse error ", e);
            }
        }
        if (TextUtils.isEmpty(message)) {
            message = "";
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext());
        builder.setMessage(message);
        final String okTitleFinal = TextUtils.isEmpty(okTitle) ? OK : okTitle;
        final String cancelTitleFinal = TextUtils.isEmpty(cancelTitle) ? CANCEL : cancelTitle;
        builder.setPositiveButton(okTitleFinal, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callback != null) {
                    callback.invoke(okTitleFinal);
                }
            }
        });
        builder.setNegativeButton(cancelTitleFinal, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callback != null) {
                    callback.invoke(cancelTitleFinal);
                }
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
        tracking(alertDialog);
    } else {
        WXLogUtils.e("[WXModalUIModule] when call confirm mWXSDKInstance.getContext() must instanceof Activity");
    }
}
Also used : AlertDialog(android.app.AlertDialog) JSONObject(com.alibaba.fastjson.JSONObject) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener) JSMethod(com.taobao.weex.annotation.JSMethod)

Aggregations

JSMethod (com.taobao.weex.annotation.JSMethod)198 WeexEventBean (com.eros.framework.model.WeexEventBean)53 WeexEventBean (com.benmu.framework.model.WeexEventBean)50 JSONObject (com.alibaba.fastjson.JSONObject)32 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)20 Intent (android.content.Intent)19 JSCallback (com.taobao.weex.bridge.JSCallback)12 Activity (android.app.Activity)11 WXEditText (com.taobao.weex.ui.view.WXEditText)8 Map (java.util.Map)8 Uri (android.net.Uri)7 AlertDialog (android.app.AlertDialog)6 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 OnClickListener (android.content.DialogInterface.OnClickListener)6 EditText (android.widget.EditText)6 JSONException (com.alibaba.fastjson.JSONException)6 Invoker (com.taobao.weex.bridge.Invoker)5 MethodInvoker (com.taobao.weex.bridge.MethodInvoker)5