com.taobao.weex.WXSDKInstance Java Examples

The following examples show how to use com.taobao.weex.WXSDKInstance. 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: SimpleComponentHolder.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  if(mConstructor == null){
    loadConstructor();
  }
  int parameters = mConstructor.getParameterTypes().length;
  WXComponent component;

  if(parameters == 3){
    component =  mConstructor.newInstance(instance,node,parent);
  }else if(parameters == 4){
    component =  mConstructor.newInstance(instance,node,parent,false);
  }else{
    //compatible deprecated constructor
    component =  mConstructor.newInstance(instance,node,parent,instance.getInstanceId(),parent.isLazy());
  }
  return component;
}
 
Example #2
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 #3
Source File: UWXFrameBaseActivity.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
    public void onViewCreated(WXSDKInstance wxsdkInstance, View view) {
        super.onViewCreated(wxsdkInstance, view);
        WXComponent comp = mInstance.getRootComponent();
        if (comp != null) {
            WXEvent events = comp.getDomObject().getEvents();
            boolean hasReady = events.contains(UConstants.Event.READY);
            if (hasReady) {
                Map<String, Object> data = new HashMap<>();
                data.put("param", wxInfo.getParam());
                WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.READY, data, null);
            }
        }
//        if (!isHasNavBar) {
//            setTranslateAnimation(getContainer());
//        }
    }
 
Example #4
Source File: SimpleComponentHolder.java    From weex-uikit with MIT License 6 votes vote down vote up
private void loadConstructor(){
  Class<? extends WXComponent> c = mCompClz;
  Constructor<? extends WXComponent> constructor;
  try {
    constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class);
  } catch (NoSuchMethodException e) {
    WXLogUtils.d("ClazzComponentCreator","Use deprecated component constructor");
    try {
      //compatible deprecated constructor with 4 args
      constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class);
    } catch (NoSuchMethodException e1) {
      try {
        //compatible deprecated constructor with 5 args
        constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class);
      } catch (NoSuchMethodException e2) {
        throw new WXRuntimeException("Can't find constructor of component.");
      }
    }
  }
  mConstructor = constructor;
}
 
Example #5
Source File: ComponentHolder.java    From weex with Apache License 2.0 6 votes vote down vote up
public WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  if(mConstructor == null){
    generate();
  }
  int parameters = mConstructor.getParameterTypes().length;
  WXComponent component;
  if(parameters == 4){
    component =  mConstructor.newInstance(instance,node,parent,lazy);
  }else{
    //compatible deprecated constructor
    component =  mConstructor.newInstance(instance,node,parent,instance.getInstanceId(),lazy);
  }

  component.setHolder(this);
  return component;
}
 
Example #6
Source File: WXSvgContainer.java    From Svg-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
public WXSvgContainer(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) {
  super(instance, dom, parent);
  mDom = dom;
  Log.v("WXSvgContainer", mDom.getAttrs().values().toString());
  if (mDom.getStyles().get(Constants.Name.HEIGHT) == null) {
    mDom.getStyles().put(Constants.Name.HEIGHT, "0");
  }
  if (mDom.getStyles().get(Constants.Name.WIDTH) == null) {
    mDom.getStyles().put(Constants.Name.WIDTH, "0");
  }
  mScale = (float) (WXViewUtils.getScreenWidth(parent.getContext()) * 1.0 / dom.getViewPortWidth());
}
 
Example #7
Source File: TabPagerFragment.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(WXSDKInstance instance, View view) {
    if (mGankIoContent.getChildCount() > 0) {
        mGankIoContent.removeAllViews();
    }
    mGankIoContent.addView(view);
}
 
Example #8
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 #9
Source File: WXRenderStatementTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    PowerMockito.mockStatic(WXSoInstallMgrSdk.class);
    PowerMockito.mockStatic(TextUtils.class);
    PowerMockito.mockStatic(WXComponentFactory.class);
    PowerMockito.when(TextUtils.isEmpty("124")).thenReturn(true);
    PowerMockito.when(WXSoInstallMgrSdk.initSo(null, 1, null)).thenReturn(true);
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    mWXRenderStatement = new WXRenderStatement(instance);
}
 
Example #10
Source File: WXAnalyzerDelegate.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
public void onException(WXSDKInstance instance, String errCode, String msg) {
    if (mWXAnalyzer == null) {
        return;
    }
    if (TextUtils.isEmpty(errCode) && TextUtils.isEmpty(msg)) {
        return;
    }
    try {
        Method method = mWXAnalyzer.getClass().getDeclaredMethod("onException", WXSDKInstance.class, String.class, String.class);
        method.invoke(mWXAnalyzer, instance, errCode, msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #11
Source File: ModuleInvocationAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void executeRender(RenderActionContext context) {
    WXSDKInstance instance;
    if(context == null || (instance = context.getInstance()) == null) {
        return;
    }
    NativeInvokeHelper helper = instance.getNativeInvokeHelper();
    try {
        helper.invoke(mWXModule,mInvoker,mArgs);
    } catch (Exception e) {
        WXLogUtils.e("callModuleMethod >>> invoke module:" + mWXModule.getClass().getSimpleName()
                + " failed. ", e);
    }
}
 
Example #12
Source File: AbstractWeexActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
protected void renderPage(String template,String source,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, source);
  mInstance.render(
    getPageName(),
    template,
    options,
    jsonInitData,
    ScreenUtil.getDisplayWidth(this),
    ScreenUtil.getDisplayHeight(this),
    WXRenderStrategy.APPEND_ASYNC);
}
 
Example #13
Source File: DefautDebugAdapter.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public View wrapContainer(WXSDKInstance instance, View wxView) {
  if (wxView != null && wxView.getContext() != null && wxView.getParent() == null && TextUtils.equals(getDebugOptions(SHOW_3D_LAYER),"true")) {
    ScalpelFrameLayout scalpelFrameLayout = new ScalpelFrameLayout(wxView.getContext());
    WXDebugTool.updateScapleView(scalpelFrameLayout);
    scalpelFrameLayout.addView(wxView);
    instance.registerActivityStateListener(new DebugActivityState(wxView));
    return scalpelFrameLayout;
  }
  return wxView;
}
 
Example #14
Source File: StandardVDomMonitor.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Override
    public void monitor(@NonNull WXSDKInstance instance) {
        this.mInstance = instance;
//        View view = instance.getGodCom().getHostView();
        View view = instance.getContainerView();
        if(view == null) {
            WXLogUtils.e(TAG,"host view is null");
            return;
        }

        view.getViewTreeObserver().addOnGlobalLayoutListener(mLayoutChangeListener);
    }
 
Example #15
Source File: WXPageActivity.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@Override
public void onRenderSuccess(WXSDKInstance instance, int width, int height) {
  if(mWxAnalyzerDelegate  != null){
    mWxAnalyzerDelegate.onWeexRenderSuccess(instance);
  }
  mProgressBar.setVisibility(View.INVISIBLE);
}
 
Example #16
Source File: WXEmbed.java    From weex-uikit with MIT License 5 votes vote down vote up
public WXEmbed(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
  super(instance, node, parent);
  mListener = new EmbedRenderListener(this);

  ERROR_IMG_WIDTH = (int) WXViewUtils.getRealPxByWidth(270,instance.getViewPortWidth());
  ERROR_IMG_HEIGHT = (int) WXViewUtils.getRealPxByWidth(260,instance.getViewPortWidth());
  if(instance instanceof EmbedManager) {
    Object itemId = node.getAttrs().get(ITEM_ID);
    if (itemId != null) {
      ((EmbedManager) instance).putEmbed(itemId.toString(), this);
    }
  }
}
 
Example #17
Source File: WXDivTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom,"1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
 
Example #18
Source File: WXPageActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(WXSDKInstance instance, View view) {
    WXLogUtils.e("into--[onViewCreated]");
    if (mWAView != null && mContainer != null && mWAView.getParent() == mContainer) {
        mContainer.removeView(mWAView);
    }

    mWAView = view;
    //        TopScrollHelper.getInstance(getApplicationContext()).addTargetScrollView(mWAView);
    mContainer.addView(view);
    mContainer.requestLayout();
    Log.d("WARenderListener", "renderSuccess");
}
 
Example #19
Source File: WXVideo.java    From weex-uikit with MIT License 5 votes vote down vote up
@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);
  }
}
 
Example #20
Source File: WXDivTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom,"1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
 
Example #21
Source File: ATagUtil.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onClick(View widget, String instanceId, String url) {
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if (instance == null) {
    return;
  }
  String href = instance.rewriteUri(Uri.parse(url), URIAdapter.LINK).toString();
  JSONArray array = new JSONArray();
  array.add(href);
  WXSDKManager.getInstance().getWXBridgeManager().
      callModuleMethod(instanceId, "event", "openURL", array);
}
 
Example #22
Source File: ExternalLoaderComponentHolder.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  if(mClass == null){
    mClass = mClzGetter.getExternalComponentClass(mType,instance);
  }
  ComponentCreator creator = new SimpleComponentHolder.ClazzComponentCreator(mClass);
  WXComponent component = creator.createInstance(instance,node,parent);

  component.bindHolder(this);
  return component;
}
 
Example #23
Source File: BenchmarkActivity.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(WXSDKInstance instance, View view) {
  if (root != null) {
    root.removeAllViews();
    root.addView(view);
  }
}
 
Example #24
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #25
Source File: DefaultUriAdapter.java    From weex-uikit with MIT License 5 votes vote down vote up
@NonNull
@Override
public Uri rewrite(WXSDKInstance instance, String type, Uri uri) {
  Uri base = Uri.parse(instance.getBundleUrl());
  Uri.Builder resultBuilder = uri.buildUpon();

  if (uri.isRelative()) {
    resultBuilder = buildRelativeURI(resultBuilder, base, uri);
    return resultBuilder.build();
  }
  return uri;


}
 
Example #26
Source File: WXDivTest.java    From weex with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddChild(){
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject testDom = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom.clone()).thenReturn(testDom);
    testDom.ref = "2";
    WXText child1 = new WXText(instance, testDom, mWXDiv, false);
    child1.initView();

    mWXDiv.addChild(child1, 0);

    assertEquals(1, mWXDiv.childCount());

    WXDomObject testDom2 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom2.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom2.clone()).thenReturn(testDom2);
    testDom2.ref = "3";
    child2 = new WXText(instance, testDom2, mWXDiv, false);
    child2.initView();

    mWXDiv.addChild(child2, -1);

    assertEquals(2, mWXDiv.childCount());
    assertEquals(child2, mWXDiv.getChild(1));

    WXDomObject testDom3 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom3.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom3.clone()).thenReturn(testDom3);
    testDom3.ref = "4";
    WXText child3 = new WXText(instance, testDom3, mWXDiv, false);
    child3.initView();

    mWXDiv.addChild(child3, 1);

    assertEquals(3, mWXDiv.childCount());
    assertEquals(child3, mWXDiv.getChild(1));
}
 
Example #27
Source File: DefaultLocation.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
public DefaultLocation(WXSDKInstance instance) {
  mWXSDKInstance = instance;
}
 
Example #28
Source File: WXImage.java    From weex-uikit with MIT License 4 votes vote down vote up
private void setRemoteSrc(Uri rewrited) {

      WXImageStrategy imageStrategy = new WXImageStrategy();
      imageStrategy.isClipping = true;

      WXImageSharpen imageSharpen = getDomObject().getAttrs().getImageSharpen();
      imageStrategy.isSharpen = imageSharpen == WXImageSharpen.SHARPEN;

      int radius = getDomObject().getStyles().getBlur();
      radius = Math.max(0, radius);
      imageStrategy.blurRadius = Math.min(10, radius);

      imageStrategy.setImageListener(new WXImageStrategy.ImageListener() {
        @Override
        public void onImageFinish(String url, ImageView imageView, boolean result, Map extra) {
          if (getDomObject() != null && getDomObject().getEvents().contains(Constants.Event.ONLOAD)) {
            Map<String, Object> params = new HashMap<String, Object>();
            Map<String, Object> size = new HashMap<>(2);
            if (imageView != null && imageView.getDrawable() != null && imageView.getDrawable() instanceof ImageDrawable) {
              size.put("naturalWidth", ((ImageDrawable) imageView.getDrawable()).getBitmapWidth());
              size.put("naturalHeight", ((ImageDrawable) imageView.getDrawable()).getBitmapHeight());
            } else {
              size.put("naturalWidth", 0);
              size.put("naturalHeight", 0);
            }

            if (getDomObject() != null && containsEvent(Constants.Event.ONLOAD)) {
              params.put("success", result);
              params.put("size", size);
              fireEvent(Constants.Event.ONLOAD, params);
            }
          }
        }
      });

      WXSDKInstance instance = getInstance();
      if (getDomObject().getAttrs().containsKey(Constants.Name.PLACE_HOLDER)) {
        String attr = (String) getDomObject().getAttrs().get(Constants.Name.PLACE_HOLDER);
        if (TextUtils.isEmpty(attr)) {
          imageStrategy.placeHolder = instance.rewriteUri(Uri.parse(attr), URIAdapter.IMAGE).toString();
        }
      }

      IWXImgLoaderAdapter imgLoaderAdapter = getInstance().getImgLoaderAdapter();
      if (imgLoaderAdapter != null) {
        imgLoaderAdapter.setImage(rewrited.toString(), getHostView(),
            getDomObject().getAttrs().getImageQuality(), imageStrategy);
      }
  }
 
Example #29
Source File: TestComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public TestComponent(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) {
  super(instance, dom, parent);
}
 
Example #30
Source File: WXText.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public WXText(WXSDKInstance instance, WXDomObject node,
              WXVContainer parent) {
  super(instance, node, parent);
}