コード例 #1
0
  private UiEventHandlerLoader() {
    ClassFilter filter = new UiEventHandlerClassFilter();

    List<Class> scanPackage =
        ClassScanUtil.scanPackage(
            AspirecnCorpSocial.getContext(),
            PropertyInfo.getInstance().getString("eventBusScanPath"),
            filter);

    for (Class<IHandler<?, ?>> clazz : scanPackage) {
      if (filter.accept(clazz)) {
        Annotation annotation = clazz.getAnnotation(UIEventHandler.class);

        Class<? extends BusEvent> eventType = ((UIEventHandler) annotation).eventType();

        IHandler<?, ?> newInstance = null;
        try {
          newInstance = clazz.newInstance();
          BeanContainer.getInstance().fetchBean(newInstance);
        } catch (InstantiationException e) {
          LogUtil.e("实例化UI处理类异常", e);
        } catch (IllegalAccessException e) {
          LogUtil.e("实例化UI处理类异常", e);
        } catch (Exception e) {
          e.printStackTrace();
        }
        uiEventHandlerMap.put(eventType, newInstance);
      }
    }
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  private UiEventHandlerLoader(List<Class> scanPackage) {
    ClassFilter filter = new UiEventHandlerClassFilter();

    for (Class<IHandler<?, ?>> clazz : scanPackage) {
      if (filter.accept(clazz)) {
        Annotation annotation = clazz.getAnnotation(UIEventHandler.class);

        Class<? extends BusEvent> eventType = ((UIEventHandler) annotation).eventType();

        IHandler<?, ?> newInstance = null;
        try {
          newInstance = clazz.newInstance();
          BeanContainer.getInstance().fetchBean(newInstance);
        } catch (InstantiationException e) {
          LogUtil.e("实例化UI处理类异常", e);
        } catch (IllegalAccessException e) {
          LogUtil.e("实例化UI处理类异常", e);
        } catch (Exception e) {
          e.printStackTrace();
        }
        uiEventHandlerMap.put(eventType, newInstance);
      }
    }
  }