Skip to content

Commit

Permalink
add ui tree of UiObject
Browse files Browse the repository at this point in the history
  • Loading branch information
cmzf committed Jan 8, 2020
1 parent 280532e commit 94ebc7f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private void pageIndex(AsyncHttpServerRequest request, AsyncHttpServerResponse r

private void apiTree(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.setContentType("application/json");
response.send(JSON.toJSONString(AccessibilityService.getInstance().getRootUiObject()));
response.send(JSON.toJSONString(AccessibilityService.getInstance().getRootUiObject().uiTree()));
}

public void start(Integer port) {
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/github/cmzf/androidinspector/UiObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public String toString() {
+ " />";
}

public UiTree<UiObject> uiTree() {
return uiTree(this);
}

public UiTree<UiObject> uiTree(UiObject node) {
ArrayList<UiTree<UiObject>> treeChildren = new ArrayList<>();
ArrayList<UiObject> children = node.children();
for (UiObject child : children) {
treeChildren.add(treeChildren.size(), uiTree(child));
}
return new UiTree<>(node, treeChildren);
}

public ArrayList<UiObject> children() {
if (mInfo == null) {
return new ArrayList<>();
Expand Down Expand Up @@ -227,4 +240,23 @@ public boolean isShowingHintText() {
return mInfo.isShowingHintText();
}

public static class UiTree<T> implements Serializable {
private T node;
private ArrayList<UiTree<T>> children;

public UiTree(T node, ArrayList<UiTree<T>> children) {
this.node = node;
if (children.size() > 0) {
this.children = children;
}
}

public T getNode() {
return node;
}

public ArrayList<UiTree<T>> getChildren() {
return children;
}
}
}

0 comments on commit 94ebc7f

Please sign in to comment.