码迷,mamicode.com
首页 > 其他好文 > 详细

ViewServer接受hierarchyviewer的命令

时间:2014-06-05 01:11:43      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:hierarchyviewer   viewserver   

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


ViewServer接受hierarchyviewer的命令,布布扣,bubuko.com

ViewServer接受hierarchyviewer的命令

标签:hierarchyviewer   viewserver   

原文地址:http://blog.csdn.net/itfootball/article/details/27204447

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!