From ba3635769a2777d3f973d6cccdd7632d764f17b1 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 19 Jul 2021 17:05:50 +0800 Subject: [PATCH] android: extract base activity for obtain doric context --- .../devkit/src/main/AndroidManifest.xml | 1 + .../pub/doric/devkit/ui/DoricDevActivity.java | 23 +++++++++-- .../doric/devkit/ui/DoricDevBaseActivity.java | 41 +++++++++++++++++++ .../doric/devkit/ui/DoricDevPerfActivity.java | 18 +++++++- .../devkit/ui/DoricShowNodeTreeActivity.java | 26 +++++++----- 5 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevBaseActivity.java diff --git a/doric-android/devkit/src/main/AndroidManifest.xml b/doric-android/devkit/src/main/AndroidManifest.xml index a58da216..d5e29b36 100644 --- a/doric-android/devkit/src/main/AndroidManifest.xml +++ b/doric-android/devkit/src/main/AndroidManifest.xml @@ -12,5 +12,6 @@ android:theme="@style/Theme.Design.Light.NoActionBar" /> + diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java index b023ded5..c45c95ed 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevActivity.java @@ -1,3 +1,18 @@ +/* + * Copyright [2020] [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.devkit.ui; import android.Manifest; @@ -399,19 +414,21 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat actionMap.put("Performance", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - Map anchorMap = context.getPerformanceProfile().getAnchorMap(); - + Intent intent = new Intent(holder.itemView.getContext(), DoricDevPerfActivity.class); + intent.putExtra(DORIC_CONTEXT_ID_KEY, context.getContextId()); + v.getContext().startActivity(intent); ((Activity) v.getContext()).finish(); } }); } - actionMap.put("Show node tree", new DialogInterface.OnClickListener() { + actionMap.put("View node tree", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(holder.itemView.getContext(), DoricShowNodeTreeActivity.class); intent.putExtra(DORIC_CONTEXT_ID_KEY, context.getContextId()); v.getContext().startActivity(intent); + ((Activity) v.getContext()).finish(); } }); final String[] items = actionMap.keySet().toArray(new String[0]); diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevBaseActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevBaseActivity.java new file mode 100644 index 00000000..0597674c --- /dev/null +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevBaseActivity.java @@ -0,0 +1,41 @@ +/* + * Copyright [2021] [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.devkit.ui; + +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import pub.doric.DoricContext; +import pub.doric.DoricContextManager; + +/** + * @Description: pub.doric.devkit.ui + * @Author: pengfei.zhou + * @CreateDate: 2021/7/19 + */ +public class DoricDevBaseActivity extends AppCompatActivity { + public static final String DORIC_CONTEXT_ID_KEY = "DORIC_CONTEXT_ID"; + protected DoricContext doricContext; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + String contextId = getIntent().getStringExtra(DORIC_CONTEXT_ID_KEY); + doricContext = DoricContextManager.getContext(contextId); + } +} diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevPerfActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevPerfActivity.java index 14147dd4..2e96eab0 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevPerfActivity.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricDevPerfActivity.java @@ -1,17 +1,31 @@ +/* + * Copyright [2021] [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.devkit.ui; import android.os.Bundle; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; /** * @Description: pub.doric.devkit.ui * @Author: pengfei.zhou * @CreateDate: 2021/7/19 */ -public class DoricDevPerfActivity extends AppCompatActivity { +public class DoricDevPerfActivity extends DoricDevBaseActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricShowNodeTreeActivity.java b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricShowNodeTreeActivity.java index 60173977..83782595 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricShowNodeTreeActivity.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/ui/DoricShowNodeTreeActivity.java @@ -1,8 +1,22 @@ +/* + * Copyright [2021] [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.devkit.ui; import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -12,8 +26,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Queue; -import pub.doric.DoricContext; -import pub.doric.DoricContextManager; import pub.doric.devkit.R; import pub.doric.devkit.ui.treeview.DoricViewNodeLayoutItemType; import pub.doric.devkit.ui.treeview.DoricViewNodeTreeViewBinder; @@ -22,20 +34,14 @@ import pub.doric.devkit.ui.treeview.TreeViewAdapter; import pub.doric.shader.GroupNode; import pub.doric.shader.ViewNode; -public class DoricShowNodeTreeActivity extends AppCompatActivity { - - public static final String DORIC_CONTEXT_ID_KEY = "DORIC_CONTEXT_ID"; +public class DoricShowNodeTreeActivity extends DoricDevBaseActivity { private RecyclerView rv; private TreeViewAdapter adapter; - private DoricContext doricContext; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - String contextId = getIntent().getStringExtra(DORIC_CONTEXT_ID_KEY); - doricContext = DoricContextManager.getContext(contextId); setContentView(R.layout.layout_show_node_tree); initView();