com.taobao.weex.bridge.WXJSObject Java Examples

The following examples show how to use com.taobao.weex.bridge.WXJSObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WXTimerModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
  boolean ret = false;
  WXJSObject[] args;
  if (msg != null) {
    int what = msg.what;
    WXLogUtils.d(TAG, "Timer Module handleMessage : " + msg.what);
    switch (what) {
      case MODULE_TIMEOUT:
        if (msg.obj == null) {
          break;
        }
        args = createTimerArgs(msg.arg1, (Integer) msg.obj, false);
        WXBridgeManager.getInstance().invokeExecJS(String.valueOf(msg.arg1), null, METHOD_CALL_JS, args, true);
        ret = true;
        break;
      case MODULE_INTERVAL:
        if (msg.obj == null) {
          break;
        }
        postMessage(MODULE_INTERVAL, (Integer) msg.obj, msg.arg2, msg.arg1);
        args = createTimerArgs(msg.arg1, (Integer) msg.obj, true);
        WXBridgeManager.getInstance().invokeExecJS(String.valueOf(msg.arg1), null, METHOD_CALL_JS, args, true);
        ret = true;
        break;
      default:
        break;
    }
  }
  return ret;
}
 
Example #2
Source File: WXTimerModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private WXJSObject[] createTimerArgs(int instanceId, int funcId, boolean keepAlive) {
  ArrayList<Object> argsList = new ArrayList<>();
  argsList.add(funcId);
  argsList.add(new HashMap<>());
  argsList.add(keepAlive);
  WXHashMap<String, Object> task = new WXHashMap<>();
  task.put(KEY_METHOD, METHOD_CALLBACK);
  task.put(KEY_ARGS, argsList);
  Object[] tasks = {task};
  return new WXJSObject[]{
      new WXJSObject(WXJSObject.String, String.valueOf(instanceId)),
      new WXJSObject(WXJSObject.JSON,
                     WXJsonUtils.fromObjectToJSONString(tasks))};
}
 
Example #3
Source File: DebugBridge.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
    public int execJS(String instanceId, String namespace, String function, WXJSObject[] args) {
//        if (!mInit || (TextUtils.isEmpty(instanceId) && !WXBridgeManager.METHOD_REGISTER_MODULES.equals(function))
//                || TextUtils.isEmpty(function)) {
//            return -1;
//        }

        ArrayList<Object> array = new ArrayList<>();
        int argsCount = args == null ? 0 : args.length;
        for (int i = 0; i < argsCount; i++) {
            if (args[i].type != WXJSObject.String) {
                array.add(JSON.parse(args[i].data.toString()));
            } else {
                array.add(args[i].data);
            }
        }

        Map<String, Object> func = new HashMap<>();
        func.put("method", function);
        func.put("args", array);

        Log.v(TAG, "callJS: function is " + function + ", args " + array);
        Map<String, Object> map = new HashMap<>();
        map.put("method", "WxDebug.callJS");
        map.put("params", func);
        if (mSession != null && mSession.isOpen()) {
            mSession.sendText(JSON.toJSONString(map));
        }

        return 0;
    }
 
Example #4
Source File: IWXBridge.java    From ucar-weex-core with Apache License 2.0 2 votes vote down vote up
/**
 * execute javascript function
 */
int execJS(String instanceId, String namespace, String function, WXJSObject[] args);
 
Example #5
Source File: IWXBridge.java    From weex-uikit with MIT License 2 votes vote down vote up
/**
 * execute javascript function
 */
int execJS(String instanceId, String namespace, String function, WXJSObject[] args);
 
Example #6
Source File: IWXBridge.java    From weex with Apache License 2.0 2 votes vote down vote up
/**
 * execute javascript function
 */
int execJS(String instanceId, String namespace, String function, WXJSObject[] args);