prepare viewnode
This commit is contained in:
parent
ef5bb17380
commit
920053c0f5
@ -4,7 +4,7 @@ import android.content.Context;
|
||||
|
||||
import com.github.penfeizhou.doric.async.AsyncResult;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPluginInfo;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -64,11 +64,11 @@ public class DoricContext {
|
||||
});
|
||||
}
|
||||
|
||||
public DoricJavaPlugin obtainPlugin(DoricPluginInfo doricPluginInfo) {
|
||||
DoricJavaPlugin plugin = mPluginMap.get(doricPluginInfo.getName());
|
||||
public DoricJavaPlugin obtainPlugin(DoricMetaInfo<DoricJavaPlugin> doricMetaInfo) {
|
||||
DoricJavaPlugin plugin = mPluginMap.get(doricMetaInfo.getName());
|
||||
if (plugin == null) {
|
||||
plugin = doricPluginInfo.createPlugin(this);
|
||||
mPluginMap.put(doricPluginInfo.getName(), plugin);
|
||||
plugin = doricMetaInfo.createInstance(this);
|
||||
mPluginMap.put(doricMetaInfo.getName(), plugin);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ package com.github.penfeizhou.doric;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPluginInfo;
|
||||
import com.github.penfeizhou.doric.render.ViewNode;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
import com.github.penfeizhou.doric.plugin.ModalPlugin;
|
||||
|
||||
@ -19,7 +20,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class DoricRegistry {
|
||||
private static Map<String, String> bundles = new ConcurrentHashMap<>();
|
||||
private Map<String, DoricPluginInfo> pluginInfoMap = new HashMap<>();
|
||||
private Map<String, DoricMetaInfo<DoricJavaPlugin>> pluginInfoMap = new HashMap<>();
|
||||
private Map<String, DoricMetaInfo<ViewNode>> nodeInfoMap = new HashMap<>();
|
||||
private static Set<DoricLibrary> doricLibraries = new HashSet<>();
|
||||
|
||||
private static void initRegistry(DoricRegistry doricRegistry) {
|
||||
@ -43,16 +45,27 @@ public class DoricRegistry {
|
||||
}
|
||||
|
||||
public void registerNativePlugin(Class<? extends DoricJavaPlugin> pluginClass) {
|
||||
DoricPluginInfo doricPluginInfo = new DoricPluginInfo(pluginClass);
|
||||
if (!TextUtils.isEmpty(doricPluginInfo.getName())) {
|
||||
pluginInfoMap.put(doricPluginInfo.getName(), doricPluginInfo);
|
||||
DoricMetaInfo<DoricJavaPlugin> doricMetaInfo = new DoricMetaInfo<>(pluginClass);
|
||||
if (!TextUtils.isEmpty(doricMetaInfo.getName())) {
|
||||
pluginInfoMap.put(doricMetaInfo.getName(), doricMetaInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public DoricPluginInfo acquirePluginInfo(String name) {
|
||||
public DoricMetaInfo<DoricJavaPlugin> acquirePluginInfo(String name) {
|
||||
return pluginInfoMap.get(name);
|
||||
}
|
||||
|
||||
public void registerViewNode(Class<? extends ViewNode> pluginClass) {
|
||||
DoricMetaInfo<ViewNode> doricMetaInfo = new DoricMetaInfo<>(pluginClass);
|
||||
if (!TextUtils.isEmpty(doricMetaInfo.getName())) {
|
||||
nodeInfoMap.put(doricMetaInfo.getName(), doricMetaInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public DoricMetaInfo<ViewNode> acquireViewNodeInfo(String name) {
|
||||
return nodeInfoMap.get(name);
|
||||
}
|
||||
|
||||
public String acquireJSBundle(String name) {
|
||||
return bundles.get(name);
|
||||
}
|
||||
|
@ -1,21 +1,17 @@
|
||||
package com.github.penfeizhou.doric.extension.bridge;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.DoricRegistry;
|
||||
import com.github.penfeizhou.doric.async.AsyncResult;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
import com.github.penfeizhou.doric.plugin.ModalPlugin;
|
||||
import com.github.penfeizhou.doric.DoricContextManager;
|
||||
import com.github.penfeizhou.doric.utils.DoricLog;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.penfeizhou.doric.utils.DoricUtils;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
@ -33,7 +29,7 @@ public class DoricBridgeExtension {
|
||||
|
||||
public JavaValue callNative(String contextId, String module, String methodName, final String callbackId, final JSDecoder jsDecoder) {
|
||||
final DoricContext context = DoricContextManager.getContext(contextId);
|
||||
DoricPluginInfo pluginInfo = mRegistry.acquirePluginInfo(module);
|
||||
DoricMetaInfo<DoricJavaPlugin> pluginInfo = mRegistry.acquirePluginInfo(module);
|
||||
if (pluginInfo == null) {
|
||||
DoricLog.e("Cannot find plugin class:%s", module);
|
||||
return new JavaValue(false);
|
||||
|
@ -15,5 +15,5 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DoricPlugin {
|
||||
String name() default "";
|
||||
String name();
|
||||
}
|
||||
|
@ -1,20 +1,15 @@
|
||||
package com.github.penfeizhou.doric.plugin;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.utils.DoricComponent;
|
||||
|
||||
/**
|
||||
* @Description: Doric
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public abstract class DoricJavaPlugin {
|
||||
private final DoricContext doricContext;
|
||||
|
||||
public abstract class DoricJavaPlugin extends DoricComponent {
|
||||
public DoricJavaPlugin(DoricContext doricContext) {
|
||||
this.doricContext = doricContext;
|
||||
}
|
||||
|
||||
public DoricContext getDoricContext() {
|
||||
return doricContext;
|
||||
super(doricContext);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.github.penfeizhou.doric.render;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.render
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DoricNode {
|
||||
String name();
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.github.penfeizhou.doric.render;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.render
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
public interface IShader {
|
||||
ViewNode create(String type);
|
||||
|
||||
boolean blend(ViewNode node, String propertyName, JSValue property);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.github.penfeizhou.doric.render;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.utils.DoricComponent;
|
||||
|
||||
/**
|
||||
* @Description: Render
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
public abstract class ViewNode extends DoricComponent {
|
||||
public ViewNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.github.penfeizhou.doric.utils;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.utils
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
public abstract class DoricComponent {
|
||||
private final DoricContext doricContext;
|
||||
|
||||
public DoricComponent(DoricContext doricContext) {
|
||||
this.doricContext = doricContext;
|
||||
}
|
||||
|
||||
public DoricContext getDoricContext() {
|
||||
return doricContext;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.github.penfeizhou.doric.extension.bridge;
|
||||
package com.github.penfeizhou.doric.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
import com.github.penfeizhou.doric.utils.DoricLog;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricMethod;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
@ -16,14 +16,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class DoricPluginInfo {
|
||||
public class DoricMetaInfo<T extends DoricComponent> {
|
||||
|
||||
private Constructor<? extends DoricJavaPlugin> pluginConstructor;
|
||||
private Constructor<? extends T> pluginConstructor;
|
||||
|
||||
private Map<String, Method> methodMap = new ConcurrentHashMap<>();
|
||||
private String name;
|
||||
|
||||
public DoricPluginInfo(Class<? extends DoricJavaPlugin> pluginClass) {
|
||||
public DoricMetaInfo(Class<? extends T> pluginClass) {
|
||||
try {
|
||||
this.pluginConstructor = pluginClass.getDeclaredConstructor(DoricContext.class);
|
||||
DoricPlugin doricPlugin = pluginClass.getAnnotation(DoricPlugin.class);
|
||||
@ -48,7 +48,7 @@ public class DoricPluginInfo {
|
||||
return name;
|
||||
}
|
||||
|
||||
public DoricJavaPlugin createPlugin(DoricContext doricContext) {
|
||||
public T createInstance(DoricContext doricContext) {
|
||||
try {
|
||||
return pluginConstructor.newInstance(doricContext);
|
||||
} catch (Exception e) {
|
@ -0,0 +1,17 @@
|
||||
package com.github.penfeizhou.doric.widget;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.render.DoricNode;
|
||||
import com.github.penfeizhou.doric.render.ViewNode;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.widget
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
@DoricNode(name = "Image")
|
||||
public class ImageNode extends ViewNode {
|
||||
public ImageNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.github.penfeizhou.doric.widget;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.render.DoricNode;
|
||||
import com.github.penfeizhou.doric.render.ViewNode;
|
||||
|
||||
/**
|
||||
* @Description: widget
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-20
|
||||
*/
|
||||
@DoricNode(name = "Text")
|
||||
public class TextNode extends ViewNode {
|
||||
public TextNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user