Example usage for android.view MotionEvent ACTION_POINTER_DOWN

List of usage examples for android.view MotionEvent ACTION_POINTER_DOWN

Introduction

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

Prototype

int ACTION_POINTER_DOWN

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

Click Source Link

Document

Constant for #getActionMasked : A non-primary pointer has gone down.

Usage

From source file:com.cloverstudio.spika.CameraCropActivity.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);/*  ww w .  j  a va2s.  co m*/
        start.set(event.getX(), event.getY());
        mode = DRAG;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
            // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
            start_x = event.getX() - start.x;
            start_y = event.getY() - start.y;
        } else if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > 10f) {
                matrix.set(savedMatrix);
                float scale = newDist / oldDist;
                mAspect = scale;
                matrix.postScale(scale, scale, mid.x, mid.y);
            }
        }
        break;
    }

    view.setImageMatrix(matrix);
    view.invalidate();
    return true;
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        multipleFingersCountingTime = false;
        multipleFingersStartTime = 0L;//from w w  w  .j a va 2 s .  c  om
        multipleFingersTime = 0L;
        break;
    }
    case MotionEvent.ACTION_POINTER_DOWN: {
        if (!multipleFingersCountingTime) {
            multipleFingersCountingTime = true;
            multipleFingersStartTime = System.currentTimeMillis();
        }
        break;
    }
    case MotionEvent.ACTION_POINTER_UP: {
        if (event.getPointerCount() <= 2) {
            if (multipleFingersCountingTime) {
                multipleFingersCountingTime = false;
                multipleFingersTime += System.currentTimeMillis() - multipleFingersStartTime;
            }
        }
        break;
    }
    }
    return false;
}

From source file:eu.hydrologis.geopaparazzi.chart.ProfileChartActivity.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  ava 2s . c  o  m*/
        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());
            scrollElev(oldFirstFinger.x - firstFinger.x);
            scrollSpeed(oldFirstFinger.x - firstFinger.x);
            xyPlotSpeed.setDomainBoundaries(minXYSpeed.x, maxXYSpeed.x, BoundaryMode.FIXED);
            xyPlotElev.setDomainBoundaries(minXYElevation.x, maxXYElevation.x, BoundaryMode.FIXED);
            xyPlotSpeed.redraw();
            xyPlotElev.redraw();

        } else if (mode == TWO_FINGERS_DRAG) {
            float oldDist = distBetweenFingers;
            distBetweenFingers = spacing(event);
            zoomElev(oldDist / distBetweenFingers);
            zoomSpeed(oldDist / distBetweenFingers);
            xyPlotSpeed.setDomainBoundaries(minXYSpeed.x, maxXYSpeed.x, BoundaryMode.FIXED);
            xyPlotElev.setDomainBoundaries(minXYElevation.x, maxXYElevation.x, BoundaryMode.FIXED);
            xyPlotSpeed.redraw();
            xyPlotElev.redraw();
        }
        break;
    }
    return true;
}

From source file:org.protocoderrunner.apprunner.AppRunnerActivity.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {

    int action = event.getAction();
    int actionCode = event.getActionMasked();

    ArrayList<PPadView.TouchEvent> t = new ArrayList<PPadView.TouchEvent>();

    // check finger if down or up
    if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {

    }//w  w w . ja va2s .c o m

    if (event.getSource() == MotionEvent.TOOL_TYPE_MOUSE) {
        // if (event.getButtonState() == ac) {

        // }
    }

    // get positions per finger
    for (int i = 0; i < event.getPointerCount(); i++) {
        // TouchEvent o = new TouchEvent("finger", event.getPointerId(i),
        // action, (int) event.getX(),
        // (int) event.getY());
        // t.add(o);
    }

    //
    // FINGER 1 UP x y
    // FINGER 2 MOVE x y
    // MOUSE 3 MOVE x y

    // return touching;
    return super.onGenericMotionEvent(event);
}

From source file:org.stockchart.StockChartView.java

private boolean handleTouchEvent(MotionEvent ev) {
    int e = ev.getAction() & MotionEvent.ACTION_MASK;

    switch (e) {//  w w w.  j  a  va  2s . c  om
    case MotionEvent.ACTION_DOWN: {
        fMode = TouchMode.DRAG;
        fDragStartPoint.set(ev.getX(), ev.getY());
    }
        break;
    case MotionEvent.ACTION_POINTER_DOWN: {
        fOldDist = getSpacing(ev);

        if (fOldDist > 10)
            fMode = TouchMode.ZOOM;
    }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP: {
        if (e == MotionEvent.ACTION_UP) {
            if (!fTouchEventHandled)
                this.onTouchEventUp(ev);

            fTouchEventHandled = false;
        }

        if (fMode == TouchMode.DRAG)
            processCrosshair(ev.getX(), ev.getY());

        fMode = TouchMode.NONE;
    }
        break;
    case MotionEvent.ACTION_MOVE: {

        if (TouchMode.ZOOM == fMode) {
            float newDist = getSpacing(ev);

            if (newDist > 10f) {
                float scale = newDist - fOldDist;

                this.zoom(inPercentsOfWidth(scale), inPercentsOfHeight(scale));

                invalidate();
                fTouchEventHandled = true;
            }

        } else if (TouchMode.DRAG == fMode) {
            float dx = fDragStartPoint.x - ev.getX();
            float dy = ev.getY() - fDragStartPoint.y;

            if (dx != 0f || dy != 0f) {
                this.move(inPercentsOfWidth(dx), inPercentsOfHeight(dy));

                invalidate();
                fTouchEventHandled = true;
            }
        }

        processCrosshair(ev.getX(), ev.getY());
    }
        break;

    }

    return true;
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (controlling) {
        velocityTracker.addMovement(event);
        velocityTracker.computeCurrentVelocity(1);

        boolean down = event.getActionMasked() == MotionEvent.ACTION_DOWN
                || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
        boolean up = event.getActionMasked() == MotionEvent.ACTION_UP
                || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP;
        Finger[] fingers = new Finger[event.getPointerCount()];
        for (int i = 0; i < event.getPointerCount(); i++) {
            fingers[i] = new Finger(event.getPointerId(i), event.getX(i), event.getY(i),
                    velocityTracker.getXVelocity(i), velocityTracker.getYVelocity(i),
                    !(event.getActionIndex() == i && up));
        }// w w w. j  ava  2s  .  c  om

        FingerMessage<?> message = up ? new UpMessage(fingers)
                : down ? new DownMessage(fingers) : new MoveMessage(fingers);
        communicator.sendMessage(message);
    }
    return super.onTouchEvent(event);
}

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;
    }//w  w  w .j  a va2 s  .c om

    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:com.example.piechart3d.PieChart3DView.java

@SuppressLint("NewApi")
@Override//www.  j  av  a2  s  .co  m
public boolean onTouchEvent(MotionEvent event) {
    getParent().requestDisallowInterceptTouchEvent(true);
    float xxx = event.getX() - centerx;
    float yyy = event.getY() - centery;

    {
        mDetector.onTouchEvent(event);
        String direction;
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case (MotionEvent.ACTION_DOWN):
            if (mZAnimator != null)
                mZAnimator.cancel();
            iniMAngle = (float) java.lang.Math.atan2(yyy, xxx);
            inix = mRenderer.angle_x;
            iniz = mRenderer.angle_z;
            x1 = event.getX();
            y1 = event.getY();
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            iniMAngle = (float) java.lang.Math.atan2(yyy, xxx);
            Log.d("appAS", "Pointer down");
            inix = mRenderer.angle_x;
            iniz = mRenderer.angle_z;
            d = rotation(event);
            break;
        case MotionEvent.ACTION_POINTER_UP:
            inix = mRenderer.angle_x;
            iniz = mRenderer.angle_z;
            iniMAngle = (float) java.lang.Math.atan2(yyy, xxx);
            break;
        case (MotionEvent.ACTION_MOVE): {
            if (event.getPointerCount() == 1) {
                x2 = event.getX();
                y2 = event.getY();
                dx = x2 - x1;
                dy = y2 - y1;
                if (Math.abs(dx) < Math.abs(dy) && Math.abs(dy) > 25) {
                    iniz = mRenderer.angle_z;
                    if (dy > 0)
                        direction = "down";
                    else
                        direction = "up";
                    this.requestDoRender(inix - (dy / 3), iniz);
                } else {
                    mAngle = (float) java.lang.Math.atan2(yyy, xxx);
                    inix = mRenderer.angle_x;
                    if (dx > 0)
                        direction = "right";
                    else
                        direction = "left";
                    this.requestDoRender(inix, /* iniz + (dx / 3) */
                            iniz + (float) Math.toDegrees((mAngle - iniMAngle)));
                    Log.d("ang", "" + iniz + " " + (iniz + (float) Math.toDegrees((mAngle - iniMAngle))));
                }
            } else if (event.getPointerCount() == 2) {
                Log.d("app", "Rotating " + event.getPointerCount());
                float rot = rotation(event) - d;
                this.requestDoRender(inix, iniz + rot);
            }
        }
        }
    }
    return true;
}

From source file:it.mb.whatshare.Utils.java

/**
 * Returns a string that represents the symbolic name of the specified
 * action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent
 * numeric constant such as "35" if unknown. By Google.
 * //from   w  ww  .j  a  v  a  2 s .  c o  m
 * @param action
 *            The action.
 * @return The symbolic name of the specified action.
 */
public static String actionToString(int action) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "ACTION_DOWN";
    case MotionEvent.ACTION_UP:
        return "ACTION_UP";
    case MotionEvent.ACTION_CANCEL:
        return "ACTION_CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "ACTION_OUTSIDE";
    case MotionEvent.ACTION_MOVE:
        return "ACTION_MOVE";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "ACTION_HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "ACTION_SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "ACTION_HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "ACTION_HOVER_EXIT";
    }
    int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        return "ACTION_POINTER_DOWN(" + index + ")";
    case MotionEvent.ACTION_POINTER_UP:
        return "ACTION_POINTER_UP(" + index + ")";
    default:
        return Integer.toString(action);
    }
}

From source file:com.hippo.widget.BothScrollView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*//w w  w .ja  va 2  s  . c o  m
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    /*
    * Shortcut the most recurring case: the user is in the dragging
    * state and he is moving his finger.  We want to intercept this
    * motion.
    */
    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) {
        return true;
    }

    /*
     * Don't try to intercept touch if we can't scroll anyway.
     */
    if (getScrollX() == 0 && !canScrollHorizontally(1) && getScrollY() == 0 && !canScrollVertically(1)) {
        return false;
    }

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
         * whether the user has moved far enough from his original down touch.
         */

        /*
        * Locally do absolute value. mLastMotionY is set to the y value
        * of the down event.
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }

        final int pointerIndex = ev.findPointerIndex(activePointerId);
        if (pointerIndex == -1) {
            Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent");
            break;
        }

        final int x = (int) ev.getX(pointerIndex);
        final int y = (int) ev.getY(pointerIndex);
        final int xDiff = Math.abs(x - mLastMotionX);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (xDiff > mTouchSlop || yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionX = x;
            mLastMotionY = y;
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            final ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }

        break;
    }

    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (!inChild(x, y)) {
            mIsBeingDragged = false;
            recycleVelocityTracker();
            break;
        }

        /*
         * Remember location of down touch.
         * ACTION_DOWN always refers to pointer index 0.
         */
        mLastMotionX = x;
        mLastMotionY = y;
        mActivePointerId = ev.getPointerId(0);

        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);

        /*
        * If being flinged and user touches the screen, initiate drag;
        * otherwise don't.  mScroller.isFinished should be false when
        * being flinged.
        */
        mIsBeingDragged = !mScroller.isFinished();
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        /* Release the drag */
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mScroller.springBack(getScrollX(), getScrollY(), 0, getHorizontalScrollRange(), 0,
                getVerticalScrollRange())) {
            ViewCompat.postInvalidateOnAnimation(this);
        }
        break;
    case MotionEvent.ACTION_POINTER_DOWN: {
        final int index = ev.getActionIndex();
        mLastMotionX = (int) ev.getX(index);
        mLastMotionY = (int) ev.getY(index);
        mActivePointerId = ev.getPointerId(index);
        break;
    }
    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        final int index = ev.findPointerIndex(mActivePointerId);
        mLastMotionX = (int) ev.getX(index);
        mLastMotionY = (int) ev.getY(index);
        break;
    }

    /*
    * The only time we want to intercept motion events is if we are in the
    * drag mode.
    */
    return mIsBeingDragged;
}