From 920053c0f5f782acd57a4db94c9d2c761b598fe2 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 20 Jul 2019 14:29:44 +0800 Subject: [PATCH] prepare viewnode --- .../github/penfeizhou/doric/DoricContext.java | 10 ++++---- .../penfeizhou/doric/DoricRegistry.java | 25 ++++++++++++++----- .../bridge/DoricBridgeExtension.java | 8 ++---- .../doric/extension/bridge/DoricPlugin.java | 2 +- .../doric/plugin/DoricJavaPlugin.java | 11 +++----- .../penfeizhou/doric/render/DoricNode.java | 19 ++++++++++++++ .../penfeizhou/doric/render/IShader.java | 14 +++++++++++ .../penfeizhou/doric/render/ViewNode.java | 15 +++++++++++ .../doric/utils/DoricComponent.java | 20 +++++++++++++++ .../DoricMetaInfo.java} | 14 +++++------ .../penfeizhou/doric/widget/ImageNode.java | 17 +++++++++++++ .../penfeizhou/doric/widget/TextNode.java | 17 +++++++++++++ 12 files changed, 139 insertions(+), 33 deletions(-) create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/render/DoricNode.java create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/render/IShader.java create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/render/ViewNode.java create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricComponent.java rename Android/doric/src/main/java/com/github/penfeizhou/doric/{extension/bridge/DoricPluginInfo.java => utils/DoricMetaInfo.java} (80%) create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java create mode 100644 Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java index 52d9b9d8..2927885f 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricContext.java @@ -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 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; } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java index f4337499..9d33ca7b 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/DoricRegistry.java @@ -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 bundles = new ConcurrentHashMap<>(); - private Map pluginInfoMap = new HashMap<>(); + private Map> pluginInfoMap = new HashMap<>(); + private Map> nodeInfoMap = new HashMap<>(); private static Set doricLibraries = new HashSet<>(); private static void initRegistry(DoricRegistry doricRegistry) { @@ -43,16 +45,27 @@ public class DoricRegistry { } public void registerNativePlugin(Class pluginClass) { - DoricPluginInfo doricPluginInfo = new DoricPluginInfo(pluginClass); - if (!TextUtils.isEmpty(doricPluginInfo.getName())) { - pluginInfoMap.put(doricPluginInfo.getName(), doricPluginInfo); + DoricMetaInfo doricMetaInfo = new DoricMetaInfo<>(pluginClass); + if (!TextUtils.isEmpty(doricMetaInfo.getName())) { + pluginInfoMap.put(doricMetaInfo.getName(), doricMetaInfo); } } - public DoricPluginInfo acquirePluginInfo(String name) { + public DoricMetaInfo acquirePluginInfo(String name) { return pluginInfoMap.get(name); } + public void registerViewNode(Class pluginClass) { + DoricMetaInfo doricMetaInfo = new DoricMetaInfo<>(pluginClass); + if (!TextUtils.isEmpty(doricMetaInfo.getName())) { + nodeInfoMap.put(doricMetaInfo.getName(), doricMetaInfo); + } + } + + public DoricMetaInfo acquireViewNodeInfo(String name) { + return nodeInfoMap.get(name); + } + public String acquireJSBundle(String name) { return bundles.get(name); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricBridgeExtension.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricBridgeExtension.java index d3a84f72..b8bea144 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricBridgeExtension.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricBridgeExtension.java @@ -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 pluginInfo = mRegistry.acquirePluginInfo(module); if (pluginInfo == null) { DoricLog.e("Cannot find plugin class:%s", module); return new JavaValue(false); diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPlugin.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPlugin.java index 037ac69d..93dc363b 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPlugin.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPlugin.java @@ -15,5 +15,5 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface DoricPlugin { - String name() default ""; + String name(); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/DoricJavaPlugin.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/DoricJavaPlugin.java index d4b2e6b6..d95ddd2a 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/DoricJavaPlugin.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/plugin/DoricJavaPlugin.java @@ -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); } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/render/DoricNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/render/DoricNode.java new file mode 100644 index 00000000..aead141a --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/render/DoricNode.java @@ -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(); +} \ No newline at end of file diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/render/IShader.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/render/IShader.java new file mode 100644 index 00000000..5bde34c6 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/render/IShader.java @@ -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); +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/render/ViewNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/render/ViewNode.java new file mode 100644 index 00000000..b18f901d --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/render/ViewNode.java @@ -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); + } +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricComponent.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricComponent.java new file mode 100644 index 00000000..a2fcaaa3 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricComponent.java @@ -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; + } +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPluginInfo.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricMetaInfo.java similarity index 80% rename from Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPluginInfo.java rename to Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricMetaInfo.java index 3ec0101a..84db2e68 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/extension/bridge/DoricPluginInfo.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricMetaInfo.java @@ -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 { - private Constructor pluginConstructor; + private Constructor pluginConstructor; private Map methodMap = new ConcurrentHashMap<>(); private String name; - public DoricPluginInfo(Class pluginClass) { + public DoricMetaInfo(Class 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) { diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java new file mode 100644 index 00000000..321f878f --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ImageNode.java @@ -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); + } +} diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java new file mode 100644 index 00000000..485cb161 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/TextNode.java @@ -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); + } +}