com.taobao.weex.common.WXModule Java Examples

The following examples show how to use com.taobao.weex.common.WXModule. 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: WXModuleManager.java    From weex-uikit with MIT License 6 votes vote down vote up
/**Hook Activity life cycle callback begin***/


  public static void onActivityCreate(String instanceId){

    HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
    if(modules!=null) {
      for (String key : modules.keySet()) {
        WXModule module = modules.get(key);
        if (module != null) {
          module.onActivityCreate();
        } else {
          WXLogUtils.w("onActivityCreate can not find the " + key + " module");
        }
      }
    }

  }
 
Example #2
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies WEEX that this event has occurred
 * @param eventName WEEX register event
 * @param module Events occur in this Module
 * @param params The parameters to be notified to WEEX are required
 */
public void fireModuleEvent(String eventName, WXModule module,Map<String, Object> params) {
  if (TextUtils.isEmpty(eventName) || module == null) {
    return;
  }

  Map<String, Object> event = new HashMap<>();
  event.put("type", eventName);
  event.put("module", module.getModuleName());
  event.put("data", params);

  List<String> callbacks = module.getEventCallbacks(eventName);
  if (callbacks != null) {
    for (String callback : callbacks) {
      SimpleJSCallback jsCallback = new SimpleJSCallback(mInstanceId, callback);
      if (module.isOnce(callback)) {
        jsCallback.invoke(event);
      } else {
        jsCallback.invokeAndKeepAlive(event);
      }
    }
  }
}
 
Example #3
Source File: WXSDKInstance.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Notifies WEEX that this event has occurred
 * @param eventName WEEX register event
 * @param module Events occur in this Module
 * @param params The parameters to be notified to WEEX are required
 */
public void fireModuleEvent(String eventName, WXModule module,Map<String, Object> params) {
  if (TextUtils.isEmpty(eventName) || module == null) {
    return;
  }
  List<String> callbacks = module.getEventCallbacks(eventName);
  if (callbacks != null) {
    for (String callback : callbacks) {
      SimpleJSCallback jsCallback = new SimpleJSCallback(mInstanceId, callback);
      if (module.isOnce(callback)) {
        jsCallback.invokeAndKeepAlive(params);
      } else {
        jsCallback.invoke(params);
      }
    }
  }
}
 
Example #4
Source File: WXModuleManager.java    From weex-uikit with MIT License 6 votes vote down vote up
public static void destroyInstanceModules(String instanceId) {
  sDomModuleMap.remove(instanceId);
  HashMap<String, WXModule> moduleMap = sInstanceModuleMap.remove(instanceId);
  if (moduleMap == null || moduleMap.size() < 1) {
    return;
  }
  Iterator<Entry<String, WXModule>> iterator = moduleMap.entrySet().iterator();
  Entry<String, WXModule> entry;
  while (iterator.hasNext()) {
    entry = iterator.next();
    WXModule module = entry.getValue();
    if(module instanceof Destroyable){
      ((Destroyable)module).destroy();
    }

  }
}
 
Example #5
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public static void destroyInstanceModules(String instanceId) {
  sDomModuleMap.remove(instanceId);
  Map<String, WXModule> moduleMap = sInstanceModuleMap.remove(instanceId);
  if (moduleMap == null || moduleMap.size() < 1) {
    return;
  }
  Iterator<Entry<String, WXModule>> iterator = moduleMap.entrySet().iterator();
  Entry<String, WXModule> entry;
  while (iterator.hasNext()) {
    entry = iterator.next();
    WXModule module = entry.getValue();
    if(module instanceof Destroyable){
      ((Destroyable)module).destroy();
    }

  }
}
 
Example #6
Source File: WXModuleManager.java    From weex-uikit with MIT License 6 votes vote down vote up
private static WXModule findModule(String instanceId, String moduleStr,ModuleFactory factory) {
  // find WXModule
  WXModule wxModule = sGlobalModuleMap.get(moduleStr);

  //not global module
  if (wxModule == null) {
    HashMap<String, WXModule> moduleMap = sInstanceModuleMap.get(instanceId);
    if (moduleMap == null) {
      moduleMap = new HashMap<>();
      sInstanceModuleMap.put(instanceId, moduleMap);
    }
    // if cannot find the Module, create a new Module and save it
    wxModule = moduleMap.get(moduleStr);
    if (wxModule == null) {
      try {
        wxModule = factory.buildInstance();
      } catch (Exception e) {
        WXLogUtils.e(moduleStr + " module build instace failed.", e);
        return null;
      }
      moduleMap.put(moduleStr, wxModule);
    }
  }

  return wxModule;
}
 
Example #7
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**Hook Activity life cycle callback begin***/


  public static void onActivityCreate(String instanceId){

    Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
    if(modules!=null) {
      for (String key : modules.keySet()) {
        WXModule module = modules.get(key);
        if (module != null) {
          module.onActivityCreate();
        } else {
          WXLogUtils.w("onActivityCreate can not find the " + key + " module");
        }
      }
    }

  }
 
Example #8
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onActivityPause(String instanceId){
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityPause();
      } else {
        WXLogUtils.w("onActivityPause can not find the " + key + " module");
      }
    }
  }
}
 
Example #9
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onActivityStart(String instanceId){

    HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
    if(modules!=null) {
      for (String key : modules.keySet()) {
        WXModule module = modules.get(key);
        if (module != null) {
          module.onActivityStart();
        } else {
          WXLogUtils.w("onActivityStart can not find the " + key + " module");
        }
      }
    }
  }
 
Example #10
Source File: WXSDKInstance.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Check whether the current module registered the event
 * @param eventName EventName register in weex
 * @param module Events occur in this Module
 * @return  register->true
 */
public boolean checkModuleEventRegistered(String eventName,WXModule module) {
  if (module != null) {
    List<String> events = module.getEventCallbacks(eventName);
    if (events != null && events.size() > 0) {
      return true;
    }
  }
  return false;
}
 
Example #11
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onActivityResume(String instanceId){
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityResume();
      } else {
        WXLogUtils.w("onActivityResume can not find the " + key + " module");
      }
    }
  }
}
 
Example #12
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onActivityResult(String instanceId,int requestCode, int resultCode, Intent data){

    HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
    if(modules!=null) {
      for (String key : modules.keySet()) {
        WXModule module = modules.get(key);
        if (module != null) {
          module.onActivityResult(requestCode, resultCode, data);
        } else {
          WXLogUtils.w("onActivityResult can not find the " + key + " module");
        }
      }
    }
  }
 
Example #13
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static boolean onCreateOptionsMenu(String instanceId,Menu menu) {
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onCreateOptionsMenu(menu);
      } else {
        WXLogUtils.w("onActivityResult can not find the " + key + " module");
      }
    }
  }
  return false;
}
 
Example #14
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onActivityStop(String instanceId){
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityStop();
      } else {
        WXLogUtils.w("onActivityStop can not find the " + key + " module");
      }
    }
  }
}
 
Example #15
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onRequestPermissionsResult(String instanceId ,int requestCode, String[] permissions, int[] grantResults) {
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onRequestPermissionsResult(requestCode, permissions, grantResults);
      } else {
        WXLogUtils.w("onActivityResult can not find the " + key + " module");
      }
    }
  }
}
 
Example #16
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onActivityDestroy(String instanceId){
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityDestroy();
      } else {
        WXLogUtils.w("onActivityDestroy can not find the " + key + " module");
      }
    }
  }
}
 
Example #17
Source File: WXModuleManager.java    From weex-uikit with MIT License 5 votes vote down vote up
public static boolean onActivityBack(String instanceId){
  HashMap<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        return module.onActivityBack();
      } else {
        WXLogUtils.w("onActivityCreate can not find the " + key + " module");
      }
    }
  }
  return false;
}
 
Example #18
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the current module registered the event
 * @param eventName EventName register in weex
 * @param module Events occur in this Module
 * @return  register->true
 */
public boolean checkModuleEventRegistered(String eventName,WXModule module) {
  if (module != null) {
    List<String> events = module.getEventCallbacks(eventName);
    if (events != null && events.size() > 0) {
      return true;
    }
  }
  return false;
}
 
Example #19
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private static Object dispatchCallModuleMethod(@NonNull WXSDKInstance instance, @NonNull WXModule wxModule,
                                               @NonNull JSONArray args, @NonNull Invoker invoker) throws Exception{
  if(!instance.isPreRenderMode()) {
    return instance.getNativeInvokeHelper().invoke(wxModule,invoker,args);
  }
  // we are in preRender mode
  if(invoker.isRunOnUIThread()) {/*ASYNC CALL*/
    DOMAction moduleInvocationAction = Actions.getModuleInvocationAction(wxModule,args,invoker);
    WXSDKManager.getInstance().getWXDomManager().postAction(instance.getInstanceId(), moduleInvocationAction,false);
    return null;
  } else {/*SYNC CALL*/
    return instance.getNativeInvokeHelper().invoke(wxModule,invoker,args);
  }
}
 
Example #20
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onRequestPermissionsResult(String instanceId ,int requestCode, String[] permissions, int[] grantResults) {
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onRequestPermissionsResult(requestCode, permissions, grantResults);
      } else {
        WXLogUtils.w("onActivityResult can not find the " + key + " module");
      }
    }
  }
}
 
Example #21
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static boolean onCreateOptionsMenu(String instanceId,Menu menu) {
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onCreateOptionsMenu(menu);
      } else {
        WXLogUtils.w("onActivityResult can not find the " + key + " module");
      }
    }
  }
  return false;
}
 
Example #22
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onActivityResult(String instanceId,int requestCode, int resultCode, Intent data){

    Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
    if(modules!=null) {
      for (String key : modules.keySet()) {
        WXModule module = modules.get(key);
        if (module != null) {
          module.onActivityResult(requestCode, resultCode, data);
        } else {
          WXLogUtils.w("onActivityResult can not find the " + key + " module");
        }
      }
    }
  }
 
Example #23
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static boolean onActivityBack(String instanceId){
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        return module.onActivityBack();
      } else {
        WXLogUtils.w("onActivityCreate can not find the " + key + " module");
      }
    }
  }
  return false;
}
 
Example #24
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onActivityDestroy(String instanceId){
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityDestroy();
      } else {
        WXLogUtils.w("onActivityDestroy can not find the " + key + " module");
      }
    }
  }
}
 
Example #25
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onActivityStop(String instanceId){
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityStop();
      } else {
        WXLogUtils.w("onActivityStop can not find the " + key + " module");
      }
    }
  }
}
 
Example #26
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onActivityResume(String instanceId){
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityResume();
      } else {
        WXLogUtils.w("onActivityResume can not find the " + key + " module");
      }
    }
  }
}
 
Example #27
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onActivityPause(String instanceId){
  Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
  if(modules!=null) {
    for (String key : modules.keySet()) {
      WXModule module = modules.get(key);
      if (module != null) {
        module.onActivityPause();
      } else {
        WXLogUtils.w("onActivityPause can not find the " + key + " module");
      }
    }
  }
}
 
Example #28
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onActivityStart(String instanceId){

    Map<String, WXModule> modules = sInstanceModuleMap.get(instanceId);
    if(modules!=null) {
      for (String key : modules.keySet()) {
        WXModule module = modules.get(key);
        if (module != null) {
          module.onActivityStart();
        } else {
          WXLogUtils.w("onActivityStart can not find the " + key + " module");
        }
      }
    }
  }
 
Example #29
Source File: WXModuleManager.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private static WXModule findModule(String instanceId, String moduleStr,ModuleFactory factory) {
  // find WXModule
  WXModule wxModule = sGlobalModuleMap.get(moduleStr);

  //not global module
  if (wxModule == null) {
    Map<String, WXModule> moduleMap = sInstanceModuleMap.get(instanceId);
    if (moduleMap == null) {
      moduleMap = new ConcurrentHashMap<>();
      sInstanceModuleMap.put(instanceId, moduleMap);
    }
    // if cannot find the Module, create a new Module and save it
    wxModule = moduleMap.get(moduleStr);
    if (wxModule == null) {
      try {
        wxModule = factory.buildInstance();
        wxModule.setModuleName(moduleStr);
      } catch (Exception e) {
        WXLogUtils.e(moduleStr + " module build instace failed.", e);
        return null;
      }
      moduleMap.put(moduleStr, wxModule);
    }
  }

  return wxModule;
}
 
Example #30
Source File: WXSDKEngine.java    From weex-uikit with MIT License 4 votes vote down vote up
public static boolean registerModule(String moduleName, Class<? extends WXModule> moduleClass) throws WXException {
  return registerModule(moduleName, moduleClass,false);
}