com.taobao.weex.WXRenderErrorCode Java Examples

The following examples show how to use com.taobao.weex.WXRenderErrorCode. 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: WXEmbed.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void onException(NestedContainer container, String errCode, String msg) {
  if (TextUtils.equals(errCode, WXRenderErrorCode.WX_NETWORK_ERROR) && container instanceof WXEmbed) {
    final WXEmbed comp = ((WXEmbed)container);
    final ImageView imageView = new ImageView(comp.getContext());
    imageView.setImageResource(R.drawable.error);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ERROR_IMG_WIDTH, ERROR_IMG_HEIGHT);
    layoutParams.gravity = Gravity.CENTER;
    imageView.setLayoutParams(layoutParams);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setAdjustViewBounds(true);
    imageView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        imageView.setOnClickListener(null);
        imageView.setEnabled(false);
        comp.loadContent();
      }
    });
    FrameLayout hostView = comp.getHostView();
    hostView.removeAllViews();
    hostView.addView(imageView);
    WXLogUtils.e("WXEmbed", "NetWork failure :" + errCode + ",\n error message :" + msg);
  }
}
 
Example #2
Source File: WXEmbed.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
public void onException(NestedContainer container, String errCode, String msg) {
  if (TextUtils.equals(errCode, WXRenderErrorCode.WX_NETWORK_ERROR) && container instanceof WXEmbed) {
    final WXEmbed comp = ((WXEmbed)container);
    final ImageView imageView = new ImageView(comp.getContext());
    imageView.setImageResource(R.drawable.error);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ERROR_IMG_WIDTH, ERROR_IMG_HEIGHT);
    layoutParams.gravity = Gravity.CENTER;
    imageView.setLayoutParams(layoutParams);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setAdjustViewBounds(true);
    imageView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        imageView.setOnClickListener(null);
        imageView.setEnabled(false);
        comp.loadContent();
      }
    });
    FrameLayout hostView = comp.getHostView();
    hostView.removeAllViews();
    hostView.addView(imageView);
    WXLogUtils.e("WXEmbed", "NetWork failure :" + errCode + ",\n error message :" + msg);
  }
}
 
Example #3
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: WXEmbed.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: WXPageActivity.java    From yanxuan-weex-demo with MIT License 5 votes vote down vote up
@Override
public void onException(WXSDKInstance instance, String errCode, String msg) {
  mProgressBar.setVisibility(View.GONE);
  mTipView.setVisibility(View.VISIBLE);
  if (TextUtils.equals(errCode, WXRenderErrorCode.WX_NETWORK_ERROR)) {
    mTipView.setText(R.string.index_tip);
  } else {
    mTipView.setText("render error:" + errCode);
  }
}
 
Example #6
Source File: WXBridgeManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * 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);
        }
      });
    }
  }, instanceId);
}
 
Example #7
Source File: WXEmbed.java    From weex-uikit with MIT License 5 votes vote down vote up
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;
}
 
Example #8
Source File: IndexActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onException(WXSDKInstance wxsdkInstance, String s, String s1) {
  super.onException(wxsdkInstance,s,s1);
  mProgressBar.setVisibility(View.GONE);
  mTipView.setVisibility(View.VISIBLE);
  if (TextUtils.equals(s, WXRenderErrorCode.WX_NETWORK_ERROR)) {
    mTipView.setText(R.string.index_tip);
  } else {
    mTipView.setText("render error:" + s1);
  }
}
 
Example #9
Source File: IndexActivity.java    From WeexOne with MIT License 5 votes vote down vote up
@Override
public void onException(WXSDKInstance instance, String errCode, String msg) {
    mProgressBar.setVisibility(View.GONE);
    mTipView.setVisibility(View.VISIBLE);
    if (TextUtils.equals(errCode, WXRenderErrorCode.WX_NETWORK_ERROR)) {
        mTipView.setText(R.string.index_tip);
    } else {
        mTipView.setText("render error:" + msg);
    }
}
 
Example #10
Source File: IndexActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onException(WXSDKInstance wxsdkInstance, String s, String s1) {
  mProgressBar.setVisibility(View.GONE);
  mTipView.setVisibility(View.VISIBLE);
  if (TextUtils.equals(s, WXRenderErrorCode.WX_NETWORK_ERROR)) {
    mTipView.setText(R.string.index_tip);
  } else {
    mTipView.setText("render error:" + s1);
  }
}