diff --git a/Android/app/build.gradle b/Android/app/build.gradle index 53d4c1d1..a095cf80 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -23,7 +23,6 @@ dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation project(':doric') - implementation 'org.nanohttpd:nanohttpd:2.3.1' implementation 'com.github.bumptech.glide:glide:4.8.0' implementation 'com.github.bumptech.glide:annotations:4.8.0' implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1' diff --git a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/LocalServer.java b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/LocalServer.java deleted file mode 100644 index 56dd53e3..00000000 --- a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/LocalServer.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.github.penfeizhou.doricdemo; - -import android.content.Context; -import android.content.res.AssetManager; - -import java.io.IOException; -import java.io.InputStream; - -import fi.iki.elonen.NanoHTTPD; - -/** - * @Description: com.github.penfeizhou.doricdemo - * @Author: pengfei.zhou - * @CreateDate: 2019-08-03 - */ -public class LocalServer extends NanoHTTPD { - private final Context context; - - public LocalServer(Context context, int port) { - super(port); - this.context = context; - } - - @Override - public Response serve(IHTTPSession session) { - String url = session.getUri(); - if (url.startsWith("/assets/")) { - String fileName = url.substring("/assets/".length()); - AssetManager assetManager = context.getAssets(); - try { - InputStream inputStream = assetManager.open(fileName); - return newFixedLengthResponse(Response.Status.OK, "text/plain", inputStream, inputStream.available()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - return newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "text/html", "HelloWorld"); - } -} diff --git a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java index 77fafcbe..1ad0aca9 100644 --- a/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java +++ b/Android/app/src/main/java/com/github/penfeizhou/doricdemo/MainActivity.java @@ -7,6 +7,7 @@ import android.widget.FrameLayout; import com.github.penfeizhou.doric.Doric; import com.github.penfeizhou.doric.DoricContext; +import com.github.penfeizhou.doric.dev.LocalServer; import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSONBuilder; @@ -33,5 +34,4 @@ public class MainActivity extends AppCompatActivity { e.printStackTrace(); } } - } diff --git a/Android/doric/build.gradle b/Android/doric/build.gradle index 5f4cff86..40d7046a 100644 --- a/Android/doric/build.gradle +++ b/Android/doric/build.gradle @@ -42,4 +42,5 @@ dependencies { api 'com.github.pengfeizhou:jsc4a:0.1.0' implementation "com.squareup.okhttp3:okhttp:3.11.0" implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1' + api 'org.nanohttpd:nanohttpd:2.3.1' } diff --git a/Android/doric/src/main/assets/debugger b/Android/doric/src/main/assets/debugger new file mode 120000 index 00000000..6fe8512f --- /dev/null +++ b/Android/doric/src/main/assets/debugger @@ -0,0 +1 @@ +../../../../../js-framework/debugger \ No newline at end of file diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/dev/LocalServer.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/dev/LocalServer.java new file mode 100644 index 00000000..9fb45e94 --- /dev/null +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/dev/LocalServer.java @@ -0,0 +1,70 @@ +package com.github.penfeizhou.doric.dev; + +import android.content.Context; +import android.content.res.AssetManager; +import android.util.Log; +import android.webkit.MimeTypeMap; + +import java.io.IOException; +import java.io.InputStream; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +import fi.iki.elonen.NanoHTTPD; + +/** + * @Description: com.github.penfeizhou.doricdemo + * @Author: pengfei.zhou + * @CreateDate: 2019-08-03 + */ +public class LocalServer extends NanoHTTPD { + private final Context context; + + public LocalServer(Context context, int port) { + super(port); + this.context = context; + } + + private static String getIpAddressString() { + try { + for (Enumeration enNetI = NetworkInterface + .getNetworkInterfaces(); enNetI.hasMoreElements(); ) { + NetworkInterface netI = enNetI.nextElement(); + for (Enumeration enumIpAddr = netI + .getInetAddresses(); enumIpAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) { + return inetAddress.getHostAddress(); + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + return "0.0.0.0"; + } + + @Override + public void start() throws IOException { + super.start(); + Log.d("Debugger", String.format("Open http://%s:8910/debugger.html to start debug", getIpAddressString())); + } + + @Override + public Response serve(IHTTPSession session) { + String url = session.getUri(); + String fileName = url.substring(1); + AssetManager assetManager = context.getAssets(); + try { + InputStream inputStream = assetManager.open("debugger/" + fileName); + String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileName.substring(fileName.lastIndexOf(".") + 1)); + return NanoHTTPD.newFixedLengthResponse(Response.Status.OK, mimeType, inputStream, inputStream.available()); + } catch (IOException e) { + e.printStackTrace(); + } + return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "text/html", "HelloWorld"); + } +} diff --git a/js-framework/debugger/debugger.html b/js-framework/debugger/debugger.html new file mode 100644 index 00000000..cd1eeba8 --- /dev/null +++ b/js-framework/debugger/debugger.html @@ -0,0 +1,13 @@ + + + + + + Doric控制台 + + + +

Doric控制台

+ + + \ No newline at end of file