bootstrap之Drag
来源:互联网 发布:有哪些网络兼职 编辑:程序博客网 时间:2024/05/22 05:18
Drag
package io.appium.android.bootstrap.handler;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.core.UiObjectNotFoundException;import io.appium.android.bootstrap.*;import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;import io.appium.android.bootstrap.utils.Point;import org.json.JSONException;import org.json.JSONObject;import java.util.Hashtable;/** * This handler is used to drag in the Android UI. * */public class Drag extends CommandHandler { /* * @param command The {@link AndroidCommand} used for this handler. * * @return {@link AndroidCommandResult} * * @throws JSONException * * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android. * bootstrap.AndroidCommand) */ private static class DragArguments { public AndroidElement el; public AndroidElement destEl; public final Point start; public final Point end; public final Integer steps; public DragArguments(final AndroidCommand command) throws JSONException { final Hashtable<String, Object> params = command.params(); try { if (params.get("elementId") != JSONObject.NULL) { el = command.getElement(); } } catch (final Exception e) { el = null; } try { if (params.get("destElId") != JSONObject.NULL) { destEl = command.getDestElement(); } } catch (final Exception e) { destEl = null; } start = new Point(params.get("startX"), params.get("startY")); end = new Point(params.get("endX"), params.get("endY")); steps = (Integer) params.get("steps"); } } private AndroidCommandResult drag(final DragArguments dragArgs) { Point absStartPos = new Point(); Point absEndPos = new Point(); final UiDevice device = UiDevice.getInstance(); try { absStartPos = getDeviceAbsPos(dragArgs.start); absEndPos = getDeviceAbsPos(dragArgs.end); } catch (final InvalidCoordinatesException e) { return getErrorResult(e.getMessage()); } Logger.debug("Dragging from " + absStartPos.toString() + " to " + absEndPos.toString() + " with steps: " + dragArgs.steps.toString()); final boolean rv = device.drag(absStartPos.x.intValue(), absStartPos.y.intValue(), absEndPos.x.intValue(), absEndPos.y.intValue(), dragArgs.steps); if (!rv) { return getErrorResult("Drag did not complete successfully"); } return getSuccessResult(rv); } private AndroidCommandResult dragElement(final DragArguments dragArgs) { Point absEndPos = new Point(); if (dragArgs.destEl == null) { try { absEndPos = getDeviceAbsPos(dragArgs.end); } catch (final InvalidCoordinatesException e) { return getErrorResult(e.getMessage()); } Logger.debug("Dragging the element with id " + dragArgs.el.getId() + " to " + absEndPos.toString() + " with steps: " + dragArgs.steps.toString()); try { final boolean rv = dragArgs.el.dragTo(absEndPos.x.intValue(), absEndPos.y.intValue(), dragArgs.steps); if (!rv) { return getErrorResult("Drag did not complete successfully"); } else { return getSuccessResult(rv); } } catch (final UiObjectNotFoundException e) { return getErrorResult("Drag did not complete successfully" + e.getMessage()); } } else { Logger.debug("Dragging the element with id " + dragArgs.el.getId() + " to destination element with id " + dragArgs.destEl.getId() + " with steps: " + dragArgs.steps); try { final boolean rv = dragArgs.el.dragTo(dragArgs.destEl.getUiObject(), dragArgs.steps); if (!rv) { return getErrorResult("Drag did not complete successfully"); } else { return getSuccessResult(rv); } } catch (final UiObjectNotFoundException e) { return getErrorResult("Drag did not complete successfully" + e.getMessage()); } } } @Override public AndroidCommandResult execute(final AndroidCommand command) throws JSONException { // DragArguments is created on each execute which prevents leaking state // across executions. final DragArguments dragArgs = new DragArguments(command); if (command.isElementCommand()) { return dragElement(dragArgs); } else { return drag(dragArgs); } }}
首先来看DragArguments对象。该类为Drag中的私有类,它的构造方法回去解析传入的command,然后获得并存储一些drag方法用到的参数。例如拖拽控件时,被拖拽的控件对象,拖拽到的控件对象。坐标拖拽时,起始点坐标、终点坐标、步骤。所以就把它看成一个实体类就行了。然后分控件和坐标分别调用dragElement()和drag()方法。
dragElement()
如果拖拽到的控件不存在,那么就要用到结束坐标。如果拖拽到的控件存在,那么就用该控件计算拖拽到坐标,调用UiObject.dragTo()方法来执行命令。
drag()
这个就好办了,都是坐标值,直接调用UiObject.dragTo来执行。
0 0
- bootstrap之Drag
- HTML5之drag
- drag
- Qt之drag and drop
- QTP之drag and drop
- QTP之drag and drop
- Android API之Drag&Drop
- JavaFX之Drag And Drop拖放操作
- Android翻译之---- Drag and Drop
- JavaFX之Drag And Drop拖放操作
- QT之拖拽Drag-Drop
- bootstrap之bootstrap&type样式
- GXT之旅:第八章:Portal&Drag-Drop——拖拽(Drag-Drop)基本介绍
- 第三部分:实现IDataObject(OLE drag&drop之旅)
- 第四部分:枚举FORMATETC(OLE drag&drop之旅)
- 第五部分:Drop源(OLE drag&drop之旅)
- 第三部分:实现IDataObject(OLE drag&drop之旅)
- 第四部分:枚举FORMATETC(OLE drag&drop之旅)
- ParseUtil.java
- dubbo文档
- Android网络通信框架Volley
- 兼容iOs7的自定义alertView
- SQL Server 2005与SAP R/3结合完成“TB级”应用
- bootstrap之Drag
- java读取中文分词工具(一)
- 两条线段知道端点line1(x1,y1)(x2,y2)line2(x3,y3)(x4,y4),判断两条线段是否相交,交点坐标(x,y)
- Android网络通信框架Volley
- 替换指定的字符串
- 漫游Kafka实现篇之分布式
- Android网络通信框架Volley
- --网络编程--java学习日记10(基础知识)
- 拍摄的视频数据丢失怎么办,如何恢复摄像机误删的视频