Search in sources :

Example 16 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXBridgeManager method commitJSBridgeAlarmMonitor.

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());
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXPerformance(com.taobao.weex.common.WXPerformance) IWXUserTrackAdapter(com.taobao.weex.adapter.IWXUserTrackAdapter)

Example 17 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXBridgeManager method invokeRefreshInstance.

private void invokeRefreshInstance(String instanceId, WXRefreshData refreshData) {
    try {
        if (!isJSFrameworkInit()) {
            WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
            if (instance != null) {
                instance.onRenderError(WXRenderErrorCode.WX_CREATE_INSTANCE_ERROR, "createInstance failed!");
            }
            String err = "[WXBridgeManager] invokeRefreshInstance: framework.js uninitialized.";
            commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, err);
            WXLogUtils.e(err);
            return;
        }
        long start = System.currentTimeMillis();
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.d("refreshInstance >>>> instanceId:" + instanceId + ", data:" + refreshData.data + ", isDirty:" + refreshData.isDirty);
        }
        if (refreshData.isDirty) {
            return;
        }
        WXJSObject instanceIdObj = new WXJSObject(WXJSObject.String, instanceId);
        WXJSObject dataObj = new WXJSObject(WXJSObject.JSON, refreshData.data == null ? "{}" : refreshData.data);
        WXJSObject[] args = { instanceIdObj, dataObj };
        invokeExecJS(instanceId, null, METHOD_REFRESH_INSTANCE, args);
        WXLogUtils.renderPerformanceLog("invokeRefreshInstance", System.currentTimeMillis() - start);
    } catch (Throwable e) {
        String err = "[WXBridgeManager] invokeRefreshInstance " + e.getCause();
        commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, err);
        WXLogUtils.e(err);
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance)

Example 18 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXBridgeManager method createInstance.

/**
   * Create instance.
   */
public void createInstance(final String instanceId, final String template, final Map<String, Object> options, final String data) {
    final WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
    if (instance == null) {
        WXLogUtils.e("WXBridgeManager", "createInstance failed, SDKInstance is not exist");
        return;
    }
    if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(template) || mJSHandler == null) {
        instance.onRenderError(WXRenderErrorCode.WX_CREATE_INSTANCE_ERROR, "createInstance fail!");
        return;
    }
    WXModuleManager.createDomModule(instance);
    post(new Runnable() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            invokeCreateInstance(instance, template, options, data);
            final long totalTime = System.currentTimeMillis() - start;
            WXSDKManager.getInstance().postOnUiThread(new Runnable() {

                @Override
                public void run() {
                    instance.createInstanceFinished(totalTime);
                }
            }, 0);
        }
    }, instanceId);
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance)

Example 19 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXDomStatement method updateStyle.

/**
   * Update styles according to the given style. Then creating a
   * command object for updating corresponding view and put the command object in the queue.
   * @param ref Reference of the dom.
   * @param style the new style. This style is only a part of the full style, and will be merged
   *              into styles
   * @param byPesudo updateStyle by pesduo class
   * @see #updateAttrs(String, JSONObject)
   */
void updateStyle(String ref, JSONObject style, boolean byPesudo) {
    if (mDestroy || style == null) {
        return;
    }
    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
    WXDomObject domObject = mRegistry.get(ref);
    if (domObject == null) {
        if (instance != null) {
            instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATESTYLE);
        }
        return;
    }
    Map<String, Object> animationMap = new ArrayMap<>(2);
    animationMap.put(WXDomObject.TRANSFORM, style.remove(WXDomObject.TRANSFORM));
    animationMap.put(WXDomObject.TRANSFORM_ORIGIN, style.remove(WXDomObject.TRANSFORM_ORIGIN));
    animations.add(new Pair<>(ref, animationMap));
    if (!style.isEmpty()) {
        domObject.updateStyle(style, byPesudo);
        domObject.traverseTree(ApplyStyleConsumer.getInstance());
        updateStyle(domObject, style);
    }
    mDirty = true;
    if (instance != null) {
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) ArrayMap(android.support.v4.util.ArrayMap) JSONObject(com.alibaba.fastjson.JSONObject)

Example 20 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXDomStatement method updateAttrs.

/**
   * Update the attributes according to the given attribute. Then creating a
   * command object for updating corresponding view and put the command object in the queue.
   * @param ref Reference of the dom.
   * @param attrs the new style. This style is only a part of the full attribute set, and will be
   *              merged into attributes
   * @see #updateStyle(String, JSONObject)
   */
void updateAttrs(String ref, final JSONObject attrs) {
    if (mDestroy) {
        return;
    }
    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
    final WXDomObject domObject = mRegistry.get(ref);
    if (domObject == null) {
        if (instance != null) {
            instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATEATTRS);
        }
        return;
    }
    domObject.updateAttr(attrs);
    mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
            mWXRenderManager.updateAttrs(mInstanceId, domObject.getRef(), attrs);
        }

        @Override
        public String toString() {
            return "updateAttr";
        }
    });
    mDirty = true;
    if (instance != null) {
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
    }
}
Also used : IWXRenderTask(com.taobao.weex.ui.IWXRenderTask) WXSDKInstance(com.taobao.weex.WXSDKInstance)

Aggregations

WXSDKInstance (com.taobao.weex.WXSDKInstance)33 IWXRenderTask (com.taobao.weex.ui.IWXRenderTask)10 Activity (android.app.Activity)3 RenderContainer (com.taobao.weex.RenderContainer)3 WXDomObject (com.taobao.weex.dom.WXDomObject)3 Spacing (com.taobao.weex.dom.flex.Spacing)3 WXComponent (com.taobao.weex.ui.component.WXComponent)3 Before (org.junit.Before)3 Rect (android.graphics.Rect)2 NotificationBean (com.benmu.framework.model.NotificationBean)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 ArrayMap (android.support.v4.util.ArrayMap)1 ViewGroup (android.view.ViewGroup)1 JSONObject (com.alibaba.fastjson.JSONObject)1 WXHttpTask (com.alibaba.weex.https.WXHttpTask)1 WXRequestListener (com.alibaba.weex.https.WXRequestListener)1 AbstractWeexActivity (com.benmu.framework.activity.AbstractWeexActivity)1 ResultActivity (com.benmu.framework.activity.ResultActivity)1 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)1