Search in sources :

Example 11 with WXSDKInstance

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

the class WXBridgeManager method reportJSException.

/**
   * 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());
            }
        }
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXJSExceptionInfo(com.taobao.weex.common.WXJSExceptionInfo) IWXJSExceptionAdapter(com.taobao.weex.adapter.IWXJSExceptionAdapter)

Example 12 with WXSDKInstance

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

the class WXPageActivity method loadWXfromLocal.

private void loadWXfromLocal(boolean reload) {
    if (reload && mInstance != null) {
        mInstance.destroy();
        mInstance = null;
    }
    if (mInstance == null) {
        RenderContainer renderContainer = new RenderContainer(this);
        mInstance = new WXSDKInstance(this);
        mInstance.setRenderContainer(renderContainer);
        mInstance.registerRenderListener(this);
        mInstance.setNestedInstanceInterceptor(this);
        mInstance.setTrackComponent(true);
    }
    mContainer.post(new Runnable() {

        @Override
        public void run() {
            Activity ctx = WXPageActivity.this;
            Rect outRect = new Rect();
            ctx.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
            mConfigMap.put("bundleUrl", mUri.toString());
            String path = mUri.getScheme().equals("file") ? assembleFilePath(mUri) : mUri.toString();
            mInstance.render(TAG, WXFileUtils.loadAsset(path, WXPageActivity.this), mConfigMap, null, WXRenderStrategy.APPEND_ASYNC);
        }
    });
}
Also used : Rect(android.graphics.Rect) WXSDKInstance(com.taobao.weex.WXSDKInstance) RenderContainer(com.taobao.weex.RenderContainer) Activity(android.app.Activity)

Example 13 with WXSDKInstance

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

the class WXEmbed method createInstance.

private WXSDKInstance createInstance() {
    WXSDKInstance sdkInstance = getInstance().createNestedInstance(this);
    getInstance().addOnInstanceVisibleListener(this);
    sdkInstance.registerRenderListener(mListener);
    String url = src;
    if (mListener != null && mListener.mEventListener != null) {
        url = mListener.mEventListener.transformUrl(src);
        if (!mListener.mEventListener.onPreCreate(this, src)) {
            //cancel render
            return null;
        }
    }
    if (TextUtils.isEmpty(url)) {
        mListener.mEventListener.onException(this, WXRenderErrorCode.WX_USER_INTERCEPT_ERROR, "degradeToH5");
        return sdkInstance;
    }
    ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams();
    sdkInstance.renderByUrl(WXPerformance.DEFAULT, url, null, null, layoutParams.width, layoutParams.height, WXRenderStrategy.APPEND_ASYNC);
    return sdkInstance;
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) ViewGroup(android.view.ViewGroup)

Example 14 with WXSDKInstance

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

the class WXVideo method setSrc.

@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
    if (TextUtils.isEmpty(src) || getHostView() == null) {
        return;
    }
    if (!TextUtils.isEmpty(src)) {
        WXSDKInstance instance = getInstance();
        mWrapper.setVideoURI(instance.rewriteUri(Uri.parse(src), URIAdapter.VIDEO));
        mWrapper.getProgressBar().setVisibility(View.VISIBLE);
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance)

Example 15 with WXSDKInstance

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

the class WXImage method setSrc.

@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
    if (src == null) {
        return;
    }
    WXSDKInstance instance = getInstance();
    Uri rewrited = instance.rewriteUri(Uri.parse(src), URIAdapter.IMAGE);
    if (Constants.Scheme.LOCAL.equals(rewrited.getScheme())) {
        setLocalSrc(rewrited);
    } else {
        setRemoteSrc(rewrited);
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) Uri(android.net.Uri)

Aggregations

WXSDKInstance (com.taobao.weex.WXSDKInstance)30 IWXRenderTask (com.taobao.weex.ui.IWXRenderTask)10 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 RenderContainer (com.taobao.weex.RenderContainer)2 Activity (android.app.Activity)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 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)1 IWXJSExceptionAdapter (com.taobao.weex.adapter.IWXJSExceptionAdapter)1 IWXUserTrackAdapter (com.taobao.weex.adapter.IWXUserTrackAdapter)1 WXErrorCode (com.taobao.weex.common.WXErrorCode)1 WXException (com.taobao.weex.common.WXException)1