From f2fc57bbc7bf9c191da34b39b46ef8119f0b438e Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 18 Jul 2019 16:28:50 +0800 Subject: [PATCH] Android hego project --- .../pengfeizhou/hegodemo/MyApplication.java | 11 ++++ .../com/github/pengfeizhou/hego/Hego.java | 9 +++ .../github/pengfeizhou/hego/HegoConstant.java | 9 +++ .../github/pengfeizhou/hego/HegoContext.java | 9 +++ .../github/pengfeizhou/hego/HegoDriver.java | 9 +++ .../github/pengfeizhou/hego/HegoJSEngine.java | 9 +++ .../com/github/pengfeizhou/hego/HegoLog.java | 9 +++ .../pengfeizhou/hego/HegoSettableFuture.java | 9 +++ .../github/pengfeizhou/hego/HegoUtils.java | 9 +++ .../pengfeizhou/hego/jse/HegoJSExecutor.java | 51 +++++++++++++++ .../github/pengfeizhou/hego/jse/IHegoJSE.java | 64 +++++++++++++++++++ 11 files changed, 198 insertions(+) create mode 100644 Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoConstant.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoJSEngine.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoLog.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoSettableFuture.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoUtils.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/HegoJSExecutor.java create mode 100644 Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/IHegoJSE.java diff --git a/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java b/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java new file mode 100644 index 00000000..16052e2d --- /dev/null +++ b/Android/app/src/main/java/com/github/pengfeizhou/hegodemo/MyApplication.java @@ -0,0 +1,11 @@ +package com.github.pengfeizhou.hegodemo; + +import android.app.Application; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class MyApplication extends Application { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java new file mode 100644 index 00000000..b04cfabb --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/Hego.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class Hego { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoConstant.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoConstant.java new file mode 100644 index 00000000..491c331e --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoConstant.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HegoConstant { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java new file mode 100644 index 00000000..4dc4bbe8 --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoContext.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HegoHolder { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java new file mode 100644 index 00000000..17407d6a --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoDriver.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public interface HegoDriver { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoJSEngine.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoJSEngine.java new file mode 100644 index 00000000..03cbfdc5 --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoJSEngine.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HegoJSEngine { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoLog.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoLog.java new file mode 100644 index 00000000..22e44258 --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoLog.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HegoLog { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoSettableFuture.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoSettableFuture.java new file mode 100644 index 00000000..0f86c84c --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoSettableFuture.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HegoSettableFuture { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoUtils.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoUtils.java new file mode 100644 index 00000000..88ddbf98 --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/HegoUtils.java @@ -0,0 +1,9 @@ +package com.github.pengfeizhou.hego; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HegoUtils { +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/HegoJSExecutor.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/HegoJSExecutor.java new file mode 100644 index 00000000..d402cce2 --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/HegoJSExecutor.java @@ -0,0 +1,51 @@ +package com.github.pengfeizhou.hego.jse; + +import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSExecutor; +import com.github.pengfeizhou.jscore.JSRuntimeException; +import com.github.pengfeizhou.jscore.JavaFunction; +import com.github.pengfeizhou.jscore.JavaValue; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public class HugoJSExecutor implements IHugoJSE { + + private final JSExecutor mJSExecutor; + + public HugoJSExecutor() { + this.mJSExecutor = JSExecutor.create(); + } + + @Override + public String loadJS(String script, String source) throws JSRuntimeException { + return mJSExecutor.loadJS(script, source); + } + + @Override + public JSDecoder evaluateJS(String script, String source, boolean hashKey) throws JSRuntimeException { + return mJSExecutor.evaluateJS(script, source, hashKey); + } + + @Override + public void injectGlobalJSFunction(String name, JavaFunction javaFunction) { + mJSExecutor.injectGlobalJSFunction(name, javaFunction); + } + + @Override + public void injectGlobalJSObject(String name, JavaValue javaValue) { + mJSExecutor.injectGlobalJSObject(name, javaValue); + } + + @Override + public JSDecoder invokeMethod(String objectName, String functionName, JavaValue[] javaValues, boolean hashKey) throws JSRuntimeException { + return mJSExecutor.invokeMethod(objectName, functionName, javaValues, hashKey); + } + + @Override + public void teardown() { + mJSExecutor.destroy(); + } +} diff --git a/Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/IHegoJSE.java b/Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/IHegoJSE.java new file mode 100644 index 00000000..c218790d --- /dev/null +++ b/Android/hego/src/main/java/com/github/pengfeizhou/hego/jse/IHegoJSE.java @@ -0,0 +1,64 @@ +package com.github.pengfeizhou.hego.jse; + +import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSRuntimeException; +import com.github.pengfeizhou.jscore.JavaFunction; +import com.github.pengfeizhou.jscore.JavaValue; + +/** + * @Description: Android + * @Author: pengfei.zhou + * @CreateDate: 2019-07-18 + */ +public interface IHugoJSE { + /** + * 执行JS语句 + * + * @param script 执行的JS语句 + * @param source 该JS语句对应的文件名,在输出错误的堆栈信息时有用 + * @return 返回JS语句的执行结果,以String形式返回 + * @throws JSRuntimeException 如果执行的脚本有异常,会抛出包含堆栈的JSRuntimeException + */ + String loadJS(String script, String source) throws JSRuntimeException; + + /** + * 执行JS语句 + * + * @param script 执行的JS语句 + * @param source 该JS语句对应的文件名,在输出错误的堆栈信息时有用 + * @param hashKey 是否在返回对象序列化时将key hash化 + * @return 返回JS语句的执行结果,以二进制数据的形式返回 + * @throws JSRuntimeException 如果执行的脚本有异常,会抛出包含堆栈的JSRuntimeException + */ + JSDecoder evaluateJS(String script, String source, boolean hashKey) throws JSRuntimeException; + + + /** + * 向JS注入全局方法,由java实现 + * + * @param name js的方法名 + * @param javaFunction java中对应的实现类 + */ + void injectGlobalJSFunction(String name, JavaFunction javaFunction); + + /** + * 向JS注入全局变量 + * + * @param name js中的变量名 + * @param javaValue 注入的全局变量,按Value进行组装 + */ + void injectGlobalJSObject(String name, JavaValue javaValue); + + /** + * 执行JS某个方法 + * + * @param objectName 执行的方法所属的变量名,如果方法为全局方法,该参数传null + * @param functionName 执行的方法名 + * @param javaValues 方法需要的参数列表,按数组传入 + * @param hashKey 是否在返回对象序列化时将key hash化 + * @throws JSRuntimeException 如果执行的方法有异常,会抛出包含堆栈的JSRuntimeException + */ + JSDecoder invokeMethod(String objectName, String functionName, JavaValue[] javaValues, boolean hashKey) throws JSRuntimeException; + + void teardown(); +}