com.taobao.weex.WXSDKManager Java Examples

The following examples show how to use com.taobao.weex.WXSDKManager. 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: WXDomModule.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Move the DomElement to the specified parent as its given n-th child.
 * @param ref reference of the node to be moved.
 * @param parentRef reference of the parent.
 * @param index the expected index that the dom in its new parent
 */
public void moveElement(String ref, String parentRef, Integer index) {
  if (TextUtils.isEmpty(ref)
      || TextUtils.isEmpty(parentRef)) {
    return;
  }
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(ref);
  task.args.add(parentRef);
  task.args.add(index);
  msg.what = WXDomHandler.MsgType.WX_DOM_MOVE_DOM;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example #2
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Update the {@link WXDomObject#style} according to the given style. Then creating a
 * command object for updating corresponding view and put the command object in the queue.
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param style the new style. This style is only a part of the full style, and will be merged
 *              into {@link WXDomObject#style}
 * @see #updateAttrs(String, JSONObject)
 */
void updateStyle(String ref, JSONObject style) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATESTYLE);
    }
    return;
  }

  domObject.updateStyle(style);
  transformStyle(domObject, false);

  updateStyle(domObject, style);
  mDirty = true;

  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #3
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void commitJSFrameworkAlarmMonitor(final String type, final WXErrorCode errorCode, String errMsg) {
  if (TextUtils.isEmpty(type) || errorCode == null) {
    return;
  }
  if (WXSDKManager.getInstance().getWXStatisticsListener() != null) {
    WXSDKManager.getInstance().getWXStatisticsListener().onException("0",
        errorCode.getErrorCode(),
        TextUtils.isEmpty(errMsg) ? errorCode.getErrorMsg() : errMsg);
  }

  final IWXUserTrackAdapter userTrackAdapter = WXSDKManager.getInstance().getIWXUserTrackAdapter();
  if (userTrackAdapter == null) {
    return;
  }
  WXPerformance performance = new WXPerformance();
  performance.errCode = errorCode.getErrorCode();
  if (errorCode != WXErrorCode.WX_SUCCESS) {
    performance.appendErrMsg(TextUtils.isEmpty(errMsg)?errorCode.getErrorMsg():errMsg);
    WXLogUtils.e("wx_monitor",performance.toString());
  }
  userTrackAdapter.commit(WXEnvironment.getApplication(), null, type, performance, null);
}
 
Example #4
Source File: DefaultLocation.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
@Override
public void watchPosition(final String successCallback, final String errorCallback, final String params) {
  WXLogUtils.d("into--[watchPosition] successCallback:" + successCallback + " errorCallback:" + errorCallback + "\nparams:" + params);
  if (!TextUtils.isEmpty(params)) {
    try {
      org.json.JSONObject jsObj = new org.json.JSONObject(params);
      boolean enableHighAccuracy = jsObj.optBoolean("enableHighAccuracy");
      boolean enableAddress = jsObj.optBoolean("address");

      String id = UUID.randomUUID().toString();
      WXLocationListener listener = findLocation(id, successCallback, errorCallback, enableHighAccuracy, enableAddress);
      if (listener != null) {
        mRegisterSucCallbacks.put(id, listener);
      }
      return;
    } catch (JSONException e) {
      WXLogUtils.e(TAG, e);
    }
  }
  Map<String, Object> options = new HashMap<>();
  options.put(ERROR_CODE, ErrorCode.PARAMS_ERROR);
  options.put(ERROR_MSG, ErrorMsg.PARAMS_ERROR);
  WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(), errorCallback, options);
}
 
Example #5
Source File: WXWebSocketManager.java    From weex with Apache License 2.0 6 votes vote down vote up
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
    throws IOException {
  mWebSocket = webSocket;
  setEnvironment(WXEnvironment.getConfig());
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(WXEnvironment.sApplication, "Has switched to DEBUG mode, you can see the DEBUG information on the browser!", Toast.LENGTH_SHORT).show();
    }
  },0);
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onSuccess(arg2);
  }
  WXLogUtils.e("into--[onOpen]");
}
 
Example #6
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Report JavaScript Exception
 */
public void reportJSException(String instanceId, String function,
                              String exception) {
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.e("reportJSException >>>> instanceId:" + instanceId
                 + ", exception function:" + function + ", exception:"
                 + exception);
  }
  WXSDKInstance instance;
  if (instanceId != null && (instance = WXSDKManager.getInstance().getSDKInstance(instanceId)) != null) {
    instance.onJSException(WXErrorCode.WX_ERR_JS_EXECUTE.getErrorCode(), function, exception);

    String err = "function:" + function + "#exception:" + exception;
    commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_JS_EXECUTE, err);

    IWXJSExceptionAdapter adapter = WXSDKManager.getInstance().getIWXJSExceptionAdapter();
    if (adapter != null) {
      WXJSExceptionInfo jsException = new WXJSExceptionInfo(instanceId, instance.getBundleUrl(), WXErrorCode.WX_ERR_JS_EXECUTE.getErrorCode(), function, exception, null);
      adapter.onJSException(jsException);
      if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d(jsException.toString());
      }
    }
  }
}
 
Example #7
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Trigger a updateStyle invoke to relayout current page
 */
public void notifyNativeSizeChanged(int w, int h) {
  if (!mNeedLayoutOnAnimation) {
    return;
  }

  Message message = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = getInstanceId();
  if (task.args == null) {
    task.args = new ArrayList<>();
  }

  JSONObject style = new JSONObject(2);
  float webW = WXViewUtils.getWebPxByWidth(w);
  float webH = WXViewUtils.getWebPxByWidth(h);

  style.put("width", webW);
  style.put("height", webH);

  task.args.add(getRef());
  task.args.add(style);
  message.obj = task;
  message.what = WXDomHandler.MsgType.WX_DOM_UPDATE_STYLE;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(message);
}
 
Example #8
Source File: DOMActionContextImpl.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private WXAnimationBean createAnimationBean(String ref,Map<String, Object> style){
  if (style != null) {
    try {
      Object transform = style.get(WXDomObject.TRANSFORM);
      if (transform instanceof String && !TextUtils.isEmpty((String) transform)) {
        String transformOrigin = (String) style.get(WXDomObject.TRANSFORM_ORIGIN);
        WXAnimationBean animationBean = new WXAnimationBean();
        WXDomObject domObject = mRegistry.get(ref);
        int width = (int) domObject.getLayoutWidth();
        int height = (int) domObject.getLayoutHeight();
        animationBean.styles = new WXAnimationBean.Style();
        animationBean.styles.init(transformOrigin, (String) transform, width, height,WXSDKManager.getInstanceViewPortWidth(mInstanceId));
        return animationBean;
      }
    }catch (RuntimeException e){
      WXLogUtils.e("", e);
      return null;
    }
  }
  return null;
}
 
Example #9
Source File: WXBridge.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * JavaScript uses this methods to call Android code
 *
 * @param instanceId
 * @param tasks
 * @param callback
 */

public int callUpdateStyle(String instanceId, String ref, byte [] tasks, String callback) {
  long start = System.currentTimeMillis();
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if(instance != null) {
    instance.firstScreenCreateInstanceTime(start);
  }
  int errorCode = IWXBridge.INSTANCE_RENDERING;
  try {
    errorCode = WXBridgeManager.getInstance().callUpdateStyle(instanceId, ref, new String(tasks), callback);
  } catch (Throwable e) {
    //catch everything during call native.
    if(WXEnvironment.isApkDebugable()){
      WXLogUtils.e(TAG,"callUpdateStyle throw exception:" + e.getMessage());
    }
  }
  if(instance != null) {
    instance.callNativeTime(System.currentTimeMillis() - start);
  }
  return errorCode;
}
 
Example #10
Source File: WXBridge.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * JavaScript uses this methods to call Android code
 *
 * @param instanceId
 * @param tasks
 * @param callback
 */

public int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String callback) {
  long start = System.currentTimeMillis();
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if(instance != null) {
    instance.firstScreenCreateInstanceTime(start);
  }
  int errorCode = IWXBridge.INSTANCE_RENDERING;
  try {
    errorCode = WXBridgeManager.getInstance().callUpdateAttrs(instanceId, ref, new String(tasks), callback);
  } catch (Throwable e) {
    //catch everything during call native.
    if(WXEnvironment.isApkDebugable()){
      WXLogUtils.e(TAG,"callUpdateAttrs throw exception:" + e.getMessage());
    }
  }
  if(instance != null) {
    instance.callNativeTime(System.currentTimeMillis() - start);
  }
  return errorCode;
}
 
Example #11
Source File: WXBridge.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * JavaScript uses this methods to call Android code
 *
 * @param instanceId
 * @param tasks
 * @param callback
 */

public int callCreateFinish(String instanceId, byte [] tasks, String callback) {
  long start = System.currentTimeMillis();
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if(instance != null) {
    instance.firstScreenCreateInstanceTime(start);
  }
  int errorCode = IWXBridge.INSTANCE_RENDERING;
  try {
    errorCode = WXBridgeManager.getInstance().callCreateFinish(instanceId, callback);
  } catch (Throwable e) {
    //catch everything during call native.
    if(WXEnvironment.isApkDebugable()){
      WXLogUtils.e(TAG,"callCreateFinish throw exception:" + e.getMessage());
    }
  }
  if(instance != null) {
    instance.callNativeTime(System.currentTimeMillis() - start);
  }
  return errorCode;
}
 
Example #12
Source File: DefaultUriAdapterTest.java    From weex-uikit with MIT License 6 votes vote down vote up
@Before
public void setup() {
  WXEnvironment.sApplication = RuntimeEnvironment.application;
  WXSDKManager wxsdkManager = WXSDKManager.getInstance();
  if (!new MockUtil().isSpy(wxsdkManager)) {
    WXSDKManager spy = Mockito.spy(wxsdkManager);
    WXSDKManagerTest.setInstance(spy);
    Mockito.when(spy.getIWXHttpAdapter()).thenReturn(new IWXHttpAdapter() {
      @Override
      public void sendRequest(WXRequest request, OnHttpListener listener) {
        //do nothing.
      }
    });
  }

  adapter = new DefaultUriAdapter();
  instance = WXSDKInstanceTest.createInstance();
}
 
Example #13
Source File: PlayDebugAdapter.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
@Override
public void initDebug(final Application application) {
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      try {
        Class cls = Class.forName("com.taobao.weex.WXPrettyFish");
        Method m = cls.getMethod("init", new Class[]{Application.class});
        m.invoke(cls, new Object[]{application});
      } catch (Exception e) {
        WXLogUtils.d("weex", "WXPrettyFish not found!");
      }
      putDebugOptions(SHOW_3D_LAYER, "true");
    }
  }, 0);
}
 
Example #14
Source File: WXBridge.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public int callCreateBody(String instanceId, String tasks, String callback) {
  long start = System.currentTimeMillis();
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if(instance != null) {
    instance.firstScreenCreateInstanceTime(start);
  }
  int errorCode = IWXBridge.INSTANCE_RENDERING;
  try {
    errorCode = WXBridgeManager.getInstance().callCreateBody(instanceId, tasks, callback);
  }catch (Throwable e){
    //catch everything during call native.
    if(WXEnvironment.isApkDebugable()){
      WXLogUtils.e(TAG,"callCreateBody throw exception:"+e.getMessage());
    }
  }
  if(instance != null) {
    instance.callNativeTime(System.currentTimeMillis() - start);
  }
  return errorCode;
}
 
Example #15
Source File: DefaultLocation.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
@Override
public void getCurrentPosition(final String successCallback, final String errorCallback, final String params) {
  if(WXEnvironment.isApkDebugable()) {
    WXLogUtils.d(TAG, "into--[getCurrentPosition] successCallback:" + successCallback + " \nerrorCallback:" + errorCallback + " \nparams:" + params);
  }
  if (!TextUtils.isEmpty(params)) {
    try {
      org.json.JSONObject jsObj = new org.json.JSONObject(params);
      boolean enableHighAccuracy = jsObj.optBoolean("enableHighAccuracy");
      boolean enableAddress = jsObj.optBoolean("address");
      WXLocationListener listener = findLocation(null, successCallback, errorCallback, enableHighAccuracy, enableAddress);
      if (listener != null) {
        mWXLocationListeners.add(listener);
      }
      return;
    } catch (JSONException e) {
      WXLogUtils.e(TAG, e);
    }
  }
  Map<String, Object> options = new HashMap<>();
  options.put(ERROR_CODE, ErrorCode.PARAMS_ERROR);
  options.put(ERROR_MSG, ErrorMsg.PARAMS_ERROR);
  WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(), errorCallback, options);
}
 
Example #16
Source File: WXDomModule.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Update {@link WXDomObject#style}
 * @param ref {@link WXDomObject#ref}
 * @param style the expected style
 */
@WXModuleAnno(moduleMethod = true, runOnUIThread = false)
public void updateStyle(String ref, JSONObject style) {
  if (TextUtils.isEmpty(ref) || style == null || style.size() < 1) {
    return;
  }
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(ref);
  task.args.add(style);
  msg.what = WXDomHandler.MsgType.WX_DOM_UPDATE_STYLE;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example #17
Source File: WXDomModule.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Scroll the specified {@link WXDomObject} to given offset in given duration
 * @param ref reference of specified dom object
 * @param options scroll option, like {offset:0, duration:300}
 */
public void scrollToElement(String ref, JSONObject options) {
  if (TextUtils.isEmpty(ref) || options == null) {
    return;
  }

  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(ref);
  task.args.add(options);
  msg.what = WXDomHandler.MsgType.WX_DOM_SCROLLTO;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example #18
Source File: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of update
 * given view is finished, and put the command object in the queue.
 */
void updateFinish() {
  if (mDestroy) {
    return;
  }
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateFinish(mInstanceId);
    }

    @Override
    public String toString() {
      return "updateFinish";
    }
  });

  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #19
Source File: WXAnimationModule.java    From weex with Apache License 2.0 6 votes vote down vote up
public static
@Nullable
Animator.AnimatorListener createAnimatorListener(final WXSDKInstance mWXSDKInstance, @Nullable final String callBack) {
  if (!TextUtils.isEmpty(callBack)) {
    return new AnimatorListenerAdapter() {
      @Override
      public void onAnimationEnd(Animator animation) {
        if (mWXSDKInstance == null) {
          WXLogUtils.e("WXRenderStatement-onAnimationEnd mWXSDKInstance == null NPE");
        } else {
          WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(),
                                              callBack,
                                              new HashMap<String, Object>());
        }
      }
    };
  } else {
    return null;
  }
}
 
Example #20
Source File: WXComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
private void updateStyleByPesudo(Map<String,Object> styles){
  Message message = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = getInstanceId();
  task.args = new ArrayList<>();

  JSONObject styleJson = new JSONObject(styles);
  task.args.add(getRef());
  task.args.add(styleJson);
  task.args.add(true);//flag pesudo
  message.obj = task;
  message.what = WXDomHandler.MsgType.WX_DOM_UPDATE_STYLE;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(message);
}
 
Example #21
Source File: WXDomModule.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXModuleAnno(moduleMethod = true, runOnUIThread = false)
public void updateFinish() {
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  msg.what = WXDomHandler.MsgType.WX_DOM_UPDATE_FINISH;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example #22
Source File: WXModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
protected final WXComponent findComponent(String ref){
  if(mWXSDKInstance != null && ref != null){
    return WXSDKManager.getInstance()
        .getWXRenderManager()
        .getWXComponent(mWXSDKInstance.getInstanceId(), ref);
  }
  return null;
}
 
Example #23
Source File: WXSwitch.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void addEvent(String type) {
  super.addEvent(type);
  if (type != null && type.equals(WXEventType.CHANGE) && getView() != null) {
    getView().setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        Map<String, Object> params = new HashMap<>(2);
        params.put("value", isChecked);
        WXSDKManager.getInstance().fireEvent(mInstanceId, mDomObj.ref, WXEventType.CHANGE, params);
      }
    });
  }
}
 
Example #24
Source File: WXDomModule.java    From weex-uikit with MIT License 5 votes vote down vote up
public void addRule(String type, JSONObject options) {
  if (TextUtils.isEmpty(type) || options == null) {
    return;
  }

  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(type);
  task.args.add(options);
  msg.what = WXDomHandler.MsgType.WX_DOM_ADD_RULE;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example #25
Source File: WXAnimationModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void transition(@Nullable String ref, @Nullable String animation, @Nullable String callBack) {
  if (!TextUtils.isEmpty(ref) && !TextUtils.isEmpty(animation) && mWXSDKInstance != null) {
    DOMAction animationActions = getAnimationAction(ref, animation, callBack);
    //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().postActionDelay(mWXSDKInstance.getInstanceId(),
                                                                 animationActions,
                                                                 false, WXDomHandler.DELAY_TIME);
  }
}
 
Example #26
Source File: WXGesture.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onLongPress(MotionEvent e) {
  if (component.containsGesture(HighLevelGesture.LONG_PRESS)) {
    List<Map<String, Object>> list = createFireEventParam(e);
    WXSDKManager.getInstance().fireEvent(component.mInstanceId,
                                         component.mDomObj.ref,
                                         HighLevelGesture.LONG_PRESS.toString(),
                                         list.get(list.size() - 1));
  }
}
 
Example #27
Source File: WXDomModule.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Notify the {@link WXDomManager} that refreshing of dom tree is finished.
 * This notify is given by JS.
 */
public void refreshFinish() {
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  msg.what = WXDomHandler.MsgType.WX_DOM_REFRESH_FINISH;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example #28
Source File: WXVideo.java    From weex-uikit with MIT License 5 votes vote down vote up
private void notify(String event, String newStatus) {
  Map<String, Object> params = new HashMap<>(2);
  params.put(Constants.Name.PLAY_STATUS, newStatus);
  params.put("timeStamp", System.currentTimeMillis());

  Map<String, Object> domChanges = new HashMap<>();
  Map<String, Object> attrsChanges = new HashMap<>();
  attrsChanges.put(Constants.Name.PLAY_STATUS, newStatus);
  domChanges.put("attrs", attrsChanges);

  WXSDKManager.getInstance().fireEvent(getInstanceId(), getRef(), event, params, domChanges);
}
 
Example #29
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public void commitJSBridgeAlarmMonitor(String instanceId, WXErrorCode errCode, String errMsg) {
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  IWXUserTrackAdapter adapter = WXSDKManager.getInstance().getIWXUserTrackAdapter();
  if (instance == null || adapter == null || errCode == null) {
    return;
  }
  WXPerformance performance = new WXPerformance();
  performance.args=instance.getBundleUrl();
  performance.errCode=errCode.getErrorCode();
  if (errCode != WXErrorCode.WX_SUCCESS) {
    performance.appendErrMsg(TextUtils.isEmpty(errMsg)?errCode.getErrorMsg():errMsg);
    WXLogUtils.e("wx_monitor",performance.toString());
  }
  adapter.commit(WXEnvironment.getApplication(), null, IWXUserTrackAdapter.JS_BRIDGE, performance, instance.getUserTrackParams());
}
 
Example #30
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public int callAddElement(String instanceId, String ref,String dom,String index, String callback){

    if (WXEnvironment.isApkDebugable()) {
      mLodBuilder.append("[WXBridgeManager] callNative::callAddElement >>>> instanceId:").append(instanceId)
              .append(", ref:").append(ref).append(", dom:").append(dom).append(", callback:").append(callback);
      WXLogUtils.d(mLodBuilder.substring(0));
      mLodBuilder.setLength(0);
    }

    if(mDestroyedInstanceId!=null && mDestroyedInstanceId.contains(instanceId)){
      return IWXBridge.DESTROY_INSTANCE;
    }


    if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
      long start = System.currentTimeMillis();
      JSONObject domObject = JSON.parseObject(dom);

      if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
        WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start);
      }
      WXDomModule domModule = getDomModule(instanceId);
      domModule.addElement(ref, domObject, Integer.parseInt(index));
    }

    if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) {
      return IWXBridge.INSTANCE_RENDERING_ERROR;
    }
    // get next tick
    getNextTick(instanceId, callback);
    return IWXBridge.INSTANCE_RENDERING;

  }