Example usage for android.view MotionEvent ACTION_MASK

List of usage examples for android.view MotionEvent ACTION_MASK

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_MASK.

Prototype

int ACTION_MASK

To view the source code for android.view MotionEvent ACTION_MASK.

Click Source Link

Document

Bit mask of the parts of the action code that are the action itself.

Usage

From source file:com.pseudosurface.levels.template.SimulatorActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    float x = event.getX();
    float y = event.getY();

    // Remember some things for zooming
    PointF start = new PointF();
    PointF mid = new PointF();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        start.set(event.getX(), event.getY());
        //          Log.d(TAG, "mode=DRAG");

        break;/*w w w  .ja  v a2 s  .c o  m*/
    case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
            midPoint(mid, event);
            mode = ZOOM;
            //             Log.d(TAG, "mode=ZOOM");
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        oldDist = -1;
        //          Log.d(TAG, "mode=NONE");
        break;
    case MotionEvent.ACTION_MOVE:

        if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > simulation.minZoom && oldDist != -1) {
                simulation.zoom -= (newDist - oldDist) * .05;
            }
            oldDist = newDist;
        } else {
            float dz = x - mPreviousX;
            float dy = y - mPreviousY;

            float r = (float) Math.sqrt(dz * dz + dy * dy);

            double theta = Math.atan2(dy, dz) + Math.PI + SimulatorActivity.angleLR;

            try {
                simulation.world.objects[simulation.world.getPlayerIndex()].omega[0] += .05f * r
                        * Math.cos(theta);
                simulation.world.objects[simulation.world.getPlayerIndex()].omega[2] += .05f * r
                        * Math.sin(theta);
            } catch (Exception e) {
            }

            //MainActivity.angleLR += dx*.01;
            //simulation.zoom += dy*.01;
        }
        break;
    }

    mPreviousX = x;
    mPreviousY = y;

    gestureDetector.onTouchEvent(event);

    return true; // indicate event was handled
}

From source file:org.cocos2dx.lib.TextInputWraper.java

public boolean onTouchEvent(final MotionEvent event) {
    // these data are used in ACTION_MOVE and ACTION_CANCEL
    final int pointerNumber = event.getPointerCount();
    final int[] ids = new int[pointerNumber];
    final float[] xs = new float[pointerNumber];
    final float[] ys = new float[pointerNumber];

    for (int i = 0; i < pointerNumber; i++) {
        ids[i] = event.getPointerId(i);/*from   w ww  .  j  a  v  a 2  s.co  m*/
        xs[i] = event.getX(i);
        ys[i] = event.getY(i);
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerDown = event.getPointerId(indexPointerDown);
        final float xPointerDown = event.getX(indexPointerDown);
        final float yPointerDown = event.getY(indexPointerDown);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
            }
        });
        break;

    case MotionEvent.ACTION_DOWN:
        // there are only one finger on the screen
        final int idDown = event.getPointerId(0);
        final float xDown = xs[0];
        final float yDown = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idDown, xDown, yDown);
            }
        });
        break;

    case MotionEvent.ACTION_MOVE:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionMove(ids, xs, ys);
            }
        });
        break;

    case MotionEvent.ACTION_POINTER_UP:
        final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerUp = event.getPointerId(indexPointUp);
        final float xPointerUp = event.getX(indexPointUp);
        final float yPointerUp = event.getY(indexPointUp);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
            }
        });
        break;

    case MotionEvent.ACTION_UP:
        // there are only one finger on the screen
        final int idUp = event.getPointerId(0);
        final float xUp = xs[0];
        final float yUp = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idUp, xUp, yUp);
            }
        });
        break;

    case MotionEvent.ACTION_CANCEL:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionCancel(ids, xs, ys);
            }
        });
        break;
    }

    if (debug) {
        dumpEvent(event);
    }
    return true;
}

From source file:net.osmand.plus.views.controls.DynamicListView.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

    if (singleTapDetector.onTouchEvent(event)) {
        if (tag != null) {
            tag.onClick();/* www .j  ava 2  s. c  om*/
        }
        touchEventsCancelled();
        return super.onTouchEvent(event);
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        if (!mCellIsMobile && mHoverCell == null) {
            // Find the view that the user pressed their finger down on.
            View v = findViewAtPositionWithDragIconTag(getRootView(), (int) event.getRawX(),
                    (int) event.getRawY());

            // If the view contains a tag set to "DragIcon" class, it means that the user wants to
            // reorder the list item.
            if ((v != null) && (v.getTag() != null) && (v.getTag() instanceof DragIcon)) {
                mDownX = (int) event.getX();
                mDownY = (int) event.getY();
                mActivePointerId = event.getPointerId(0);
                mTotalOffset = 0;
                tag = (DragIcon) v.getTag();

                int position = pointToPosition(mDownX, mDownY);
                if (position != INVALID_POSITION) {
                    Object item = getAdapter().getItem(position);
                    if (mActiveItemsList == null || mActiveItemsList.contains(item)) {

                        int itemNum = position - getFirstVisiblePosition();
                        itemsSwapped = false;

                        View selectedView = getChildAt(itemNum);
                        mMobileItemId = getAdapter().getItemId(position);
                        mHoverCell = getAndAddHoverView(selectedView);
                        selectedView.setVisibility(INVISIBLE);

                        mCellIsMobile = true;
                        updateNeighborViewsForID(mMobileItemId);

                        if (dCallbacks != null) {
                            dCallbacks.onItemSwapping(position);
                        }
                    }
                }
            }
        }
        break;

    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER_ID) {
            break;
        }

        int pointerIndex = event.findPointerIndex(mActivePointerId);

        mLastEventY = (int) event.getY(pointerIndex);
        int deltaY = mLastEventY - mDownY;

        if (mCellIsMobile && mHoverCell != null) {
            mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
                    mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
            mHoverCell.setBounds(mHoverCellCurrentBounds);
            invalidate();

            handleCellSwitch();

            mIsMobileScrolling = false;
            handleMobileCellScroll();

            return false;
        }
        break;

    case MotionEvent.ACTION_UP:
        touchEventsEnded();
        break;

    case MotionEvent.ACTION_CANCEL:
        touchEventsCancelled();
        break;

    case MotionEvent.ACTION_POINTER_UP:
        /* If a multitouch event took place and the original touch dictating
         * the movement of the hover cell has ended, then the dragging event
         * ends and the hover cell is animated to its corresponding position
         * in the listview. */
        pointerIndex = (event.getAction()
                & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = event.getPointerId(pointerIndex);
        if (pointerId == mActivePointerId) {
            touchEventsEnded();
        }
        break;

    default:
        break;
    }

    return super.onTouchEvent(event);
}

From source file:com.slushpupie.deskclock.DeskClock.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (!supportMultiTouch)
        return false;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mode = DRAG;//from ww  w .  j  a v  a2 s  . c  o  m
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
            mode = ZOOM;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
            // ..
        } else if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > 10f) {
                float scaleF = newDist / oldDist;
                int scale = (int) (scaleF * 100.0);
                if (scale < 0)
                    scale = scale * -1;
                if (scale > 100)
                    scale = 100;

                // change font size
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
                prefs.edit().putInt("pref_scale", scale).commit();
            }
        }
        break;
    }
    if (mode == ZOOM) {
        return true;
    } else {
        return false;
    }
}

From source file:com.heneryh.aquanotes.ui.controllers.GraphsFragment.java

public boolean onTouch(View arg0, MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // Start gesture
        firstFinger = new PointF(event.getX(), event.getY());
        mode = ONE_FINGER_DRAG;/*from   ww w .  j  a va2  s .  com*/
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        //When the gesture ends, a thread is created to give inertia to the scrolling and zoom 
        final Timer t = new Timer();
        t.schedule(new TimerTask() {
            @Override
            public void run() {
                while (Math.abs(lastScrolling) > 1f || Math.abs(lastZooming - 1) < 1.01) {
                    lastScrolling *= .8; //speed of scrolling damping
                    scroll(lastScrolling);
                    lastZooming += (1 - lastZooming) * .2; //speed of zooming damping
                    zoom(lastZooming);
                    checkBoundaries();
                    try {
                        mySimpleXYPlot.postRedraw();
                    } catch (final InterruptedException e) {
                        e.printStackTrace();
                    }
                    // the thread lives until the scrolling and zooming are imperceptible
                }
            }
        }, 0);

    case MotionEvent.ACTION_POINTER_DOWN: // second finger
        distBetweenFingers = spacing(event);
        // the distance check is done to avoid false alarms
        if (distBetweenFingers > 5f)
            mode = TWO_FINGERS_DRAG;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == ONE_FINGER_DRAG) {
            final PointF oldFirstFinger = firstFinger;
            firstFinger = new PointF(event.getX(), event.getY());
            lastScrolling = oldFirstFinger.x - firstFinger.x;
            scroll(lastScrolling);
            lastZooming = (firstFinger.y - oldFirstFinger.y) / mySimpleXYPlot.getHeight();
            if (lastZooming < 0)
                lastZooming = 1 / (1 - lastZooming);
            else
                lastZooming += 1;
            zoom(lastZooming);
            checkBoundaries();
            mySimpleXYPlot.redraw();

        } else if (mode == TWO_FINGERS_DRAG) {
            final float oldDist = distBetweenFingers;
            distBetweenFingers = spacing(event);
            lastZooming = oldDist / distBetweenFingers;
            zoom(lastZooming);
            checkBoundaries();
            mySimpleXYPlot.redraw();
        }
        break;
    }
    return true;
}

From source file:net.simonvt.staggeredgridview.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    velocityTracker.addMovement(ev);/*from  ww w  .  j ava2  s. co m*/
    final int action = ev.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        velocityTracker.clear();
        scroller.abortAnimation();
        lastTouchY = ev.getY();
        lastTouchX = ev.getX();
        activePointerId = ev.getPointerId(0);
        touchRemainderY = 0;
        if (touchMode == TOUCH_MODE_FLINGING) {
            // Catch!
            touchMode = TOUCH_MODE_DRAGGING;
            return true;
        }
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = ev.findPointerIndex(activePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + activePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = ev.getY(index);
        final float dy = y - lastTouchY + touchRemainderY;
        final int deltaY = (int) dy;
        touchRemainderY = dy - deltaY;

        if (Math.abs(dy) > touchSlop) {
            touchMode = TOUCH_MODE_DRAGGING;
            return true;
        }
    }
    }

    return false;
}

From source file:org.cocos2dx.lib.TextInputWraper.java

private void dumpEvent(MotionEvent event) {
    String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?",
            "9?" };
    StringBuilder sb = new StringBuilder();
    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;
    sb.append("event ACTION_").append(names[actionCode]);
    if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {
        sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
        sb.append(")");
    }/*ww  w .  j  av a 2  s . co m*/
    sb.append("[");
    for (int i = 0; i < event.getPointerCount(); i++) {
        sb.append("#").append(i);
        sb.append("(pid ").append(event.getPointerId(i));
        sb.append(")=").append((int) event.getX(i));
        sb.append(",").append((int) event.getY(i));
        if (i + 1 < event.getPointerCount())
            sb.append(";");
    }
    sb.append("]");
    Log.d(TAG, sb.toString());
}

From source file:com.xiaoyu.erbao.cctrls.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        return false;
    }//from   ww w .j ava  2s . co  m

    if (!mEnabled || !mIsDragging && !touchPointIsWithinBounds(mInitialX, mInitialY)) {
        return false;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    final int action = ev.getAction();

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialRawX = getViewX(ev);
        mLastY = mInitialRawY = getViewY(ev);
        mInitialX = ev.getX();
        mInitialY = ev.getY();
        mActivePointerId = ev.getPointerId(0);
        break;
    }

    case MotionEvent.ACTION_MOVE: {

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);

        if (!touchPointIsWithinBounds(ev.getX(), ev.getY(), false))
            return false;

        final float x = getViewX(ev);
        final float y = getViewY(ev);

        final float deltaX = mLastX - x;
        final float deltaY = mLastY - y;

        mLastX = x;
        mLastY = y;
        if (!mIsDragging) {

            final float xDiff = Math.abs(x - mInitialRawX);
            final float yDiff = Math.abs(y - mInitialRawY);

            final boolean validHorizontalDrag = xDiff > mTouchSlop && xDiff > yDiff;
            final boolean validVerticalDrag = yDiff > mTouchSlop && yDiff > xDiff;

            if (validHorizontalDrag || validVerticalDrag) {
                mIsDragging = true;
                setDrawingCacheEnabled(true);
            }
        }

        if (mIsDragging) {

            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY));
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            switch (mScreenSide) {
            case STICK_TO_LEFT:
                topBound = bottomBound = rightBound = 0;
                leftBound = getWidth(); // How far left we can scroll
                break;
            case STICK_TO_RIGHT:
                rightBound = -getWidth();
                topBound = bottomBound = leftBound = 0;
                break;
            case STICK_TO_TOP:
                topBound = getHeight();
                bottomBound = rightBound = leftBound = 0;
                break;
            case STICK_TO_BOTTOM:
                bottomBound = -(getHeight() - computeOffsetDistance());
                topBound = rightBound = leftBound = 0;
                break;
            default:
                topBound = bottomBound = rightBound = leftBound = 0;
                break;
            }

            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;

            scrollToAndNotify((int) scrollX, (int) scrollY);
        }
        break;
    }

    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();

            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = getViewX(ev);
            final float y = getViewY(ev);

            int nextState = determineNextStateForDrag(scrollX, scrollY, initialVelocityX, initialVelocityY,
                    (int) mInitialRawX, (int) mInitialRawY, (int) x, (int) y);
            setLayerState(nextState, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_VALUE;
            endDrag();

        } else if (changeStateOnTap) {
            int nextState = determineNextStateAfterTap();
            setLayerState(nextState, true, true);
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            setLayerState(mCurrentState, true, true);
            mActivePointerId = INVALID_VALUE;
            endDrag();
        }
        break;

    case MotionEvent.ACTION_POINTER_DOWN: {
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = ev.getPointerId(pointerIndex);
        mLastX = getViewX(ev);
        mLastY = getViewY(ev);
        break;

    }
    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        mLastX = getViewX(ev);
        mLastY = getViewY(ev);
        break;
    }
    }

    return true;
}

From source file:org.stockchart.StockChartView.java

private boolean handleTouchStickerEvent(MotionEvent ev) {
    int e = ev.getAction() & MotionEvent.ACTION_MASK;
    float x = ev.getX();
    float y = ev.getY();

    Plot stickerPlot = fStickerInfo.area.getPlot();

    switch (e) {//from  w w w.j ava  2s  . co  m
    case MotionEvent.ACTION_DOWN: {
        if (stickerPlot.getAbsoluteBounds().contains(x, y)) {
            double vx = fStickerInfo.area.getValueByCoordinate(fStickerInfo.sticker.getHorizontalAxis(), x,
                    true);
            double vy = fStickerInfo.area.getValueByCoordinate(fStickerInfo.sticker.getVerticalAxis(), y, true);

            switch (fStickerInfo.stickerPoint) {
            case STICKER_FIRST_POINT:
                fStickerInfo.sticker.setFirstPoint(vx, vy);
                break;
            case STICKER_SECOND_POINT:
                fStickerInfo.sticker.setSecondPoint(vx, vy);
                break;
            case STICKER_MID_POINT: {
                this.fStickerMidPoint.set(vx, vy);
                this.fStickerFirstPoint.set(fStickerInfo.sticker.getX1(), fStickerInfo.sticker.getY1());
                this.fStickerSecondPoint.set(fStickerInfo.sticker.getX2(), fStickerInfo.sticker.getY2());
            }
                break;
            default: {
                fStickerInfo.sticker.setFirstPoint(vx, vy);
                this.fCustomObjects.put(CustomObjects.STICKER, fStickerInfo);
            }
            }

            this.invalidate();
        }
    }
        break;
    case MotionEvent.ACTION_UP: {
        if (fStickerInfo.sticker.isValid() && fStickerInfo.stickerPoint == STICKER_AUTO_POINT)
            fStickerInfo.area.getStickers().add(fStickerInfo.sticker);

        this.fCustomObjects.remove(CustomObjects.STICKER);
        fStickerInfo = null;
        this.invalidate();

    }
        break;
    case MotionEvent.ACTION_MOVE: {
        RectF absoluteBounds = stickerPlot.getAbsoluteBounds();

        if (!absoluteBounds.contains(x, y)) {
            if (x < absoluteBounds.left)
                x = absoluteBounds.left;
            else if (x > absoluteBounds.right)
                x = absoluteBounds.right;

            if (y < absoluteBounds.top)
                y = absoluteBounds.top;
            else if (y > absoluteBounds.bottom)
                y = absoluteBounds.bottom;
        }

        double vx = fStickerInfo.area.getValueByCoordinate(fStickerInfo.sticker.getHorizontalAxis(), x, true);
        double vy = fStickerInfo.area.getValueByCoordinate(fStickerInfo.sticker.getVerticalAxis(), y, true);

        if (fStickerInfo.stickerPoint == STICKER_FIRST_POINT)
            fStickerInfo.sticker.setFirstPoint(vx, vy);
        else if (fStickerInfo.stickerPoint == STICKER_MID_POINT) {
            double dx = vx - this.fStickerMidPoint.x;
            double dy = vy - this.fStickerMidPoint.y;

            fStickerInfo.sticker.setFirstPoint(fStickerFirstPoint.x + dx, fStickerFirstPoint.y + dy);
            fStickerInfo.sticker.setSecondPoint(fStickerSecondPoint.x + dx, fStickerSecondPoint.y + dy);
        } else
            fStickerInfo.sticker.setSecondPoint(vx, vy);

        this.invalidate();
    }
        break;

    }

    return true;
}

From source file:com.jest.phone.PhoneActivity.java

@Override
public boolean onTouch(View arg0, MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // Start gesture
        firstFinger = new PointF(event.getX(), event.getY());
        mode = ONE_FINGER_DRAG;//from   ww w  .  j  av  a 2 s  .c  om
        stopThread = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_POINTER_DOWN: // second finger
        distBetweenFingers = spacing(event);
        // the distance check is done to avoid false alarms
        if (distBetweenFingers > 5f) {
            mode = TWO_FINGERS_DRAG;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == ONE_FINGER_DRAG) {
            PointF oldFirstFinger = firstFinger;
            firstFinger = new PointF(event.getX(), event.getY());
            scroll(oldFirstFinger.x - firstFinger.x);
            sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
            sensorHistoryPlot.redraw();

        } else if (mode == TWO_FINGERS_DRAG) {
            float oldDist = distBetweenFingers;
            distBetweenFingers = spacing(event);
            zoom(oldDist / distBetweenFingers);
            sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
            sensorHistoryPlot.redraw();
        }
        break;
    }
    return true;
}