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);
}
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);
}
}
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);
}
}
}
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");
}
}
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");
}
}
Aggregations