/** * Gets upper left corner. * * @return the upper left corner of the bounds */ public Point getUpperLeftCorner() { return new Point(upperLeftCorner); }
/** * Sets upper left corner. * * @param upperLeftCorner * - the upper left corner of the bounds */ public void setUpperLeftCorner(Point upperLeftCorner) { this.upperLeftCorner = new Point(upperLeftCorner); }
/** * Creates new Bounds instance given upper left corner, width and height. * * @param upperLeftCorner * - the upper left corner of the bounds * @param width * - the width of the bounds * @param height * - the height of the bounds */ public Bounds(Point upperLeftCorner, int width, int height) { this.upperLeftCorner = new Point(upperLeftCorner); this.width = width; this.height = height; }
@Override public Bounds getBounds() { Point upperLeft = new Point(bounds.left, bounds.top); // As Bounds are initially constructed with width and height int width = bounds.right - bounds.left; int height = bounds.bottom - bounds.top; return new Bounds(upperLeft, width, height); } }
/** * Gets lower right corner. * * @return the lower right corner of the bounds */ public Point getLowerRightCorner() { int lowerRightCornerX = upperLeftCorner.getX() + width; int lowerRightCornerY = upperLeftCorner.getY() + height; Point lowerRightCorner = new Point(lowerRightCornerX, lowerRightCornerY); return lowerRightCorner; }
/** * Gets upper right corner. * * @return the upper right corner of the bounds */ public Point getUpperRightCorner() { int upperRightCornerX = upperLeftCorner.getX() + width; int upperRightCornerY = upperLeftCorner.getY(); Point upperRightCorner = new Point(upperRightCornerX, upperRightCornerY); return upperRightCorner; }
/** * Gets bounds center. * * @return the center point of the bounds */ public Point getCenter() { int centerX = upperLeftCorner.getX() + width / 2; int centerY = upperLeftCorner.getY() + height / 2; Point center = new Point(centerX, centerY); return center; }
/** * Gets lower left corner. * * @return the lower left corner of the bounds */ public Point getLowerLeftCorner() { int lowerLeftCornerX = upperLeftCorner.getX(); int lowerLeftCornerY = upperLeftCorner.getY() + height; Point lowerLeftCorner = new Point(lowerLeftCornerX, lowerLeftCornerY); return lowerLeftCorner; }
public void tapScreen(String deviceSerialNumber, int x, int y) { getDevice(deviceSerialNumber); Point tapPoint = new Point(x, y); device.tapScreenLocation(tapPoint); releaseDevice(); }
/** * Calculates the coordinates of a vector with start point A and end point B. * * @param pointA * - start point of the vector. * @param pointB * - end point of the vector. * @return the coordinates of a vector with start point A and end point B. */ public static Point getVector(Point pointA, Point pointB) { int vectorX = pointB.getX() - pointA.getX(); int vectorY = pointB.getY() - pointA.getY(); Point vector = new Point(vectorX, vectorY); return vector; }
/** * Gets the given point equivalent relative to the bounds upper left corner. * * @param point * - a {@link Point} for which to get the point equivalent relative to the bounds upper left corner * @return the point equivalent relative to the bounds upper left corner */ public Point getRelativePoint(Point point) { int relativePointX = point.getX() - upperLeftCorner.getX(); int relativePointY = point.getY() - upperLeftCorner.getY(); Point relativePoint = new Point(relativePointX, relativePointY); return relativePoint; }
/** * Creates new Bounds instance given upper left and lower right corners. * * @param upperLeftCorner * - the upper left corner of the bounds * @param lowerRightCorner * - the lower left corner of the bounds */ public Bounds(Point upperLeftCorner, Point lowerRightCorner) { int calculatedWidth = lowerRightCorner.getX() - upperLeftCorner.getX(); int calculatedHeight = lowerRightCorner.getY() - upperLeftCorner.getY(); this.upperLeftCorner = new Point(upperLeftCorner); this.width = calculatedWidth; this.height = calculatedHeight; }
/** * Simulates a pinch in on the element. NOTE emulator devices may not detect pinch gestures on UI elements with size * smaller than 100x100dp. * * @return <code>true</code> if the pinch in is successful, <code>false</code> if it fails * @throws StaleElementReferenceException * if the element has become stale before executing this method */ public boolean pinchIn() { revalidateThrowing(); Bounds elementBounds = propertiesContainer.getBounds(); final int BOUNDS_OFFSET_DENOMINATOR = 10; final int WIDTH_OFFSET = elementBounds.getWidth() / BOUNDS_OFFSET_DENOMINATOR; final int HEIGHT_OFFSET = elementBounds.getHeight() / BOUNDS_OFFSET_DENOMINATOR; // starting the pinch at a distance from the exact bounds of the element so that it will not affect other UI // elements Point lowerRight = elementBounds.getLowerRightCorner(); int firstFingerInitialX = lowerRight.getX() - WIDTH_OFFSET; int firstFingerInitialY = lowerRight.getY() - HEIGHT_OFFSET; Point firstFingerInitial = new Point(firstFingerInitialX, firstFingerInitialY); Point upperLeft = elementBounds.getUpperLeftCorner(); int secondFingerInitialX = upperLeft.getX() + WIDTH_OFFSET; int secondFingerInitialY = upperLeft.getY() + HEIGHT_OFFSET; Point secondFingerInitial = new Point(secondFingerInitialX, secondFingerInitialY); boolean result = (boolean) communicator.sendAction(RoutingAction.GESTURE_PINCH_IN, firstFingerInitial, secondFingerInitial); return result; }
protected void setCommonProperties(AccessibilityNodeInfo nodeInfo, AccessibilityElement element, int index) { element.setText(CharSequenceUtils.getString(nodeInfo.getText())); element.setClassName(CharSequenceUtils.getString(nodeInfo.getClassName())); element.setPackageName(CharSequenceUtils.getString(nodeInfo.getPackageName())); element.setContentDescriptor(CharSequenceUtils.getString(nodeInfo.getContentDescription())); element.setChechkable(nodeInfo.isCheckable()); element.setChechked(nodeInfo.isChecked()); element.setClickable(nodeInfo.isClickable()); element.setEnabled(nodeInfo.isEnabled()); element.setFocusable(nodeInfo.isFocusable()); element.setFocused(nodeInfo.isFocused()); element.setScrollable(nodeInfo.isScrollable()); element.setLongClickable(nodeInfo.isLongClickable()); element.setPassword(nodeInfo.isPassword()); element.setSelected(nodeInfo.isSelected()); element.setIndex(index); Rect boundsRect = new Rect(); nodeInfo.getBoundsInScreen(boundsRect); Point topLeft = new Point(boundsRect.left, boundsRect.top); Point bottomRight = new Point(boundsRect.right, boundsRect.bottom); Bounds bounds = new Bounds(topLeft, bottomRight); element.setBounds(bounds); }