com.taobao.weex.common.WXRuntimeException Java Examples

The following examples show how to use com.taobao.weex.common.WXRuntimeException. 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: BasicListComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
private void recycleImage(View view) {
  if (view instanceof ImageView) {
    if (getInstance().getImgLoaderAdapter() != null) {
      getInstance().getImgLoaderAdapter().setImage(null, (ImageView) view,
          null, null);
    } else {
      if (WXEnvironment.isApkDebugable()) {
        throw new WXRuntimeException("getImgLoaderAdapter() == null");
      }
      WXLogUtils.e("Error getImgLoaderAdapter() == null");
    }

  } else if (view instanceof ViewGroup) {
    for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
      recycleImage(((ViewGroup) view).getChildAt(i));
    }
  }
}
 
Example #2
Source File: WXDomManager.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Remove the specified dom statement. This is called when {@link WXSDKManager} destroy
 * instances.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 */
public void removeDomStatement(String instanceId) {
  if (!WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXDomManager] removeDomStatement");
  }
  final WXDomStatement statement = mDomRegistries.remove(instanceId);
  if (statement != null) {
    post(new Runnable() {

      @Override
      public void run() {
        statement.destroy();
      }
    });
  }
}
 
Example #3
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 #4
Source File: WXViewUtils.java    From weex-uikit with MIT License 6 votes vote down vote up
public static int getScreenWidth(Context ctx) {
  if(ctx!=null){
    Resources res = ctx.getResources();
    mScreenWidth = res.getDisplayMetrics().widthPixels;

    if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
      mScreenHeight = res
              .getDisplayMetrics()
              .heightPixels;
      mScreenWidth = mScreenHeight > mScreenWidth ? mScreenWidth : mScreenHeight;
    }
  } else if(WXEnvironment.isApkDebugable()){
    throw new WXRuntimeException("Error Context is null When getScreenHeight");
  }
  return mScreenWidth;
}
 
Example #5
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void destroy() {
  ComponentObserver observer;
  if ((observer = getInstance().getComponentObserver()) != null) {
    observer.onPreDestory(this);
  }

  if (WXEnvironment.isApkDebugable() && !WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXComponent] destroy can only be called in main thread");
  }
  if(mHost!= null && mHost.getLayerType()==View.LAYER_TYPE_HARDWARE && isLayerTypeEnabled()) {
    mHost.setLayerType(View.LAYER_TYPE_NONE, null);
  }
  removeAllEvent();
  removeStickyStyle();

  View view;
  if(mDomObj.isFixed() && (view = getHostView()) != null){
    getInstance().removeFixedView(view);
  }

  mDomObj = ImmutableDomObject.DESTROYED;
  mIsDestroyed = true;
}
 
Example #6
Source File: WXComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
/********************************
 *  end hook Activity life cycle callback
 ********************************************************/


public void destroy() {
  if (WXEnvironment.isApkDebugable() && !WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXComponent] destroy can only be called in main thread");
  }
  if(mHost!= null && mHost.getLayerType()==View.LAYER_TYPE_HARDWARE) {
    mHost.setLayerType(View.LAYER_TYPE_NONE, null);
  }
  removeAllEvent();
  removeStickyStyle();
  if (mDomObj != null) {
    mDomObj = null;
  }
}
 
Example #7
Source File: SimpleComponentHolder.java    From ucar-weex-core with Apache License 2.0 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 #8
Source File: WXDomManager.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the specified dom statement. This is called when {@link WXSDKManager} destroy
 * instances.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 */
public void removeDomStatement(String instanceId) {
  if (!WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXDomManager] removeDomStatement");
  }
  final WXDomStatement statement = mDomRegistries.remove(instanceId);
  if (statement != null) {
    post(new Runnable() {

      @Override
      public void run() {
        statement.destroy();
      }
    });
  }
}
 
Example #9
Source File: WXDomManager.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the specified dom statement. This is called when {@link WXSDKManager} destroy
 * instances.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 */
public void removeDomStatement(String instanceId) {
  if (!WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXDomManager] removeDomStatement");
  }
  final DOMActionContextImpl statement = mDomRegistries.remove(instanceId);
  if (statement != null) {
    post(new Runnable() {

      @Override
      public void run() {
        statement.destroy();
      }
    });
  }
}
 
Example #10
Source File: WXViewUtils.java    From weex with Apache License 2.0 6 votes vote down vote up
@Deprecated
public static int getScreenWidth( ) {
  if(WXEnvironment.sApplication!=null) {
    int width = WXEnvironment.sApplication.getResources().getDisplayMetrics().widthPixels;

    if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
      int height = WXEnvironment.sApplication.getResources()
              .getDisplayMetrics()
              .heightPixels;
      width = height > width ?width:height;
    }
    return width;
  }
  if(WXEnvironment.isApkDebugable()){
    throw new WXRuntimeException("Error Context is null When getScreenHeight");
  }
  return 0;
}
 
Example #11
Source File: WXViewUtils.java    From weex with Apache License 2.0 6 votes vote down vote up
public static int getScreenWidth(Context cxt) {
  if(cxt!=null){
    int width = WXEnvironment.sApplication.getResources().getDisplayMetrics().widthPixels;

    if(WXEnvironment.SETTING_FORCE_VERTICAL_SCREEN){
      int height = WXEnvironment.sApplication.getResources()
              .getDisplayMetrics()
              .heightPixels;
      width = height > width ?width:height;
    }
    return width;
  }
  if(WXEnvironment.isApkDebugable()){
    throw new WXRuntimeException("Error Context is null When getScreenHeight");
  }
  return 0;
}
 
Example #12
Source File: WXListComponent.java    From weex with Apache License 2.0 6 votes vote down vote up
private void recycleImage(View view) {
    if (view instanceof ImageView) {
        if (mInstance.getImgLoaderAdapter() != null) {
            mInstance.getImgLoaderAdapter().setImage(null, (ImageView) view,
                    null, null);
        } else {
            if (WXEnvironment.isApkDebugable()) {
                throw new WXRuntimeException("getImgLoaderAdapter() == null");
            }
            WXLogUtils.e("Error getImgLoaderAdapter() == null");
        }

    } else if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            recycleImage(((ViewGroup) view).getChildAt(i));
        }
    }
}
 
Example #13
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for creating body according to the JSONObject.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param element the jsonObject according to which to create command object.
 */
void createBody(String instanceId, JSONObject element) {
  if (!isDomThread()) {
    throw new WXRuntimeException("Create body operation must be done in dom thread");
  }
  WXDomStatement statement = new WXDomStatement(instanceId, mWXRenderManager);
  mDomRegistries.put(instanceId, statement);
  statement.createBody(element);
}
 
Example #14
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for adding a default event listener to the corresponding {@link
 * WXDomObject}.
 *
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param type the type of the event, this may be a plain event defined in
 * {@link com.taobao.weex.ui.component.WXEventType} or a gesture defined in {@link com.taobao
 * .weex.ui.view.gesture.WXGestureType}
 */
void addEvent(String instanceId, String ref, String type) {
  if (!isDomThread()) {
    throw new WXRuntimeException("AddEvent operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.addEvent(ref, type);
}
 
Example #15
Source File: WXSDKManager.java    From weex with Apache License 2.0 5 votes vote down vote up
void destroyInstance(String instanceId) {
  if (TextUtils.isEmpty(instanceId)) {
    return;
  }
  if (!WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXSDKManager] destroyInstance error");
  }
  mWXRenderManager.removeRenderStatement(instanceId);
  mWXDomManager.removeDomStatement(instanceId);
  mBridgeManager.destroyInstance(instanceId);
  WXModuleManager.destroyInstanceModules(instanceId);
}
 
Example #16
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Batch the execution of {@link WXDomStatement}
 */
void batch() {
  if (!isDomThread()) {
    throw new WXRuntimeException("Batch operation must be done in dom thread");
  }

  Iterator<Entry<String, WXDomStatement>> iterator = mDomRegistries.entrySet().iterator();
  while (iterator.hasNext()) {
    iterator.next().getValue().batch();
  }
}
 
Example #17
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for adding a dom node to its parent in a specific location.
 *
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param element the dom object in the form of JSONObject
 * @param parentRef parent to which the dom is added.
 * @param index the location of which the dom is added.
 */
void addDom(String instanceId, String parentRef, JSONObject element, int index) {
  if (!isDomThread()) {
    throw new WXRuntimeException("Add dom operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.addDom(element, parentRef, index);
}
 
Example #18
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for removing the specified {@link WXDomObject}.
 *
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param ref {@link WXDomObject#ref} of the dom.
 */
//removeElement(ref:String)
void removeDom(String instanceId, String ref) {
  if (!isDomThread()) {
    throw new WXRuntimeException("Remove dom operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.removeDom(ref);
}
 
Example #19
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for moving the specific {@link WXDomObject} to a new parent.
 *
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param ref {@link WXDomObject#ref} of the dom to be moved.
 * @param parentRef {@link WXDomObject#ref} of the new parent DOM node
 * @param index the index of the dom to be inserted in the new parent.
 */
void moveDom(String instanceId, String ref, String parentRef, int index) {
  if (!isDomThread()) {
    throw new WXRuntimeException("Move dom operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.moveDom(ref, parentRef, index);
}
 
Example #20
Source File: WXSDKManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * FireEvent back to JS
 */
public void fireEvent(final String instanceId, String ref, String type, Map<String, Object> params) {
  if (WXEnvironment.isApkDebugable() && Looper.getMainLooper().getThread().getId() != Thread.currentThread().getId()) {
    throw new WXRuntimeException("[WXSDKManager]  fireEvent error");
  }
  mBridgeManager.fireEvent(instanceId, ref, type, params);
}
 
Example #21
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for updating the {@link WXDomObject#attr} according to the
 * given attribute.
 *
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param attr the new attribute. This attribute is only a part of the full attribute, and will be
 *             merged into {@link WXDomObject#attr}
 */
void updateAttrs(String instanceId, String ref, JSONObject attr) {
  if (!isDomThread()) {
    throw new WXRuntimeException("UpdateAttrs operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.updateAttrs(ref, attr);
}
 
Example #22
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke {@link WXDomStatement} for updating style
 *
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param ref the given dom object
 * @param style the given style.
 */
void updateStyle(String instanceId, String ref, JSONObject style) {
  if (!isDomThread()) {
    throw new WXRuntimeException("UpdateStyle operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.updateStyle(ref, style);
}
 
Example #23
Source File: WXBridgeManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the JavaScript about the event happened on Android
 */
public void fireEvent(final String instanceId, final String ref,
                      final String type, final Map<String, Object> data) {
  if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(ref)
      || TextUtils.isEmpty(type) || mJSHandler == null) {
    return;
  }
  if (!checkMainThread()) {
    throw new WXRuntimeException(
        "fireEvent must be called by main thread");
  }
  addUITask(METHOD_FIRE_EVENT, instanceId, ref, type, data);
  sendMessage(instanceId, WXJSBridgeMsgType.CALL_JS_BATCH);
}
 
Example #24
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke the {@link WXDomStatement} for removing the event listener of the corresponding {@link
 * WXDomObject}.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param type the type of the event, this may be a plain event defined in
 * {@link com.taobao.weex.ui.component.WXEventType} or a gesture defined in {@link com.taobao
 * .weex.ui.view.gesture.WXGestureType}
 */
void removeEvent(String instanceId, String ref, String type) {
  if (!isDomThread()) {
    throw new WXRuntimeException("RemoveEvent operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.removeEvent(ref, type);
}
 
Example #25
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke the {@link WXDomStatement} for scrolling the given view to the specified position.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance to
 *                                                                    scroll.
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param options the specified position
 */
void scrollToDom(String instanceId, String ref, JSONObject options) {
  if (!isDomThread()) {
    throw new WXRuntimeException("ScrollToDom operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.scrollToDom(ref, options);
}
 
Example #26
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the creating of whole dom tree has finished. This message is sent by JS.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance to
 *                                                                    notify.
 */
void createFinish(String instanceId) {
  if (!isDomThread()) {
    throw new WXRuntimeException("CreateFinish operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.createFinish();
}
 
Example #27
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the refreshing has finished.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance to
 *                                                                    notify.
 */
void refreshFinish(String instanceId) {
  if (!isDomThread()) {
    throw new WXRuntimeException("RefreshFinish operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.refreshFinish();
}
 
Example #28
Source File: WXDomManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the update has finished.
 * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance to
 *                                                                    notify.
 */
void updateFinish(String instanceId) {
  if (!isDomThread()) {
    throw new WXRuntimeException("RefreshFinish operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    return;
  }
  statement.updateFinish();
}
 
Example #29
Source File: WXRenderManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Remove renderStatement, can only be invoked in UI thread.
 * @param instanceId {@link WXSDKInstance#mInstanceId}
 */
public void removeRenderStatement(String instanceId) {
  if (!WXUtils.isUiThread()) {
    throw new WXRuntimeException("[WXRenderManager] removeRenderStatement can only be called in main thread");
  }
  WXRenderStatement statement = mRegistries.remove(instanceId);
  if (statement != null) {
    statement.destroy();
  }
}
 
Example #30
Source File: ComponentHolder.java    From weex with Apache License 2.0 5 votes vote down vote up
private synchronized void generate(){
  WXLogUtils.d(TAG,"Generate Component:"+mClz.getSimpleName());
  HashMap<String, Invoker> methods = new HashMap<>();

  Annotation[] annotations;
  Annotation anno;
  for (Method method : mClz.getMethods()) {
    annotations = method.getDeclaredAnnotations();
    for (int i = 0,annotationsCount = annotations.length;
         i < annotationsCount; ++i) {
      anno = annotations[i];
      if (anno != null && anno instanceof WXComponentProp) {
        String name = ((WXComponentProp) anno).name();
        methods.put(name, new MethodInvoker(method));
        break;
      }
    }
  }

  mMethods = methods;
  try {
    mConstructor = mClz.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class);
  } catch (NoSuchMethodException e) {
    try {
      //compatible deprecated constructor
      mConstructor = mClz.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class);
    } catch (NoSuchMethodException e1) {
      e1.printStackTrace();
      throw new WXRuntimeException("Can't find constructor of component.");
    }
    e.printStackTrace();
  }
}