Android: impl show node tree view
This commit is contained in:
parent
61c262bcc6
commit
844908bdc6
@ -25,6 +25,7 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import pub.doric.devkit.R;
|
import pub.doric.devkit.R;
|
||||||
import pub.doric.devkit.ui.treeview.DoricViewNodeLayoutItemType;
|
import pub.doric.devkit.ui.treeview.DoricViewNodeLayoutItemType;
|
||||||
@ -32,6 +33,7 @@ import pub.doric.devkit.ui.treeview.DoricViewNodeTreeViewBinder;
|
|||||||
import pub.doric.devkit.ui.treeview.TreeNode;
|
import pub.doric.devkit.ui.treeview.TreeNode;
|
||||||
import pub.doric.devkit.ui.treeview.TreeViewAdapter;
|
import pub.doric.devkit.ui.treeview.TreeViewAdapter;
|
||||||
import pub.doric.shader.GroupNode;
|
import pub.doric.shader.GroupNode;
|
||||||
|
import pub.doric.shader.SuperNode;
|
||||||
import pub.doric.shader.ViewNode;
|
import pub.doric.shader.ViewNode;
|
||||||
|
|
||||||
public class DoricShowNodeTreeActivity extends DoricDevBaseActivity {
|
public class DoricShowNodeTreeActivity extends DoricDevBaseActivity {
|
||||||
@ -71,6 +73,17 @@ public class DoricShowNodeTreeActivity extends DoricDevBaseActivity {
|
|||||||
viewQueue.offer((ViewNode) groupNode.getChildNodes().get(i));
|
viewQueue.offer((ViewNode) groupNode.getChildNodes().get(i));
|
||||||
treeQueue.offer(temp);
|
treeQueue.offer(temp);
|
||||||
}
|
}
|
||||||
|
} else if (viewNode instanceof SuperNode) {
|
||||||
|
SuperNode superNode = (SuperNode) viewNode;
|
||||||
|
Set<String> viewIds = superNode.getSubNodeViewIds();
|
||||||
|
for (String viewId : viewIds) {
|
||||||
|
assert treeNode != null;
|
||||||
|
TreeNode<DoricViewNodeLayoutItemType> temp = new TreeNode(new DoricViewNodeLayoutItemType(superNode.getSubNodeById(viewId)));
|
||||||
|
treeNode.addChild(temp);
|
||||||
|
|
||||||
|
viewQueue.offer(superNode.getSubNodeById(viewId));
|
||||||
|
treeQueue.offer(temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import pub.doric.devkit.R;
|
|||||||
import pub.doric.shader.ViewNode;
|
import pub.doric.shader.ViewNode;
|
||||||
|
|
||||||
public class DoricViewNodeLayoutItemType implements LayoutItemType {
|
public class DoricViewNodeLayoutItemType implements LayoutItemType {
|
||||||
private final ViewNode viewNode;
|
public final ViewNode viewNode;
|
||||||
|
|
||||||
public DoricViewNodeLayoutItemType(ViewNode viewNode) {
|
public DoricViewNodeLayoutItemType(ViewNode viewNode) {
|
||||||
this.viewNode = viewNode;
|
this.viewNode = viewNode;
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
package pub.doric.devkit.ui.treeview;
|
package pub.doric.devkit.ui.treeview;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import pub.doric.devkit.R;
|
import pub.doric.devkit.R;
|
||||||
|
import pub.doric.shader.GroupNode;
|
||||||
|
import pub.doric.shader.RootNode;
|
||||||
|
import pub.doric.shader.SuperNode;
|
||||||
|
import pub.doric.shader.ViewNode;
|
||||||
|
|
||||||
public class DoricViewNodeTreeViewBinder extends TreeViewBinder<DoricViewNodeTreeViewBinder.ViewHolder> {
|
public class DoricViewNodeTreeViewBinder extends TreeViewBinder<DoricViewNodeTreeViewBinder.ViewHolder> {
|
||||||
|
|
||||||
@ -14,6 +21,26 @@ public class DoricViewNodeTreeViewBinder extends TreeViewBinder<DoricViewNodeTre
|
|||||||
@Override
|
@Override
|
||||||
public void bindView(ViewHolder holder, int position, TreeNode node) {
|
public void bindView(ViewHolder holder, int position, TreeNode node) {
|
||||||
DoricViewNodeLayoutItemType layoutItemType = (DoricViewNodeLayoutItemType) node.getContent();
|
DoricViewNodeLayoutItemType layoutItemType = (DoricViewNodeLayoutItemType) node.getContent();
|
||||||
|
|
||||||
|
ViewNode viewNode = layoutItemType.viewNode;
|
||||||
|
String type = viewNode.getType();
|
||||||
|
if (viewNode instanceof RootNode) {
|
||||||
|
type = "Root";
|
||||||
|
}
|
||||||
|
String viewId = " <" + viewNode.getId() + "> ";
|
||||||
|
|
||||||
|
String value = type + viewId;
|
||||||
|
if (viewNode instanceof GroupNode) {
|
||||||
|
GroupNode groupNode = (GroupNode) viewNode;
|
||||||
|
String childDesc = "(" + groupNode.getChildNodes().size() + " Child)";
|
||||||
|
value = value + childDesc;
|
||||||
|
} else if (viewNode instanceof SuperNode) {
|
||||||
|
SuperNode superNode = (SuperNode) viewNode;
|
||||||
|
Set<String> viewIds = superNode.getSubNodeViewIds();
|
||||||
|
String childDesc = "(" + viewIds.size() + " Child)";
|
||||||
|
value = value + childDesc;
|
||||||
|
}
|
||||||
|
holder.nodeName.setText(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -23,8 +50,12 @@ public class DoricViewNodeTreeViewBinder extends TreeViewBinder<DoricViewNodeTre
|
|||||||
|
|
||||||
public static class ViewHolder extends TreeViewBinder.ViewHolder {
|
public static class ViewHolder extends TreeViewBinder.ViewHolder {
|
||||||
|
|
||||||
|
public TextView nodeName;
|
||||||
|
|
||||||
public ViewHolder(View rootView) {
|
public ViewHolder(View rootView) {
|
||||||
super(rootView);
|
super(rootView);
|
||||||
|
|
||||||
|
this.nodeName = rootView.findViewById(R.id.node_type_tv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private static final String KEY_IS_EXPAND = "IS_EXPAND";
|
private static final String KEY_IS_EXPAND = "IS_EXPAND";
|
||||||
private final List<? extends TreeViewBinder> viewBinders;
|
private final List<? extends TreeViewBinder> viewBinders;
|
||||||
private List<TreeNode> displayNodes;
|
private List<TreeNode> displayNodes;
|
||||||
private int padding = 30;
|
private int padding = DoricUtils.dp2px(15);
|
||||||
private OnTreeNodeListener onTreeNodeListener;
|
private OnTreeNodeListener onTreeNodeListener;
|
||||||
private boolean toCollapseChild;
|
private boolean toCollapseChild;
|
||||||
|
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
@ -1,10 +1,24 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp">
|
android:layout_height="50dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="20dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:src="@drawable/icon_doric_dev_info" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/node_type_tv"
|
android:id="@+id/node_type_tv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
tools:text="Node Name" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -23,10 +23,11 @@ import com.github.pengfeizhou.jscore.JSObject;
|
|||||||
import com.github.pengfeizhou.jscore.JSValue;
|
import com.github.pengfeizhou.jscore.JSValue;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.utils.DoricUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: pub.doric.shader
|
* @Description: pub.doric.shader
|
||||||
@ -136,4 +137,17 @@ public abstract class SuperNode<V extends View> extends ViewNode<V> {
|
|||||||
targetProps.asObject().setProperty(key, jsValue);
|
targetProps.asObject().setProperty(key, jsValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getSubNodeViewIds() {
|
||||||
|
Set<String> allKeys = subNodes.keySet();
|
||||||
|
Iterator<String> iterator = allKeys.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
String element = iterator.next();
|
||||||
|
if (getSubNodeById(element) == null) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allKeys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user