Add SSR mode and test on Android
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
<activity
|
||||
android:name=".DoricEmbeddedActivity"
|
||||
android:theme="@style/Theme.Design.Light.NoActionBar" />
|
||||
<activity
|
||||
android:name=".DoricSSRActivity"
|
||||
android:theme="@style/Theme.Design.Light.NoActionBar" />
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package pub.doric.demo;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricPanel;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.devkit.remote.ValueBuilder;
|
||||
import pub.doric.navbar.BaseDoricNavBar;
|
||||
import pub.doric.shader.RootNode;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
/**
|
||||
* @Description: pub.doric.demo
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2021/7/14
|
||||
*/
|
||||
public class DoricSSRActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_debug_timing);
|
||||
BaseDoricNavBar doricNavBar = findViewById(R.id.doric_nav_bar);
|
||||
TextView textView = new TextView(this);
|
||||
textView.setText("Devkit");
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DoricDev.getInstance().openDevMode();
|
||||
}
|
||||
});
|
||||
textView.setLayoutParams(new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
doricNavBar.setRight(textView);
|
||||
final DoricPanel doricPanel = findViewById(R.id.doric_panel);
|
||||
RootNode rootNode = new RootNode(DoricContext.MOCK_CONTEXT);
|
||||
rootNode.setRootView(doricPanel);
|
||||
String json = DoricUtils.readAssetFile("src/LayoutDemo.ssr.json");
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
ValueBuilder vb = new ValueBuilder(jsonObject);
|
||||
JSDecoder jsDecoder = new JSDecoder(vb.build());
|
||||
JSObject jsObject = jsDecoder.decode().asObject();
|
||||
Log.d("Timing", "Decode cost " + (System.currentTimeMillis() - start) + " ms");
|
||||
rootNode.blend(jsObject.getProperty("props").asObject());
|
||||
Log.d("Timing", "SSR cost " + (System.currentTimeMillis() - start) + " ms");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,15 +25,14 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.refresh.DoricSwipeLayout;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
@@ -133,13 +132,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
tv.getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
tv.setText(data[position - 3]);
|
||||
} else if (position == 3) {
|
||||
tv.setText("SSR Example");
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(tv.getContext(), DoricSSRActivity.class);
|
||||
tv.getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tv.setText(data[position - 4]);
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(tv.getContext(), DoricDebugTimingActivity.class);
|
||||
intent.putExtra("source", "assets://src/" + data[position - 3]);
|
||||
intent.putExtra("source", "assets://src/" + data[position - 4]);
|
||||
//intent.putExtra("alias", data[position - 1].replace(".js", ""));
|
||||
intent.putExtra("alias", "__dev__");
|
||||
tv.getContext().startActivity(intent);
|
||||
@@ -150,7 +158,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return data.length + 3;
|
||||
return data.length + 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,8 +26,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||
import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
@@ -35,6 +33,7 @@ import com.github.pengfeizhou.jscore.JSObject;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.devkit.R;
|
||||
@@ -156,7 +155,7 @@ public class DoricSnapshotView extends DoricFloatingView {
|
||||
rootNode.setId(viewId);
|
||||
rootNode.blend(jsObject.getProperty("props").asObject());
|
||||
} else {
|
||||
ViewNode viewNode = doricContext.targetViewNode(viewId);
|
||||
ViewNode<?> viewNode = doricContext.targetViewNode(viewId);
|
||||
if (viewNode != null) {
|
||||
viewNode.blend(jsObject.getProperty("props").asObject());
|
||||
}
|
||||
|
@@ -17,13 +17,11 @@ package pub.doric;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
|
||||
@@ -39,6 +37,8 @@ import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.engine.RetainedJavaValue;
|
||||
import pub.doric.navbar.IDoricNavBar;
|
||||
@@ -72,6 +72,8 @@ public class DoricContext {
|
||||
private final Map<String, Animator> animators = new HashMap<>();
|
||||
private final Map<String, DoricResource> cachedResources = new WeakHashMap<>();
|
||||
private final Set<SoftReference<RetainedJavaValue>> retainedJavaValues = new HashSet<>();
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public static final DoricContext MOCK_CONTEXT = new DoricContext(Doric.application(), "", "", "");
|
||||
|
||||
public Collection<ViewNode<?>> allHeadNodes(String type) {
|
||||
Map<String, ViewNode<?>> headNode = mHeadNodes.get(type);
|
||||
|
Reference in New Issue
Block a user