use of com.alibaba.fastjson.JSONArray in project weex-example by KalicyZhou.
the class WXBridgeManager method callNative.
/**
* Dispatch the native task to be executed.
*
* @param instanceId {@link WXSDKInstance#mInstanceId}
* @param tasks tasks to be executed
* @param callback next tick id
*/
public int callNative(String instanceId, String tasks, String callback) {
if (TextUtils.isEmpty(tasks)) {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null");
}
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, "[WXBridgeManager] callNative: call Native tasks is null");
return IWXBridge.INSTANCE_RENDERING_ERROR;
}
if (WXEnvironment.isApkDebugable()) {
mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId).append(", tasks:").append(tasks).append(", callback:").append(callback);
WXLogUtils.d(mLodBuilder.substring(0));
mLodBuilder.setLength(0);
}
if (mDestroyedInstanceId != null && mDestroyedInstanceId.contains(instanceId)) {
return IWXBridge.DESTROY_INSTANCE;
}
long start = System.currentTimeMillis();
JSONArray array = JSON.parseArray(tasks);
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start);
}
int size = array.size();
if (size > 0) {
try {
JSONObject task;
for (int i = 0; i < size; ++i) {
task = (JSONObject) array.get(i);
if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
Object target = task.get(MODULE);
if (target != null) {
if (WXDomModule.WXDOM.equals(target)) {
WXDomModule dom = getDomModule(instanceId);
dom.callDomMethod(task);
} else {
WXModuleManager.callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS));
}
} else if (task.get(COMPONENT) != null) {
//call component
WXDomModule dom = getDomModule(instanceId);
dom.invokeMethod((String) task.get(REF), (String) task.get(METHOD), (JSONArray) task.get(ARGS));
} else {
throw new IllegalArgumentException("unknown callNative");
}
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callNative exception: ", e);
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, "[WXBridgeManager] callNative exception " + e.getCause());
}
}
if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) {
return IWXBridge.INSTANCE_RENDERING_ERROR;
}
// get next tick
getNextTick(instanceId, callback);
return IWXBridge.INSTANCE_RENDERING;
}
use of com.alibaba.fastjson.JSONArray in project weex-example by KalicyZhou.
the class WXBridge method callNativeModule.
/**
* Bridge module Js Method
* support Sync or Async through setting Annotation as {@link com.taobao.weex.annotation.JSMethod }
* @param instanceId Instance ID
* @param module the name of module
* @param method the name of method
* @param arguments the arguments of the method
* @param options option arguments for extending
* @return the result
*/
@Override
public Object callNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options) {
JSONArray argArray = JSON.parseArray(new String(arguments));
Object object = WXBridgeManager.getInstance().callNativeModule(instanceId, module, method, argArray, options);
return new WXJSObject(object);
}
use of com.alibaba.fastjson.JSONArray in project weex-example by KalicyZhou.
the class WXDomObject method parse.
/**
* Parse the jsonObject to {@link WXDomObject} recursively
* @param json the original JSONObject
* @return Dom Object corresponding to the JSONObject.
*/
@Nullable
public static WXDomObject parse(JSONObject json, WXSDKInstance wxsdkInstance) {
if (json == null || json.size() <= 0) {
return null;
}
String type = (String) json.get(TYPE);
WXDomObject domObject = WXDomObjectFactory.newInstance(type);
domObject.setViewPortWidth(wxsdkInstance.getViewPortWidth());
if (domObject == null) {
return null;
}
domObject.parseFromJson(json);
domObject.mDomContext = wxsdkInstance;
Object children = json.get(CHILDREN);
if (children != null && children instanceof JSONArray) {
JSONArray childrenArray = (JSONArray) children;
int count = childrenArray.size();
for (int i = 0; i < count; ++i) {
domObject.add(parse(childrenArray.getJSONObject(i), wxsdkInstance), -1);
}
}
return domObject;
}
Aggregations