From c452ebffda4c7e619edd5fbc52b616e632f07094 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 23 Sep 2021 15:03:22 +0800 Subject: [PATCH] android:add timing activity --- .../app/src/main/AndroidManifest.xml | 8 +- .../doric/demo/DoricDebugTimingActivity.java | 124 ++++++++++++++++++ .../java/pub/doric/demo/MainActivity.java | 2 +- .../java/pub/doric/demo/MyApplication.java | 2 + .../main/res/layout/activity_debug_timing.xml | 18 +++ 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 doric-android/app/src/main/java/pub/doric/demo/DoricDebugTimingActivity.java create mode 100644 doric-android/app/src/main/res/layout/activity_debug_timing.xml diff --git a/doric-android/app/src/main/AndroidManifest.xml b/doric-android/app/src/main/AndroidManifest.xml index ac223bc3..11a06015 100644 --- a/doric-android/app/src/main/AndroidManifest.xml +++ b/doric-android/app/src/main/AndroidManifest.xml @@ -2,8 +2,6 @@ - - + + + + \ No newline at end of file diff --git a/doric-android/app/src/main/java/pub/doric/demo/DoricDebugTimingActivity.java b/doric-android/app/src/main/java/pub/doric/demo/DoricDebugTimingActivity.java new file mode 100644 index 00000000..e554213c --- /dev/null +++ b/doric-android/app/src/main/java/pub/doric/demo/DoricDebugTimingActivity.java @@ -0,0 +1,124 @@ +/* + * 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 androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import pub.doric.DoricContext; +import pub.doric.DoricPanel; +import pub.doric.DoricSingleton; +import pub.doric.async.AsyncResult; +import pub.doric.devkit.DoricDev; +import pub.doric.navbar.BaseDoricNavBar; +import pub.doric.navigator.IDoricNavigator; +import pub.doric.performance.DoricPerformanceProfile; +import pub.doric.utils.DoricLog; + +/** + * @Description: pub.doric.demo + * @Author: pengfei.zhou + * @CreateDate: 2021/7/14 + */ +public class DoricDebugTimingActivity extends AppCompatActivity { + @Override + protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final long pefStart = System.currentTimeMillis(); + setContentView(R.layout.activity_debug_timing); + final 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); + DoricSingleton.getInstance().getJSLoaderManager().loadJSBundle(getSource()).setCallback(new AsyncResult.Callback() { + @Override + public void onResult(String result) { + doricPanel.config(result, getAlias(), getExtra()); + DoricContext context = doricPanel.getDoricContext(); + context.setDoricNavigator(new IDoricNavigator() { + @Override + public void push(String source, String alias, String extra) { + + } + + @Override + public void pop() { + + } + }); + context.setDoricNavBar(doricNavBar); + doricPanel.getDoricContext().getPerformanceProfile().addAnchorHook(new DoricPerformanceProfile.AnchorHook() { + @Override + public void onAnchor(String name, long prepare, long start, long end) { + if (name.equals(DoricPerformanceProfile.STEP_RENDER)) { + long cost = end - pefStart; + Log.d("Timing", "Cost " + cost + "ms"); + } + } + }); + } + + @Override + public void onError(Throwable t) { + DoricLog.e("Doric load JS error:" + t.getLocalizedMessage()); + } + + @Override + public void onFinish() { + + } + }); + + } + + /** + * @return Scheme for DoricFragment to load. + */ + protected String getSource() { + return getIntent().getStringExtra("source"); + } + + /** + * @return Alias used for JS error message. + */ + protected String getAlias() { + return getIntent().getStringExtra("alias"); + } + + /** + * @return Extra data used for JS Panel in JSON format. + */ + protected String getExtra() { + return getIntent().getStringExtra("extra"); + } + +} diff --git a/doric-android/app/src/main/java/pub/doric/demo/MainActivity.java b/doric-android/app/src/main/java/pub/doric/demo/MainActivity.java index 39eab2a2..5bb4f74e 100644 --- a/doric-android/app/src/main/java/pub/doric/demo/MainActivity.java +++ b/doric-android/app/src/main/java/pub/doric/demo/MainActivity.java @@ -119,7 +119,7 @@ public class MainActivity extends AppCompatActivity { tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(tv.getContext(), DoricDebugActivity.class); + Intent intent = new Intent(tv.getContext(), DoricDebugTimingActivity.class); intent.putExtra("source", "assets://src/" + data[position - 1]); intent.putExtra("alias", data[position - 1].replace(".js", "")); tv.getContext().startActivity(intent); diff --git a/doric-android/app/src/main/java/pub/doric/demo/MyApplication.java b/doric-android/app/src/main/java/pub/doric/demo/MyApplication.java index a56faf7d..f61a8f49 100644 --- a/doric-android/app/src/main/java/pub/doric/demo/MyApplication.java +++ b/doric-android/app/src/main/java/pub/doric/demo/MyApplication.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; import pub.doric.Doric; +import pub.doric.DoricNativeDriver; import pub.doric.DoricRegistry; import pub.doric.DoricSingleton; @@ -45,6 +46,7 @@ public class MyApplication extends Application { DoricSingleton.getInstance().setEnvironmentValue(map); } }, intentFilter); + DoricNativeDriver.getInstance(); Doric.enablePerformance(true); Doric.enableRenderSnapshot(true); } diff --git a/doric-android/app/src/main/res/layout/activity_debug_timing.xml b/doric-android/app/src/main/res/layout/activity_debug_timing.xml new file mode 100644 index 00000000..d5863bb9 --- /dev/null +++ b/doric-android/app/src/main/res/layout/activity_debug_timing.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file