rename hego to doric

This commit is contained in:
pengfei.zhou 2019-07-19 10:27:09 +08:00
parent 6bcc9ffe49
commit 51c8924c2a
48 changed files with 340 additions and 424 deletions

7
Android/.gitignore vendored
View File

@ -1,12 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/
.DS_Store
/build
/captures

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/hego" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>Android Lint</id>
</State>
</expanded-state>
</profile-state>
</entry>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.github.pengfeizhou.hego"
applicationId "com.github.pengfeizhou.doric"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
@ -27,5 +27,5 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':hego')
implementation project(':doric')
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.pengfeizhou.hegodemo">
package="com.github.pengfeizhou.doricdemo">
<application
android:name=".MyApplication"
@ -10,7 +10,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.github.pengfeizhou.hegodemo.MainActivity">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -1,10 +1,10 @@
package com.github.pengfeizhou.hegodemo;
package com.github.pengfeizhou.doricdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.github.pengfeizhou.hego.HegoContext;
import com.github.pengfeizhou.hego.utils.HegoUtils;
import com.github.pengfeizhou.doric.DoricContext;
import com.github.pengfeizhou.doric.utils.DoricUtils;
public class MainActivity extends AppCompatActivity {
@ -12,7 +12,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HegoContext hegoContext = HegoContext.createContext(HegoUtils.readAssetFile("demo.js"), "demo");
hegoContext.callEntity("log");
DoricContext doricContext = DoricContext.createContext(DoricUtils.readAssetFile("demo.js"), "demo");
doricContext.callEntity("log");
}
}

View File

@ -1,11 +1,11 @@
package com.github.pengfeizhou.hegodemo;
package com.github.pengfeizhou.doricdemo;
import android.app.Application;
import com.github.pengfeizhou.hego.Hego;
import com.github.pengfeizhou.doric.Doric;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
@ -13,6 +13,6 @@ public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Hego.init(this);
Doric.init(this);
}
}

View File

@ -1,3 +1,3 @@
<resources>
<string name="app_name">HEGO</string>
<string name="app_name">Doric</string>
</resources>

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego;
package com.github.pengfeizhou.doric.test;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.github.pengfeizhou.hego.test", appContext.getPackageName());
assertEquals("com.github.pengfeizhou.doric.test", appContext.getPackageName());
}
}

View File

@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.pengfeizhou.hego" />
package="com.github.pengfeizhou.doric" />

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego;
package com.github.pengfeizhou.doric;
import android.app.Application;
@ -6,11 +6,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class Hego {
public class Doric {
private static Application sApplication;
public static void init(Application application) {
@ -23,11 +23,11 @@ public class Hego {
private static Map<String, String> bundles = new ConcurrentHashMap<>();
public static void registerJSModuleContent(String name, String bundle) {
public static void registerJSBundle(String name, String bundle) {
bundles.put(name, bundle);
}
public static String getJSModuleContent(String name) {
public static String getJSBundle(String name) {
return bundles.get(name);
}
}

View File

@ -0,0 +1,34 @@
package com.github.pengfeizhou.doric;
import com.github.pengfeizhou.doric.utils.DoricSettableFuture;
import com.github.pengfeizhou.jscore.JSDecoder;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class DoricContext {
private static AtomicInteger sCounter = new AtomicInteger();
private final String mContextId;
private DoricContext(String contextId) {
this.mContextId = contextId;
}
public static DoricContext createContext(String script, String alias) {
String contextId = String.valueOf(sCounter.incrementAndGet());
DoricDriver.getInstance().createPage(contextId, script, alias);
return new DoricContext(contextId);
}
public DoricSettableFuture<JSDecoder> callEntity(String methodName, Object... args) {
return DoricDriver.getInstance().invokeContextMethod(mContextId, methodName, args);
}
public void teardown() {
DoricDriver.getInstance().destoryContext(mContextId);
}
}

View File

@ -0,0 +1,40 @@
package com.github.pengfeizhou.doric;
import com.github.pengfeizhou.doric.engine.DoricJSEngine;
import com.github.pengfeizhou.doric.utils.DoricSettableFuture;
import com.github.pengfeizhou.jscore.JSDecoder;
/**
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class DoricDriver {
private final DoricJSEngine doricJSEngine;
public DoricSettableFuture<JSDecoder> invokeContextMethod(final String contextId, final String method, final Object... args) {
return doricJSEngine.invokeContextEntityMethod(contextId, method, args);
}
private static class Inner {
private static final DoricDriver sInstance = new DoricDriver();
}
private DoricDriver() {
doricJSEngine = new DoricJSEngine();
}
public static DoricDriver getInstance() {
return Inner.sInstance;
}
public void createPage(final String contextId, final String script, final String source) {
doricJSEngine.prepareContext(contextId, script, source);
}
public void destoryContext(String contextId) {
doricJSEngine.destroyContext(contextId);
}
}

View File

@ -0,0 +1,54 @@
package com.github.pengfeizhou.doric;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class DoricPanel extends FrameLayout {
private DoricContext mDoricContext;
public DoricPanel(@NonNull Context context) {
super(context);
}
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public DoricPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void config(String script, String alias) {
DoricContext doricContext = DoricContext.createContext(script, alias);
config(doricContext);
}
public void config(DoricContext doricContext) {
mDoricContext = doricContext;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
public DoricContext getDoricContext() {
return mDoricContext;
}
}

View File

@ -0,0 +1,18 @@
package com.github.pengfeizhou.doric.bridge;
import com.github.pengfeizhou.doric.DoricContext;
/**
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public abstract class BaseModule {
private final DoricContext doricContext;
protected BaseModule(DoricContext doricContext) {
this.doricContext = doricContext;
}
public abstract String moduleName();
}

View File

@ -0,0 +1,26 @@
package com.github.pengfeizhou.doric.bridge;
import com.github.pengfeizhou.doric.DoricContext;
import com.github.pengfeizhou.doric.extension.DoricMethod;
/**
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class ModalModule extends BaseModule {
protected ModalModule(DoricContext doricContext) {
super(doricContext);
}
@Override
public String moduleName() {
return "modal";
}
@DoricMethod(name = "toast")
public void toast() {
}
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.engine;
package com.github.pengfeizhou.doric.engine;
import android.os.Handler;
import android.os.HandlerThread;
@ -6,13 +6,13 @@ import android.os.Looper;
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.extension.HegoTimerExtension;
import com.github.pengfeizhou.hego.utils.HegoUtils;
import com.github.pengfeizhou.doric.Doric;
import com.github.pengfeizhou.doric.extension.DoricBridgeExtension;
import com.github.pengfeizhou.doric.utils.DoricConstant;
import com.github.pengfeizhou.doric.utils.DoricLog;
import com.github.pengfeizhou.doric.utils.DoricSettableFuture;
import com.github.pengfeizhou.doric.extension.DoricTimerExtension;
import com.github.pengfeizhou.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue;
@ -22,17 +22,17 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerCallback {
public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.TimerCallback {
private final Handler mJSHandler;
private final HegoBridgeExtension mHegoBridgeExtensio;
private IHegoJSE mHegoJSE;
private HegoTimerExtension mTimerExtension;
private final DoricBridgeExtension mDoricBridgeExtension;
private IDoricJSE mDoricJSE;
private DoricTimerExtension mTimerExtension;
public HegoJSEngine() {
public DoricJSEngine() {
HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName());
handlerThread.start();
Looper looper = handlerThread.getLooper();
@ -44,14 +44,14 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
initHugoRuntime();
}
});
mTimerExtension = new HegoTimerExtension(looper, this);
mHegoBridgeExtensio = new HegoBridgeExtension();
mTimerExtension = new DoricTimerExtension(looper, this);
mDoricBridgeExtension = new DoricBridgeExtension();
}
private void initJSExecutor() {
mHegoJSE = new HegoJSExecutor();
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_LOG, new JavaFunction() {
mDoricJSE = new DoricJSExecutor();
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {
try {
@ -59,13 +59,13 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
String message = args[1].string();
switch (type) {
case "w":
HegoLog.w(message, "_js");
DoricLog.w(message, "_js");
break;
case "e":
HegoLog.e(message, "_js");
DoricLog.e(message, "_js");
break;
default:
HegoLog.d(message, "_js");
DoricLog.d(message, "_js");
break;
}
} catch (Exception e) {
@ -74,17 +74,17 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
return null;
}
});
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_REQUIRE, new JavaFunction() {
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_REQUIRE, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {
try {
String name = args[0].string();
String content = Hego.getJSModuleContent(name);
String content = Doric.getJSBundle(name);
if (TextUtils.isEmpty(content)) {
HegoLog.e("error");
DoricLog.e("error");
return new JavaValue(false);
}
mHegoJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
mDoricJSE.loadJS(packageModuleScript(name, content), "Module://" + name);
return new JavaValue(true);
} catch (Exception e) {
e.printStackTrace();
@ -92,7 +92,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
}
}
});
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_TIMER_SET, new JavaFunction() {
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_TIMER_SET, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {
try {
@ -106,7 +106,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
return null;
}
});
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_TIMER_CLEAR, new JavaFunction() {
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_TIMER_CLEAR, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {
try {
@ -117,7 +117,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
return null;
}
});
mHegoJSE.injectGlobalJSFunction(HegoConstant.INJECT_BRIDGE, new JavaFunction() {
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_BRIDGE, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {
try {
@ -126,7 +126,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
String method = args[2].string();
String callbackId = args[3].string();
JSDecoder jsDecoder = args[4];
return mHegoBridgeExtensio.callNative(contextId, module, method, callbackId, jsDecoder);
return mDoricBridgeExtension.callNative(contextId, module, method, callbackId, jsDecoder);
} catch (Exception e) {
e.printStackTrace();
}
@ -136,10 +136,10 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
}
private void initHugoRuntime() {
loadBuiltinJS("hego-sandbox.js");
String libName = "./index";
String libJS = HegoUtils.readAssetFile("hego-lib.js");
mHegoJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
loadBuiltinJS(DoricConstant.DORIC_BUNDLE_SANDBOX);
String libName = DoricConstant.DORIC_MODULE_LIB;
String libJS = DoricUtils.readAssetFile(DoricConstant.DORIC_BUNDLE_LIB);
mDoricJSE.loadJS(packageModuleScript(libName, libJS), "Module://" + libName);
}
@Override
@ -148,19 +148,19 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
}
public void teardown() {
mHegoJSE.teardown();
mDoricJSE.teardown();
}
private void loadBuiltinJS(String assetName) {
String script = HegoUtils.readAssetFile(assetName);
mHegoJSE.loadJS(script, "Assets://" + assetName);
String script = DoricUtils.readAssetFile(assetName);
mDoricJSE.loadJS(script, "Assets://" + assetName);
}
public void prepareContext(final String contextId, final String script, final String source) {
Runnable runnable = new Runnable() {
@Override
public void run() {
mHegoJSE.loadJS(packageContextScript(contextId, script), "Context://" + source);
mDoricJSE.loadJS(packageContextScript(contextId, script), "Context://" + source);
}
};
doOnJSThread(runnable);
@ -178,37 +178,37 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
Runnable runnable = new Runnable() {
@Override
public void run() {
mHegoJSE.loadJS(String.format(HegoConstant.TEMPLATE_CONTEXT_DESTORY, contextId), "_Context://" + contextId);
mDoricJSE.loadJS(String.format(DoricConstant.TEMPLATE_CONTEXT_DESTROY, contextId), "_Context://" + contextId);
}
};
doOnJSThread(runnable);
}
private String packageContextScript(String contextId, String content) {
return String.format(HegoConstant.TEMPLATE_CONTEXT_CREATE, content, contextId, contextId);
return String.format(DoricConstant.TEMPLATE_CONTEXT_CREATE, content, contextId, contextId);
}
private String packageModuleScript(String moduleName, String content) {
return String.format(HegoConstant.TEMPLATE_MODULE, moduleName, content);
return String.format(DoricConstant.TEMPLATE_MODULE, moduleName, content);
}
public boolean isJSThread() {
return Looper.myLooper() == mJSHandler.getLooper();
}
public HegoSettableFuture<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) {
public DoricSettableFuture<JSDecoder> invokeContextEntityMethod(final String contextId, final String method, final Object... args) {
final Object[] nArgs = new Object[args.length + 2];
nArgs[0] = contextId;
nArgs[1] = method;
if (args.length > 0) {
System.arraycopy(args, 0, nArgs, 2, args.length);
}
return invokeHegoMethod(HegoConstant.HEGO_CONTEXT_INVOKE, nArgs);
return invokeDoricMethod(DoricConstant.DORIC_CONTEXT_INVOKE, nArgs);
}
public HegoSettableFuture<JSDecoder> invokeHegoMethod(final String method, final Object... args) {
final HegoSettableFuture<JSDecoder> settableFuture = new HegoSettableFuture<>();
public DoricSettableFuture<JSDecoder> invokeDoricMethod(final String method, final Object... args) {
final DoricSettableFuture<JSDecoder> settableFuture = new DoricSettableFuture<>();
Runnable runnable = new Runnable() {
@Override
public void run() {
@ -234,7 +234,7 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
values.add(new JavaValue(String.valueOf(arg)));
}
}
settableFuture.set(mHegoJSE.invokeMethod(HegoConstant.GLOBAL_HEGO, method,
settableFuture.set(mDoricJSE.invokeMethod(DoricConstant.GLOBAL_DORIC, method,
values.toArray(new JavaValue[values.size()]), true));
}
};
@ -244,6 +244,6 @@ public class HegoJSEngine implements Handler.Callback, HegoTimerExtension.TimerC
@Override
public void callback(long timerId) {
invokeHegoMethod(HegoConstant.HEGO_TIMER_CALLBACK, timerId);
invokeDoricMethod(DoricConstant.DORIC_TIMER_CALLBACK, timerId);
}
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.engine;
package com.github.pengfeizhou.doric.engine;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSExecutor;
@ -7,15 +7,15 @@ import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoJSExecutor implements IHegoJSE {
public class DoricJSExecutor implements IDoricJSE {
private final JSExecutor mJSExecutor;
public HegoJSExecutor() {
public DoricJSExecutor() {
this.mJSExecutor = JSExecutor.create();
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.engine;
package com.github.pengfeizhou.doric.engine;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSRuntimeException;
@ -6,11 +6,11 @@ import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public interface IHegoJSE {
public interface IDoricJSE {
/**
* 执行JS语句
*

View File

@ -1,15 +1,15 @@
package com.github.pengfeizhou.hego.extension;
package com.github.pengfeizhou.doric.extension;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JavaValue;
/**
* @Description: Android
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoBridgeExtension {
public HegoBridgeExtension() {
public class DoricBridgeExtension {
public DoricBridgeExtension() {
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.extension;
package com.github.pengfeizhou.doric.extension;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@ -7,13 +7,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @Description: Android
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface HegoMethod {
public @interface DoricMethod {
String name() default "";
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.extension;
package com.github.pengfeizhou.doric.extension;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@ -7,13 +7,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface HegoModule {
public @interface DoricModule {
String name() default "";
}

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego.extension;
package com.github.pengfeizhou.doric.extension;
import android.os.Handler;
import android.os.Looper;
@ -8,18 +8,18 @@ import java.util.HashSet;
import java.util.Set;
/**
* @Description: Android
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoTimerExtension implements Handler.Callback {
public class DoricTimerExtension implements Handler.Callback {
private static final int MSG_TIMER = 0;
private final Handler mTimerHandler;
private final TimerCallback mTimerCallback;
private Set<Long> mDeletedTimerIds = new HashSet<>();
public HegoTimerExtension(Looper looper, TimerCallback timerCallback) {
public DoricTimerExtension(Looper looper, TimerCallback timerCallback) {
mTimerHandler = new Handler(looper, this);
mTimerCallback = timerCallback;
}

View File

@ -1,17 +1,13 @@
package com.github.pengfeizhou.hego.extension;
package com.github.pengfeizhou.doric.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
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
@ -34,12 +30,12 @@ public class ModuleClassInfo {
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())) {
DoricMethod doricMethod = method.getAnnotation(DoricMethod.class);
if (doricMethod != null) {
if (TextUtils.isEmpty(doricMethod.name())) {
methodMap.put(method.getName(), method);
} else {
methodMap.put(hegoMethod.name(), method);
methodMap.put(doricMethod.name(), method);
}
}
}

View File

@ -0,0 +1,45 @@
package com.github.pengfeizhou.doric.utils;
/**
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class DoricConstant {
public static final String DORIC_BUNDLE_SANDBOX = "doric-sandbox.js";
public static final String DORIC_BUNDLE_LIB = "doric-lib.js";
public static final String DORIC_MODULE_LIB = "./index";
public static final String INJECT_LOG = "nativeLog";
public static final String INJECT_REQUIRE = "nativeRequire";
public static final String INJECT_TIMER_SET = "nativeSetTimer";
public static final String INJECT_TIMER_CLEAR = "nativeClearTimer";
public static final String INJECT_BRIDGE = "nativeBridge";
public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" +
"function(doric,context,require,exports){" + "\n" +
"%s" + "\n" +
"},doric.jsObtainContext(\"%s\"),[" +
"undefined," +
"doric.jsObtainContext(\"%s\")," +
"doric.__require__" +
",{}" +
"])";
public static final String TEMPLATE_MODULE = "Reflect.apply(doric.jsRegisterModule,this,[" +
"\"%s\"," +
"Reflect.apply(function(__module){" +
"(function(module,exports,require){" + "\n" +
"%s" + "\n" +
"})(__module,__module.exports,doric.__require__);" +
"\nreturn __module.exports;" +
"},this,[{exports:{}}])" +
"])";
public static final String TEMPLATE_CONTEXT_DESTROY = "doric.jsRelease(%s)";
public static final String GLOBAL_DORIC = "doric";
public static final String DORIC_CONTEXT_RELEASE = "jsReleaseContext";
public static final String DORIC_CONTEXT_INVOKE = "jsCallEntityMethod";
public static final String DORIC_TIMER_CALLBACK = "jsCallbackTimer";
}

View File

@ -1,16 +1,16 @@
package com.github.pengfeizhou.hego.utils;
package com.github.pengfeizhou.doric.utils;
import android.util.Log;
import com.github.pengfeizhou.hego.Hego;
import com.github.pengfeizhou.doric.Doric;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoLog {
private static String TAG = Hego.class.getSimpleName();
public class DoricLog {
private static String TAG = Doric.class.getSimpleName();
public static void d(String message, String... suffix) {
StringBuilder stringBuilder = new StringBuilder(TAG);

View File

@ -1,7 +1,7 @@
package com.github.pengfeizhou.hego.utils;
package com.github.pengfeizhou.doric.utils;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit;
* A super simple Future-like class that can safely notify another Thread when a value is ready.
* Does not support setting errors or canceling.
*/
public class HegoSettableFuture<T> {
public class DoricSettableFuture<T> {
private final CountDownLatch mReadyLatch = new CountDownLatch(1);
private volatile

View File

@ -1,22 +1,22 @@
package com.github.pengfeizhou.hego.utils;
package com.github.pengfeizhou.doric.utils;
import android.content.res.AssetManager;
import com.github.pengfeizhou.hego.Hego;
import com.github.pengfeizhou.doric.Doric;
import java.io.IOException;
import java.io.InputStream;
/**
* @Description: Hego
* @Description: Doric
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoUtils {
public class DoricUtils {
public static String readAssetFile(String assetFile) {
InputStream inputStream = null;
try {
AssetManager assetManager = Hego.application().getAssets();
AssetManager assetManager = Doric.application().getAssets();
inputStream = assetManager.open(assetFile);
int length = inputStream.available();
byte[] buffer = new byte[length];

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Doric</string>
</resources>

View File

@ -1,4 +1,4 @@
package com.github.pengfeizhou.hego;
package com.github.pengfeizhou.doric.test;
import org.junit.Test;

View File

@ -1,34 +0,0 @@
package com.github.pengfeizhou.hego;
import com.github.pengfeizhou.hego.utils.HegoSettableFuture;
import com.github.pengfeizhou.jscore.JSDecoder;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Description: Hego
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoContext {
private static AtomicInteger sCounter = new AtomicInteger();
private final String mContextId;
private HegoContext(String contextId) {
this.mContextId = contextId;
}
public static HegoContext createContext(String script, String alias) {
String contextId = String.valueOf(sCounter.incrementAndGet());
HegoDriver.getInstance().createPage(contextId, script, alias);
return new HegoContext(contextId);
}
public HegoSettableFuture<JSDecoder> callEntity(String methodName, Object... args) {
return HegoDriver.getInstance().invokeContextMethod(mContextId, methodName, args);
}
public void teardown() {
HegoDriver.getInstance().destoryContext(mContextId);
}
}

View File

@ -1,40 +0,0 @@
package com.github.pengfeizhou.hego;
import com.github.pengfeizhou.hego.engine.HegoJSEngine;
import com.github.pengfeizhou.hego.utils.HegoSettableFuture;
import com.github.pengfeizhou.jscore.JSDecoder;
/**
* @Description: Hego
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoDriver {
private final HegoJSEngine hegoJSEngine;
public HegoSettableFuture<JSDecoder> invokeContextMethod(final String contextId, final String method, final Object... args) {
return hegoJSEngine.invokeContextEntityMethod(contextId, method, args);
}
private static class Inner {
private static final HegoDriver sInstance = new HegoDriver();
}
private HegoDriver() {
hegoJSEngine = new HegoJSEngine();
}
public static HegoDriver getInstance() {
return Inner.sInstance;
}
public void createPage(final String contextId, final String script, final String source) {
hegoJSEngine.prepareContext(contextId, script, source);
}
public void destoryContext(String contextId) {
hegoJSEngine.destroyContext(contextId);
}
}

View File

@ -1,54 +0,0 @@
package com.github.pengfeizhou.hego;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* @Description: Hego
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoPanel extends FrameLayout {
private HegoContext mHegoContext;
public HegoPanel(@NonNull Context context) {
super(context);
}
public HegoPanel(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public HegoPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public HegoPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void config(String script, String alias) {
HegoContext hegoContext = HegoContext.createContext(script, alias);
config(hegoContext);
}
public void config(HegoContext hegoContext) {
mHegoContext = hegoContext;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
public HegoContext getHegoContext() {
return mHegoContext;
}
}

View File

@ -1,18 +0,0 @@
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();
}

View File

@ -1,26 +0,0 @@
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() {
}
}

View File

@ -1,39 +0,0 @@
package com.github.pengfeizhou.hego.utils;
/**
* @Description: Hego
* @Author: pengfei.zhou
* @CreateDate: 2019-07-18
*/
public class HegoConstant {
public static final String INJECT_LOG = "nativeLog";
public static final String INJECT_REQUIRE = "nativeRequire";
public static final String INJECT_TIMER_SET = "nativeSetTimer";
public static final String INJECT_TIMER_CLEAR = "nativeClearTimer";
public static final String INJECT_BRIDGE = "nativeBridge";
public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" +
"function(hego,context,require,exports){" + "\n" +
"%s" + "\n" +
"},hego.jsObtainContext(\"%s\"),[" +
"undefined," +
"hego.jsObtainContext(\"%s\")," +
"hego.__require__" +
",{}" +
"])";
public static final String TEMPLATE_MODULE = "Reflect.apply(hego.jsRegisterModule,this,[" +
"\"%s\"," +
"Reflect.apply(function(__module){" +
"(function(module,exports,require){" + "\n" +
"%s" + "\n" +
"})(__module,__module.exports,hego.__require__);" +
"\nreturn __module.exports;" +
"},this,[{exports:{}}])" +
"])";
public static final String TEMPLATE_CONTEXT_DESTORY = "hego.jsRelease(%s)";
public static final String GLOBAL_HEGO = "hego";
public static final String HEGO_CONTEXT_RELEASE = "jsReleaseContext";
public static final String HEGO_CONTEXT_INVOKE = "jsCallEntityMethod";
public static final String HEGO_TIMER_CALLBACK = "jsCallbackTimer";
}

View File

@ -1,3 +0,0 @@
<resources>
<string name="app_name">HEGO</string>
</resources>

View File

@ -1 +1 @@
include ':app', ':hego'
include ':app', ':doric'

View File

@ -1,2 +1,2 @@
# hego
# Doric
A cross-platform development framework for Android &amp; iOS

View File

@ -1,7 +1,7 @@
{
"name": "hego-js-framework",
"name": "doric-js-framework",
"version": "0.1.0",
"description": "The JS Framework of Hego",
"description": "The JS Framework of Doric",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
@ -11,14 +11,14 @@
},
"repository": {
"type": "https",
"url": "https://github.com/penfeizhou/hego.git"
"url": "https://github.com/penfeizhou/doric.git"
},
"author": "pengfeizhou",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/penfeizhou/hego/issues"
"url": "https://github.com/penfeizhou/doric/issues"
},
"homepage": "https://github.com/penfeizhou/hego#readme",
"homepage": "https://github.com/penfeizhou/doric#readme",
"dependencies": {
"reflect-metadata": "^0.1.13",
"rollup": "^1.17.0",

View File

@ -7,9 +7,9 @@ export default [
{
input: "build/index.runtime.js",
output: {
name: "hego",
name: "doric",
format: "iife",
file: "bundle/hego-sandbox.js",
file: "bundle/doric-sandbox.js",
},
sourceMap: true,
plugins: [
@ -21,7 +21,7 @@ export default [
input: "build/index.js",
output: {
format: "cjs",
file: "bundle/hego-lib.js",
file: "bundle/doric-lib.js",
},
sourceMap: true,
plugins: [