Search in sources :

Example 36 with Point

use of android.graphics.Point in project platform_frameworks_base by android.

the class UiDevice method getDisplaySizeDp.

/**
     * Returns the display size in dp (device-independent pixel)
     *
     * The returned display size is adjusted per screen rotation. Also this will return the actual
     * size of the screen, rather than adjusted per system decorations (like status bar).
     *
     * @return a Point containing the display size in dp
     */
public Point getDisplaySizeDp() {
    Tracer.trace();
    Display display = getAutomatorBridge().getDefaultDisplay();
    Point p = new Point();
    display.getRealSize(p);
    DisplayMetrics metrics = new DisplayMetrics();
    display.getRealMetrics(metrics);
    float dpx = p.x / metrics.density;
    float dpy = p.y / metrics.density;
    p.x = Math.round(dpx);
    p.y = Math.round(dpy);
    return p;
}
Also used : Point(android.graphics.Point) DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display)

Example 37 with Point

use of android.graphics.Point in project platform_frameworks_base by android.

the class UiDevice method getDisplayWidth.

/**
     * Gets the width of the display, in pixels. The width and height details
     * are reported based on the current orientation of the display.
     * @return width in pixels or zero on failure
     * @since API Level 16
     */
public int getDisplayWidth() {
    Tracer.trace();
    Display display = getAutomatorBridge().getDefaultDisplay();
    Point p = new Point();
    display.getSize(p);
    return p.x;
}
Also used : Point(android.graphics.Point) Display(android.view.Display)

Example 38 with Point

use of android.graphics.Point in project platform_frameworks_base by android.

the class UiObject method performTwoPointerGesture.

/**
     * Generates a two-pointer gesture with arbitrary starting and ending points.
     *
     * @param startPoint1 start point of pointer 1
     * @param startPoint2 start point of pointer 2
     * @param endPoint1 end point of pointer 1
     * @param endPoint2 end point of pointer 2
     * @param steps the number of steps for the gesture. Steps are injected 
     * about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.
     * @return <code>true</code> if all touch events for this gesture are injected successfully,
     *         <code>false</code> otherwise
     * @since API Level 18
     */
public boolean performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps) {
    // avoid a divide by zero
    if (steps == 0)
        steps = 1;
    final float stepX1 = (endPoint1.x - startPoint1.x) / steps;
    final float stepY1 = (endPoint1.y - startPoint1.y) / steps;
    final float stepX2 = (endPoint2.x - startPoint2.x) / steps;
    final float stepY2 = (endPoint2.y - startPoint2.y) / steps;
    int eventX1, eventY1, eventX2, eventY2;
    eventX1 = startPoint1.x;
    eventY1 = startPoint1.y;
    eventX2 = startPoint2.x;
    eventY2 = startPoint2.y;
    // allocate for steps plus first down and last up
    PointerCoords[] points1 = new PointerCoords[steps + 2];
    PointerCoords[] points2 = new PointerCoords[steps + 2];
    // Include the first and last touch downs in the arrays of steps
    for (int i = 0; i < steps + 1; i++) {
        PointerCoords p1 = new PointerCoords();
        p1.x = eventX1;
        p1.y = eventY1;
        p1.pressure = 1;
        p1.size = 1;
        points1[i] = p1;
        PointerCoords p2 = new PointerCoords();
        p2.x = eventX2;
        p2.y = eventY2;
        p2.pressure = 1;
        p2.size = 1;
        points2[i] = p2;
        eventX1 += stepX1;
        eventY1 += stepY1;
        eventX2 += stepX2;
        eventY2 += stepY2;
    }
    // ending pointers coordinates
    PointerCoords p1 = new PointerCoords();
    p1.x = endPoint1.x;
    p1.y = endPoint1.y;
    p1.pressure = 1;
    p1.size = 1;
    points1[steps + 1] = p1;
    PointerCoords p2 = new PointerCoords();
    p2.x = endPoint2.x;
    p2.y = endPoint2.y;
    p2.pressure = 1;
    p2.size = 1;
    points2[steps + 1] = p2;
    return performMultiPointerGesture(points1, points2);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Point(android.graphics.Point)

Example 39 with Point

use of android.graphics.Point in project platform_frameworks_base by android.

the class InteractionController method swipe.

/**
     * Performs a swipe between points in the Point array.
     * @param segments is Point array containing at least one Point object
     * @param segmentSteps steps to inject between two Points
     * @return true on success
     */
public boolean swipe(Point[] segments, int segmentSteps) {
    boolean ret = false;
    int swipeSteps = segmentSteps;
    double xStep = 0;
    double yStep = 0;
    // avoid a divide by zero
    if (segmentSteps == 0)
        segmentSteps = 1;
    // must have some points
    if (segments.length == 0)
        return false;
    // first touch starts exactly at the point requested
    ret = touchDown(segments[0].x, segments[0].y);
    for (int seg = 0; seg < segments.length; seg++) {
        if (seg + 1 < segments.length) {
            xStep = ((double) (segments[seg + 1].x - segments[seg].x)) / segmentSteps;
            yStep = ((double) (segments[seg + 1].y - segments[seg].y)) / segmentSteps;
            for (int i = 1; i < swipeSteps; i++) {
                ret &= touchMove(segments[seg].x + (int) (xStep * i), segments[seg].y + (int) (yStep * i));
                if (ret == false)
                    break;
                // set some known constant delay between steps as without it this
                // become completely dependent on the speed of the system and results
                // may vary on different devices. This guarantees at minimum we have
                // a preset delay.
                SystemClock.sleep(MOTION_EVENT_INJECTION_DELAY_MILLIS);
            }
        }
    }
    ret &= touchUp(segments[segments.length - 1].x, segments[segments.length - 1].y);
    return (ret);
}
Also used : Point(android.graphics.Point)

Example 40 with Point

use of android.graphics.Point in project platform_frameworks_base by android.

the class UiObject method pinchOut.

/**
     * Performs a two-pointer gesture, where each pointer moves diagonally
     * opposite across the other, from the center out towards the edges of the
     * this UiObject.
     * @param percent percentage of the object's diagonal length for the pinch gesture
     * @param steps the number of steps for the gesture. Steps are injected 
     * about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.
     * @return <code>true</code> if all touch events for this gesture are injected successfully,
     *         <code>false</code> otherwise
     * @throws UiObjectNotFoundException
     * @since API Level 18
     */
public boolean pinchOut(int percent, int steps) throws UiObjectNotFoundException {
    // make value between 1 and 100
    percent = (percent < 0) ? 1 : (percent > 100) ? 100 : percent;
    float percentage = percent / 100f;
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
    if (node == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    Rect rect = getVisibleBounds(node);
    if (rect.width() <= FINGER_TOUCH_HALF_WIDTH * 2)
        throw new IllegalStateException("Object width is too small for operation");
    // start from the same point at the center of the control
    Point startPoint1 = new Point(rect.centerX() - FINGER_TOUCH_HALF_WIDTH, rect.centerY());
    Point startPoint2 = new Point(rect.centerX() + FINGER_TOUCH_HALF_WIDTH, rect.centerY());
    // End at the top-left and bottom-right corners of the control
    Point endPoint1 = new Point(rect.centerX() - (int) ((rect.width() / 2) * percentage), rect.centerY());
    Point endPoint2 = new Point(rect.centerX() + (int) ((rect.width() / 2) * percentage), rect.centerY());
    return performTwoPointerGesture(startPoint1, startPoint2, endPoint1, endPoint2, steps);
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)1151 Display (android.view.Display)217 Rect (android.graphics.Rect)194 Paint (android.graphics.Paint)170 WindowManager (android.view.WindowManager)138 RemoteException (android.os.RemoteException)76 RectF (android.graphics.RectF)62 Bitmap (android.graphics.Bitmap)54 Resources (android.content.res.Resources)41 View (android.view.View)41 ArrayList (java.util.ArrayList)40 ImageView (android.widget.ImageView)37 Camera (android.hardware.Camera)36 Canvas (android.graphics.Canvas)31 Matrix (android.graphics.Matrix)29 Animator (android.animation.Animator)27 SuppressLint (android.annotation.SuppressLint)27 Configuration (android.content.res.Configuration)26 IOException (java.io.IOException)24 Message (android.os.Message)22