Code example for MotionEvent

Methods: getPointerCountgetXgetY

0
    private void zoom(MotionEvent event) {
        float zoomCurrentDistance = distance(event);
 
        if (onPinchListener != null) {
            onPinchListener.onPinch(zoomCurrentDistance / zoomLastDistance, //
                    new PointF(event.getX(POINTER1), event.getY(POINTER1)));
        } 
 
        zoomLastDistance = zoomCurrentDistance;
    } 
 
    private void startDrag(MotionEvent event) {
        dragLastX = event.getX(POINTER1);
        dragLastY = event.getY(POINTER1);
        onDragListener.startDrag(dragLastX, dragLastY);
    } 
 
    private void drag(MotionEvent event) {
        float dragCurrentX = event.getX(POINTER1);
        float dragCurrentY = event.getY(POINTER1);
 
        if (onDragListener != null) {
            onDragListener.onDrag(dragCurrentX - dragLastX,
                    dragCurrentY - dragLastY);
        } 
 
        dragLastX = dragCurrentX;
        dragLastY = dragCurrentY;
    } 
 
    /** Calculates the distance between the 2 current pointers */ 
    private float distance(MotionEvent event) {
        if (event.getPointerCount() < 2) {
            return 0; 
        } 
        return PointF.length(event.getX(POINTER1) - event.getX(POINTER2), //
                event.getY(POINTER1) - event.getY(POINTER2));
    } 
 
    /** 
     * Test if a MotionEvent with the given start and end offsets 
     * can be considered as a "click".