doric plugin
This commit is contained in:
parent
51c8924c2a
commit
ac8d111f7b
@ -20,7 +20,7 @@ public class DoricContext {
|
||||
|
||||
public static DoricContext createContext(String script, String alias) {
|
||||
String contextId = String.valueOf(sCounter.incrementAndGet());
|
||||
DoricDriver.getInstance().createPage(contextId, script, alias);
|
||||
DoricDriver.getInstance().createContext(contextId, script, alias);
|
||||
return new DoricContext(contextId);
|
||||
}
|
||||
|
||||
@ -29,6 +29,6 @@ public class DoricContext {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
DoricDriver.getInstance().destoryContext(mContextId);
|
||||
DoricDriver.getInstance().destroyContext(mContextId);
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ public class DoricDriver {
|
||||
return Inner.sInstance;
|
||||
}
|
||||
|
||||
public void createPage(final String contextId, final String script, final String source) {
|
||||
public void createContext(final String contextId, final String script, final String source) {
|
||||
doricJSEngine.prepareContext(contextId, script, source);
|
||||
}
|
||||
|
||||
public void destoryContext(String contextId) {
|
||||
public void destroyContext(String contextId) {
|
||||
doricJSEngine.destroyContext(contextId);
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,14 @@ import com.github.pengfeizhou.doric.DoricContext;
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public abstract class BaseModule {
|
||||
public abstract class DoricNativePlugin {
|
||||
private final DoricContext doricContext;
|
||||
|
||||
protected BaseModule(DoricContext doricContext) {
|
||||
protected DoricNativePlugin(DoricContext doricContext) {
|
||||
this.doricContext = doricContext;
|
||||
}
|
||||
|
||||
public abstract String moduleName();
|
||||
public DoricContext getDoricContext() {
|
||||
return doricContext;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.github.pengfeizhou.doric.bridge;
|
||||
|
||||
import com.github.pengfeizhou.doric.DoricContext;
|
||||
import com.github.pengfeizhou.doric.extension.DoricComponent;
|
||||
import com.github.pengfeizhou.doric.extension.DoricMethod;
|
||||
|
||||
/**
|
||||
@ -8,17 +9,13 @@ import com.github.pengfeizhou.doric.extension.DoricMethod;
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class ModalModule extends BaseModule {
|
||||
@DoricComponent(name = "modal")
|
||||
public class ModalPlugin extends DoricNativePlugin {
|
||||
|
||||
protected ModalModule(DoricContext doricContext) {
|
||||
protected ModalPlugin(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String moduleName() {
|
||||
return "modal";
|
||||
}
|
||||
|
||||
@DoricMethod(name = "toast")
|
||||
public void toast() {
|
||||
|
@ -17,8 +17,6 @@ import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JavaFunction;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -214,25 +212,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
public void run() {
|
||||
ArrayList<JavaValue> values = new ArrayList<>();
|
||||
for (Object arg : args) {
|
||||
if (arg == null) {
|
||||
values.add(new JavaValue());
|
||||
} else if (arg instanceof JSONObject) {
|
||||
values.add(new JavaValue((JSONObject) arg));
|
||||
} else if (arg instanceof String) {
|
||||
values.add(new JavaValue((String) arg));
|
||||
} else if (arg instanceof Integer) {
|
||||
values.add(new JavaValue((Integer) arg));
|
||||
} else if (arg instanceof Long) {
|
||||
values.add(new JavaValue((Long) arg));
|
||||
} else if (arg instanceof Double) {
|
||||
values.add(new JavaValue((Double) arg));
|
||||
} else if (arg instanceof Boolean) {
|
||||
values.add(new JavaValue((Boolean) arg));
|
||||
} else if (arg instanceof JavaValue) {
|
||||
values.add((JavaValue) arg);
|
||||
} else {
|
||||
values.add(new JavaValue(String.valueOf(arg)));
|
||||
}
|
||||
values.add(DoricUtils.toJavaValue(arg));
|
||||
}
|
||||
settableFuture.set(mDoricJSE.invokeMethod(DoricConstant.GLOBAL_DORIC, method,
|
||||
values.toArray(new JavaValue[values.size()]), true));
|
||||
|
@ -14,6 +14,6 @@ import java.lang.annotation.Target;
|
||||
@Documented
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DoricModule {
|
||||
public @interface DoricComponent {
|
||||
String name() default "";
|
||||
}
|
@ -3,6 +3,9 @@ package com.github.pengfeizhou.doric.utils;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.github.pengfeizhou.doric.Doric;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -35,4 +38,26 @@ public class DoricUtils {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static JavaValue toJavaValue(Object arg) {
|
||||
if (arg == null) {
|
||||
return new JavaValue();
|
||||
} else if (arg instanceof JSONObject) {
|
||||
return new JavaValue((JSONObject) arg);
|
||||
} else if (arg instanceof String) {
|
||||
return new JavaValue((String) arg);
|
||||
} else if (arg instanceof Integer) {
|
||||
return new JavaValue((Integer) arg);
|
||||
} else if (arg instanceof Long) {
|
||||
return new JavaValue((Long) arg);
|
||||
} else if (arg instanceof Double) {
|
||||
return new JavaValue((Double) arg);
|
||||
} else if (arg instanceof Boolean) {
|
||||
return new JavaValue((Boolean) arg);
|
||||
} else if (arg instanceof JavaValue) {
|
||||
return (JavaValue) arg;
|
||||
} else {
|
||||
return new JavaValue(String.valueOf(arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user