add server

This commit is contained in:
pengfei.zhou 2019-08-03 17:58:25 +08:00
parent 4d8e11b660
commit bb86c3c332
5 changed files with 54 additions and 3 deletions

View File

@ -28,4 +28,5 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':doric') implementation project(':doric')
implementation 'org.nanohttpd:nanohttpd:2.3.1'
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.penfeizhou.doricdemo"> package="com.github.penfeizhou.doricdemo">
<uses-permission android:name="android.permission.INTERNET"/>
<application <application
android:name="com.github.penfeizhou.doricdemo.MyApplication" android:name="com.github.penfeizhou.doricdemo.MyApplication"
android:allowBackup="true" android:allowBackup="true"

View File

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

View File

@ -5,10 +5,13 @@ import android.os.Bundle;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.github.penfeizhou.doric.Doric;
import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricContext;
import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.penfeizhou.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSONBuilder;
import java.io.IOException;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -22,6 +25,13 @@ public class MainActivity extends AppCompatActivity {
.put("height", ViewGroup.LayoutParams.MATCH_PARENT)); .put("height", ViewGroup.LayoutParams.MATCH_PARENT));
doricContext.callEntity("log"); doricContext.callEntity("log");
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root)); doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
Doric.connectDevKit("wss://192.168.11.38:7777");
LocalServer localServer = new LocalServer(getApplicationContext(), 8910);
try {
localServer.start();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }

View File

@ -41,10 +41,10 @@ class CounterView extends ViewHolder {
offsetY: 10, offsetY: 10,
} }
vlayout.shadow = { vlayout.shadow = {
color: Color.parse("#00ff00"), color: Color.parse("#ffff00"),
opacity: 0.5, opacity: 0.5,
radius: 20, radius: 20,
offsetX: -10, offsetX: 10,
offsetY: 10, offsetY: 10,
} }
vlayout.corners = 20 vlayout.corners = 20