com.taobao.weex.common.WXJSBridgeMsgType Java Examples

The following examples show how to use com.taobao.weex.common.WXJSBridgeMsgType. 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: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Callback to Javascript function.
 * @param instanceId Weex Instance Id
 * @param callback  callback referenece handle
 * @param data callback data
 * @param keepAlive if keep callback instance alive for later use
 */
void callbackJavascript(final String instanceId, final String callback,
                        final Object data, boolean keepAlive) {
  if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(callback)
      || mJSHandler == null) {
    return;
  }

  addJSTask(METHOD_CALLBACK, instanceId, callback, data,keepAlive);
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #2
Source File: WXBridgeManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the JavaScript about the event happened on Android
 */
public void fireEvent(final String instanceId, final String ref,
                      final String type, final Map<String, Object> data) {
  if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(ref)
      || TextUtils.isEmpty(type) || mJSHandler == null) {
    return;
  }
  if (!checkMainThread()) {
    throw new WXRuntimeException(
        "fireEvent must be called by main thread");
  }
  addUITask(METHOD_FIRE_EVENT, instanceId, ref, type, data);
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #3
Source File: WXBridgeManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize JavaScript framework
 * @param framework String representation of the framework to be init.
 */
public synchronized void initScriptsFramework(String framework) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = framework;
  msg.what = WXJSBridgeMsgType.INIT_FRAMEWORK;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example #4
Source File: WXBridgeManager.java    From weex with Apache License 2.0 5 votes vote down vote up
void setTimeout(String callbackId, String time) {
  Message message = Message.obtain();
  message.what = WXJSBridgeMsgType.SET_TIMEOUT;
  TimerInfo timerInfo = new TimerInfo();
  timerInfo.callbackId = callbackId;
  timerInfo.time = (long) Float.parseFloat(time);
  message.obj = timerInfo;

  mJSHandler.sendMessageDelayed(message, timerInfo.time);
}
 
Example #5
Source File: WXTimerModuleTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Test
public void testClearInterval() throws Exception {
  module.clearInterval(0);
  Mockito.verify(bridge,never()).removeMessage(anyInt(),anyInt());

  reset(bridge);
  module.clearInterval(1);
  Mockito.verify(bridge,times(1)).removeMessage(eq(WXJSBridgeMsgType.MODULE_INTERVAL),eq(1));
}
 
Example #6
Source File: WXTimerModuleTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Test
public void testClearTimeout() throws Exception {
  module.clearTimeout(0);
  Mockito.verify(bridge,never()).removeMessage(anyInt(),anyInt());

  reset(bridge);
  module.clearTimeout(1);
  Mockito.verify(bridge,times(1)).removeMessage(eq(WXJSBridgeMsgType.MODULE_TIMEOUT),eq(1));
}
 
Example #7
Source File: WXBridgeManagerTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Test
public void testHandleMessage() throws Exception {
  int[] msgs = {
      WXJSBridgeMsgType.INIT_FRAMEWORK,
      WXJSBridgeMsgType.CALL_JS_BATCH,
      WXJSBridgeMsgType.SET_TIMEOUT,
      WXJSBridgeMsgType.MODULE_INTERVAL,
      WXJSBridgeMsgType.MODULE_TIMEOUT
  };
  Message msg = new Message();
  for(int w:msgs) {
    msg.what = w;
    getInstance().handleMessage(msg);
  }
}
 
Example #8
Source File: WXTimerModule.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void setInterval(int funcId, int interval, int instanceId) {
  if(interval<0){
    interval = 0;
  }
  if(funcId <= 0){
    return;
  }
  Message message = Message.obtain();
  message.what = WXJSBridgeMsgType.MODULE_INTERVAL;
  message.arg1 = instanceId;
  message.arg2 = interval;
  message.obj = funcId;
  WXBridgeManager.getInstance().sendMessageDelayed(message, interval);
}
 
Example #9
Source File: WXTimerModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = false)
public void clearInterval(int funcId) {
  if(funcId <= 0){
    return;
  }
  WXBridgeManager.getInstance().removeMessage(WXJSBridgeMsgType.MODULE_INTERVAL, funcId);
}
 
Example #10
Source File: WXTimerModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = false)
public void clearTimeout(int funcId) {
  if(funcId <= 0){
    return;
  }
  WXBridgeManager.getInstance().removeMessage(WXJSBridgeMsgType.MODULE_TIMEOUT, funcId);
}
 
Example #11
Source File: WXTimerModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = false)
public void setTimeout(int funcId, int delay) {
  if(delay<0){
    delay = 0;
  }
  if(funcId <= 0){
    return;
  }
  Message message = Message.obtain();
  message.what = WXJSBridgeMsgType.MODULE_TIMEOUT;
  message.arg1 = Integer.parseInt(mWXSDKInstance.getInstanceId());
  message.obj = funcId;
  WXBridgeManager.getInstance().sendMessageDelayed(message, delay);
}
 
Example #12
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
void setTimeout(String callbackId, String time) {
  Message message = Message.obtain();
  message.what = WXJSBridgeMsgType.SET_TIMEOUT;
  TimerInfo timerInfo = new TimerInfo();
  timerInfo.callbackId = callbackId;
  timerInfo.time = (long) Float.parseFloat(time);
  message.obj = timerInfo;

  mJSHandler.sendMessageDelayed(message, timerInfo.time);
}
 
Example #13
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Notify the JavaScript about the event happened on Android
 */
public void fireEventOnNode(final String instanceId, final String ref,
                      final String type, final Map<String, Object> data,final Map<String, Object> domChanges) {
  if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(ref)
      || TextUtils.isEmpty(type) || mJSHandler == null) {
    return;
  }
  if (!checkMainThread()) {
    throw new WXRuntimeException(
        "fireEvent must be called by main thread");
  }
  addJSTask(METHOD_FIRE_EVENT, instanceId, ref, type, data,domChanges);
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #14
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Initialize JavaScript framework
 * @param framework String representation of the framework to be init.
 */
public synchronized void initScriptsFramework(String framework) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = framework;
  msg.what = WXJSBridgeMsgType.INIT_FRAMEWORK;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example #15
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
void setTimeout(String callbackId, String time) {
  Message message = Message.obtain();
  message.what = WXJSBridgeMsgType.SET_TIMEOUT;
  TimerInfo timerInfo = new TimerInfo();
  timerInfo.callbackId = callbackId;
  timerInfo.time = (long) Float.parseFloat(time);
  message.obj = timerInfo;

  mJSHandler.sendMessageDelayed(message, timerInfo.time);
}
 
Example #16
Source File: WXBridgeManagerTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleMessage() throws Exception {
  int[] msgs = {
      WXJSBridgeMsgType.INIT_FRAMEWORK,
      WXJSBridgeMsgType.CALL_JS_BATCH,
      WXJSBridgeMsgType.SET_TIMEOUT,
      WXJSBridgeMsgType.MODULE_INTERVAL,
      WXJSBridgeMsgType.MODULE_TIMEOUT
  };
  Message msg = new Message();
  for(int w:msgs) {
    msg.what = w;
    getInstance().handleMessage(msg);
  }
}
 
Example #17
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void takeJSHeapSnapshot(String filename) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = filename;
  msg.what = WXJSBridgeMsgType.TAKE_HEAP_SNAPSHOT;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example #18
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Callback to Javascript function.
 * @param instanceId Weex Instance Id
 * @param callback  callback referenece handle
 * @param data callback data
 * @param keepAlive if keep callback instance alive for later use
 */
void callbackJavascript(final String instanceId, final String callback,
                        final Object data, boolean keepAlive) {
  if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(callback)
      || mJSHandler == null) {
    return;
  }

  addJSTask(METHOD_CALLBACK, instanceId, callback, data,keepAlive);
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #19
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the JavaScript about the event happened on Android
 */
public void fireEventOnNode(final String instanceId, final String ref,
                      final String type, final Map<String, Object> data,final Map<String, Object> domChanges) {
  if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(ref)
      || TextUtils.isEmpty(type) || mJSHandler == null) {
    return;
  }
  if (!checkMainThread()) {
    throw new WXRuntimeException(
        "fireEvent must be called by main thread");
  }
  addJSTask(METHOD_FIRE_EVENT, instanceId, ref, type, data,domChanges);
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #20
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize JavaScript framework
 * @param framework String representation of the framework to be init.
 */
public synchronized void initScriptsFramework(String framework) {
  Message msg = mJSHandler.obtainMessage();
  msg.obj = framework;
  msg.what = WXJSBridgeMsgType.INIT_FRAMEWORK;
  msg.setTarget(mJSHandler);
  msg.sendToTarget();
}
 
Example #21
Source File: WXBridgeManager.java    From weex-uikit with MIT License 4 votes vote down vote up
private void getNextTick(final String instanceId, final String callback) {
  addJSTask(METHOD_CALLBACK,instanceId, callback, "{}");
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #22
Source File: WXBridgeManager.java    From weex with Apache License 2.0 4 votes vote down vote up
private void getNextTick(final String instanceId, final String callback) {
  addNextTickTask(instanceId, callback, "{}");
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #23
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
private void getNextTick(final String instanceId, final String callback) {
  addJSTask(METHOD_CALLBACK,instanceId, callback, "{}");
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}