sceneFromUiDump function

Scene sceneFromUiDump(
  1. String xml,
  2. double dpr
)

Flat scene of the labelled or tappable nodes in a uiautomator dump, framed in logical points.

Implementation

Scene sceneFromUiDump(String xml, double dpr) {
  final nodes = <NativeNode>[];
  for (final m in RegExp(r'<node ([^>]*?)/?>').allMatches(xml)) {
    final a = {
      for (final kv in RegExp(r'([\w-]+)="([^"]*)"').allMatches(m.group(1)!)) kv.group(1)!: _unescape(kv.group(2)!),
    };
    final text = a['text'] ?? '';
    final b = RegExp(r'\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]').firstMatch(a['bounds'] ?? '');
    if (b == null) continue;
    nodes.add((
      cls: (a['class'] ?? 'View').split('.').last,
      label: text.isNotEmpty ? text : (a['content-desc'] ?? ''),
      clickable: a['clickable'] == 'true',
      x1: int.parse(b.group(1)!),
      y1: int.parse(b.group(2)!),
      x2: int.parse(b.group(3)!),
      y2: int.parse(b.group(4)!),
    ));
  }
  return nativeScene(nodes, dpr);
}