Android hego project

This commit is contained in:
pengfei.zhou 2019-07-18 16:28:50 +08:00
parent 36c5029935
commit f2fc57bbc7
11 changed files with 198 additions and 0 deletions

View File

@ -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 {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class Hego {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoConstant {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoHolder {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public interface HegoDriver {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoJSEngine {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoLog {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoSettableFuture {
}

View File

@ -0,0 +1,9 @@
package com.github.pengfeizhou.hego;
/**
* @Description: Android
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoUtils {
}

View File

@ -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();
}
}

View File

@ -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();
}