stash changed
This commit is contained in:
parent
d8cf7bee4d
commit
6bcc9ffe49
@ -0,0 +1,18 @@
|
||||
package com.github.pengfeizhou.hego.bridge;
|
||||
|
||||
import com.github.pengfeizhou.hego.HegoContext;
|
||||
|
||||
/**
|
||||
* @Description: Android
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public abstract class BaseModule {
|
||||
private final HegoContext hegoContext;
|
||||
|
||||
protected BaseModule(HegoContext hegoContext) {
|
||||
this.hegoContext = hegoContext;
|
||||
}
|
||||
|
||||
public abstract String moduleName();
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.github.pengfeizhou.hego.bridge;
|
||||
|
||||
import com.github.pengfeizhou.hego.HegoContext;
|
||||
import com.github.pengfeizhou.hego.extension.HegoMethod;
|
||||
|
||||
/**
|
||||
* @Description: Hego
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class ModalModule extends BaseModule {
|
||||
|
||||
protected ModalModule(HegoContext hegoContext) {
|
||||
super(hegoContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String moduleName() {
|
||||
return "modal";
|
||||
}
|
||||
|
||||
@HegoMethod(name = "toast")
|
||||
public void toast() {
|
||||
|
||||
}
|
||||
}
|
@ -7,12 +7,12 @@ import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.pengfeizhou.hego.Hego;
|
||||
import com.github.pengfeizhou.hego.extension.HegoBridgeExtension;
|
||||
import com.github.pengfeizhou.hego.utils.HegoConstant;
|
||||
import com.github.pengfeizhou.hego.utils.HegoLog;
|
||||
import com.github.pengfeizhou.hego.utils.HegoSettableFuture;
|
||||
import com.github.pengfeizhou.hego.utils.HegoTimerExtension;
|
||||
import com.github.pengfeizhou.hego.extension.HegoTimerExtension;
|
||||
import com.github.pengfeizhou.hego.utils.HegoUtils;
|
||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JavaFunction;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerCallback {
|
||||
private final Handler mJSHandler;
|
||||
private final HegoBridgeExtension mHegoBridgeExtensio;
|
||||
private IHegoJSE mHegoJSE;
|
||||
private HegoTimerExtension mTimerExtension;
|
||||
|
||||
@ -44,6 +45,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
|
||||
}
|
||||
});
|
||||
mTimerExtension = new HegoTimerExtension(looper, this);
|
||||
mHegoBridgeExtensio = new HegoBridgeExtension();
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +117,22 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
|
||||
return null;
|
||||
}
|
||||
});
|
||||
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_BRIDGE, new JavaFunction() {
|
||||
@Override
|
||||
public JavaValue exec(JSDecoder[] args) {
|
||||
try {
|
||||
String contextId = args[0].string();
|
||||
String module = args[1].string();
|
||||
String method = args[2].string();
|
||||
String callbackId = args[3].string();
|
||||
JSDecoder jsDecoder = args[4];
|
||||
return mHegoBridgeExtensio.callNative(contextId, module, method, callbackId, jsDecoder);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initHugoRuntime() {
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.github.pengfeizhou.hego.extension;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
/**
|
||||
* @Description: Android
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class HegoBridgeExtension {
|
||||
public HegoBridgeExtension() {
|
||||
|
||||
}
|
||||
|
||||
public JavaValue callNative(String contextId, String module, String method, String callbackId, JSDecoder jsDecoder) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.github.pengfeizhou.hego.extension;
|
||||
|
||||
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: Android
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface HegoMethod {
|
||||
String name() default "";
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.github.pengfeizhou.hego.extension;
|
||||
|
||||
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: Hego
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface HegoModule {
|
||||
String name() default "";
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.github.pengfeizhou.hego.utils;
|
||||
package com.github.pengfeizhou.hego.extension;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
@ -0,0 +1,48 @@
|
||||
package com.github.pengfeizhou.hego.extension;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: Android
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class ModuleClassInfo {
|
||||
|
||||
private Class clz;
|
||||
|
||||
private Object instance;
|
||||
|
||||
private Map<String, Method> methodMap = new HashMap<>();
|
||||
public boolean stringify = false;
|
||||
|
||||
public ModuleClassInfo(Class clz) {
|
||||
this.clz = clz;
|
||||
try {
|
||||
this.instance = clz.newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Method[] methods = clz.getMethods();
|
||||
if (methods != null) {
|
||||
for (Method method : methods) {
|
||||
HegoMethod hegoMethod = method.getAnnotation(HegoMethod.class);
|
||||
if (hegoMethod != null) {
|
||||
if (TextUtils.isEmpty(hegoMethod.name())) {
|
||||
methodMap.put(method.getName(), method);
|
||||
} else {
|
||||
methodMap.put(hegoMethod.name(), method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ import { loge } from "../util/log";
|
||||
|
||||
declare function nativeRequire(moduleName: string): boolean
|
||||
|
||||
declare function nativeBridge(contextId: string, namespace: string, method: string, args?: any, callbackId?: string): boolean
|
||||
declare function nativeBridge(contextId: string, namespace: string, method: string, callbackId?: string, args?: any): boolean
|
||||
|
||||
export function jsCallResolve(contextId: string, callbackId: string, args?: any) {
|
||||
const context = gContexts.get(contextId)
|
||||
@ -77,7 +77,7 @@ export class Context {
|
||||
callNative(namespace: string, method: string, args?: any): Promise<any> {
|
||||
const callbackId = uniqueId('callback')
|
||||
|
||||
nativeBridge(this.id, namespace, method, args, callbackId)
|
||||
nativeBridge(this.id, namespace, method, callbackId, args)
|
||||
return new Promise((resolve, reject) => {
|
||||
this.callbacks.set(callbackId, {
|
||||
resolve,
|
||||
|
Reference in New Issue
Block a user