zoukankan      html  css  js  c++  java
  • 老李推荐:第14章8节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-获取控件列表并建立控件树 2

    这个方法非常重要,重点做了两个事情:

    • 重点1:392行处通过向ViewServer发送”DUMP”命令来获得控件列表,获得谁的控件列表呢?注意”DUMP”命令所带的参数,调用的是刚才哈希值为-1的那个Window的encode方法,而这个方法所做的事情其实就是将-1转换成16进制,请看代码14-8-3。所以这里其实获得的就是屏幕最前面的Activity窗口的所有控件

     public String encode() {  

      return Integer.toHexString(this.mHashCode);  

    }  

    代码14-8-3 Window - encode

    • 重点2: 在获得所有控件列表之后,394行处就会调用parseViewHierarchy这个方法来解析这个ViewServer返回来的一大串控件列表信息,并且把这些解析出来的控件组建成我们最终的控件树

     

    411     public static ViewNode parseViewHierarchy(BufferedReader in, Window window) {  

    412         ViewNode currentNode = null;  

    413         int currentDepth = -1;  

    414         String line;  

    415         try {  

    416             while ((line = in.readLine()) != null) {  

    417                 if ("DONE.".equalsIgnoreCase(line)) {  

    418                     break;  

    419                 }  

    420                 int depth = 0;  

    421                 while (line.charAt(depth) == ' ') {  

    422                     depth++;  

    423                 }  

    424                 while (depth <= currentDepth) {  

    425                     if (currentNode != null) {  

    426                         currentNode = currentNode.parent;  

    427                     }  

    428                     currentDepth--;  

    429                 }  

    430                 currentNode = new ViewNode(window, currentNode, line.substring(depth));  

    431                 currentDepth = depth;  

    432             }  

    433         } catch (IOException e) {  

    434             Log.e(TAG, "Error reading view hierarchy stream: " + e.getMessage());  

    435             return null;  

    436         }  

    437         if (currentNode == null) {  

    438             return null;  

    439         }  

    440         while (currentNode.parent != null) {  

    441             currentNode = currentNode.parent;  

    442         }  

    443         return currentNode;  

    444     }  

    代码14-8-4 BridgeDevice - parseViewHierarchy

  • 相关阅读:
    webpack中的extract-text-webpack-plugin插件使用方法总结
    vue知识总结第一篇vue组件的定义以及父子组件的传值。
    Java在当前时间的基础上增加N时间
    SVN服务器端和客户端的搭建与使用
    字符串后面去0、补0
    安装Oracle数据库并建立可以用的用户
    【品优购代码外笔记】安装并使用Zookeeper
    【十次方基础教程(后台)】influxDB、cAdvisor、cAdvisor的安装与使用(监控微服务内存,自动扩容)
    【十次方基础教程(后台)】使用Rancher管理容器
    【十次方基础教程(后台)】使用Gogs,Jenkins实现持续集成
  • 原文地址:https://www.cnblogs.com/poptest/p/5103251.html
Copyright © 2011-2022 走看看