Repository navigation
Expand file tree
/
Copy pathhandler_snapshot.java
More file actions
59 lines (53 loc) · 2.28 KB
/
Copy pathhandler_snapshot.java
File metadata and controls
59 lines (53 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import android.view.accessibility.AccessibilityNodeInfo;
import android.graphics.Rect;
import android.graphics.Point;
import android.view.WindowManager;
import android.content.Context;
import org.json.JSONObject;
import org.json.JSONArray;
a11Y.set();
walkNode(AccessibilityNodeInfo node, String path, int depth, JSONArray out) {
if (node == null || node == void) return;
Rect r = new Rect();
node.getBoundsInScreen(r);
if (r.width() >= 2 && r.height() >= 2) {
JSONObject n = new JSONObject();
n.put("path", path);
n.put("depth", depth);
n.put("left", r.left); n.put("top", r.top);
n.put("right", r.right); n.put("bottom", r.bottom);
n.put("centerX", (r.left + r.right) / 2);
n.put("centerY", (r.top + r.bottom) / 2);
n.put("clickable", node.isClickable());
n.put("longClickable", node.isLongClickable());
n.put("scrollable", node.isScrollable());
n.put("editable", node.isEditable());
n.put("focusable", node.isFocusable());
n.put("checkable", node.isCheckable());
n.put("checked", node.isChecked());
n.put("enabled", node.isEnabled());
n.put("className", node.getClassName() != null ? node.getClassName().toString() : "");
n.put("viewId", node.getViewIdResourceName() != null ? node.getViewIdResourceName() : "");
n.put("text", node.getText() != null ? node.getText().toString() : "");
n.put("desc", node.getContentDescription() != null ? node.getContentDescription().toString() : "");
out.put(n);
}
for (int i = 0; i < node.getChildCount(); i++) {
walkNode(node.getChild(i), path + "." + i, depth + 1, out);
}
}
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
sz = new Point();
wm.getDefaultDisplay().getRealSize(sz);
nodes = new JSONArray();
root = getRoot();
if (root != null) walkNode(root, "0", 0, nodes);
resp = new JSONObject();
resp.put("width", sz.x);
resp.put("height", sz.y);
resp.put("ts", System.currentTimeMillis());
resp.put("nodeCount", nodes.length());
resp.put("nodes", nodes);
tasker.setVariable("response_code", "200");
tasker.setVariable("response_body", resp.toString());
tasker.setVariable("response_mime_type", "application/json");