FileDocCategorySizeDatePackage
GestureUtils.javaAPI DocAndroid 5.1 API3932Thu Mar 12 22:22:42 GMT 2015com.android.server.accessibility

GestureUtils

public final class GestureUtils extends Object
Some helper functions for gesture detection.

Fields Summary
Constructors Summary
private GestureUtils()

        /* cannot be instantiated */
    
Methods Summary
public static doublecomputeDistance(android.view.MotionEvent first, android.view.MotionEvent second, int pointerIndex)

         return MathUtils.dist(first.getX(pointerIndex), first.getY(pointerIndex),
                 second.getX(pointerIndex), second.getY(pointerIndex));
    
private static booleaneventsWithinTimeAndDistanceSlop(android.view.MotionEvent first, android.view.MotionEvent second, int timeout, int distance, int actionIndex)

        if (isTimedOut(first, second, timeout)) {
            return false;
        }
        final double deltaMove = computeDistance(first, second, actionIndex);
        if (deltaMove >= distance) {
            return false;
        }
        return true;
    
public static booleanisDraggingGesture(float firstPtrDownX, float firstPtrDownY, float secondPtrDownX, float secondPtrDownY, float firstPtrX, float firstPtrY, float secondPtrX, float secondPtrY, float maxDraggingAngleCos)
Determines whether a two pointer gesture is a dragging one.

param
event The event with the pointer data.
return
True if the gesture is a dragging one.


        // Check if the pointers are moving in the same direction.
        final float firstDeltaX = firstPtrX - firstPtrDownX;
        final float firstDeltaY = firstPtrY - firstPtrDownY;

        if (firstDeltaX == 0 && firstDeltaY == 0) {
            return true;
        }

        final float firstMagnitude =
            (float) Math.sqrt(firstDeltaX * firstDeltaX + firstDeltaY * firstDeltaY);
        final float firstXNormalized =
            (firstMagnitude > 0) ? firstDeltaX / firstMagnitude : firstDeltaX;
        final float firstYNormalized =
            (firstMagnitude > 0) ? firstDeltaY / firstMagnitude : firstDeltaY;

        final float secondDeltaX = secondPtrX - secondPtrDownX;
        final float secondDeltaY = secondPtrY - secondPtrDownY;

        if (secondDeltaX == 0 && secondDeltaY == 0) {
            return true;
        }

        final float secondMagnitude =
            (float) Math.sqrt(secondDeltaX * secondDeltaX + secondDeltaY * secondDeltaY);
        final float secondXNormalized =
            (secondMagnitude > 0) ? secondDeltaX / secondMagnitude : secondDeltaX;
        final float secondYNormalized =
            (secondMagnitude > 0) ? secondDeltaY / secondMagnitude : secondDeltaY;

        final float angleCos =
            firstXNormalized * secondXNormalized + firstYNormalized * secondYNormalized;

        if (angleCos < maxDraggingAngleCos) {
            return false;
        }

        return true;
    
public static booleanisMultiTap(android.view.MotionEvent firstUp, android.view.MotionEvent secondUp, int multiTapTimeSlop, int multiTapDistanceSlop, int actionIndex)

        return eventsWithinTimeAndDistanceSlop(firstUp, secondUp, multiTapTimeSlop,
                multiTapDistanceSlop, actionIndex);
    
public static booleanisSamePointerContext(android.view.MotionEvent first, android.view.MotionEvent second)

        return (first.getPointerIdBits() == second.getPointerIdBits()
                && first.getPointerId(first.getActionIndex())
                        == second.getPointerId(second.getActionIndex()));
    
public static booleanisTap(android.view.MotionEvent down, android.view.MotionEvent up, int tapTimeSlop, int tapDistanceSlop, int actionIndex)

        return eventsWithinTimeAndDistanceSlop(down, up, tapTimeSlop, tapDistanceSlop, actionIndex);
    
public static booleanisTimedOut(android.view.MotionEvent firstUp, android.view.MotionEvent secondUp, int timeout)

        final long deltaTime = secondUp.getEventTime() - firstUp.getEventTime();
        return (deltaTime >= timeout);