首页 > 代码库 > ViewServer接受hierarchyviewer的命令
ViewServer接受hierarchyviewer的命令
AUTOLIST
线程阻塞,命令发送后,会等待viewserver反馈结果。viewserver在检测到界面跳转以后才会回馈结果。
private class WindowChangeMonitor implements Runnable { private IDevice device; public WindowChangeMonitor(IDevice device) { this.device = device; } public void run() { while (!Thread.currentThread().isInterrupted()) { DeviceConnection connection = null; try { connection = new DeviceConnection(this.device); connection.sendCommand("AUTOLIST"); String line; while ((!Thread.currentThread().isInterrupted()) && ((line = connection.getInputStream().readLine()) != null)) { if (line.equalsIgnoreCase("LIST UPDATE")) { } if (line.equalsIgnoreCase("FOCUS UPDATE")) { } show(line); } } catch (IOException e) { } finally { if (connection != null) connection.close(); } } } }
以上程序运行后,会一直等待,知道界面有跳转。反馈的结果有2种:LIST UPDATE和FOCUS UPATE。输出结果如下:
Appiot----------------LIST UPDATE Appiot----------------FOCUS UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE
一个界面的跳转有一个FOCUS UPDATE事件触发,但是会触发若干LIST UPDATE事件。
GET_FOCUS
得到当前设备上显示的界面的activity。
在刚才代码的基础上,当检测到界面跳转时,获得跳转后的activity.
private class WindowChangeMonitor implements Runnable { private IDevice device; public WindowChangeMonitor(IDevice device) { this.device = device; } public void run() { while (!Thread.currentThread().isInterrupted()) { DeviceConnection connection = null; try { connection = new DeviceConnection(this.device); connection.sendCommand("AUTOLIST"); String line; while ((!Thread.currentThread().isInterrupted()) && ((line = connection.getInputStream().readLine()) != null)) { if (line.equalsIgnoreCase("LIST UPDATE")) { } if (line.equalsIgnoreCase("FOCUS UPDATE")) { getWindowId(); } show(line); } } catch (IOException e) { } finally { if (connection != null) connection.close(); } } } public void getWindowId(){ DeviceConnection connection = null; try { connection = new DeviceConnection(this.device); connection.sendCommand("GET_FOCUS"); String line; while ((!Thread.currentThread().isInterrupted()) && ((line = connection.getInputStream().readLine()) != null)) { show(line); } } catch (IOException e) { } finally { if (connection != null) connection.close(); } } }
输出结果:
Appiot----------------LIST UPDATE Appiot----------------42180858 com.sina.weibopro/com.sina.weibopro.DetailWeiboActivity Appiot----------------FOCUS UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。