Example usage for android.view MotionEvent getPointerId

List of usage examples for android.view MotionEvent getPointerId

Introduction

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

Prototype

public final int getPointerId(int pointerIndex) 

Source Link

Document

Return the pointer identifier associated with a particular pointer data index in this event.

Usage

From source file:de.tobiasbielefeld.solitaire.ui.GameManager.java

public boolean onTouch(View v, MotionEvent event) {
    /*/*from   w ww.  j av  a  2s .co m*/
     * handle input like touching cards and stacks and moving cards around
     */

    //if something important happens don't accept input
    if (stopConditions())
        return true;

    //also don't do anything with a second touch point
    if (event.getPointerId(0) != 0) {
        if (movingCards.hasCards())
            movingCards.returnToPos();

        return true;
    }

    float X = event.getX() + v.getX(), Y = event.getY() + v.getY();

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (currentGame.hasMainStack() && currentGame.testIfMainStackTouched(X, Y)) {

            if (currentGame.hasLimitedRedeals() && currentGame.dealFromStack().isEmpty()) {
                if (currentGame.getRemainingNumberOfRedeals() == 0)
                    return true;
                else
                    currentGame.incrementRedealCounter(this);
            }

            currentGame.onMainStackTouch();
        } else if (cards[v.getId()].isUp()) {//&& currentGame.addCardToMovementTest(cards[v.getId()])) {

            if (getSharedBoolean("pref_key_double_tap_enable", true)) {
                if (tappedStack != null && tappedStack == cards[v.getId()].getStack()
                        && System.currentTimeMillis() - firstTapTime < doubleTapSpeed) {

                    CardAndStack cardAndStack = null;

                    if (getSharedBoolean("pref_key_double_tap_all_cards", true)
                            && cards[v.getId()].getStack().getID() <= currentGame.getLastTableauID()) {
                        cardAndStack = currentGame.doubleTap(cards[v.getId()].getStack());
                    } else if (currentGame.addCardToMovementTest(cards[v.getId()])) {
                        cardAndStack = currentGame.doubleTap(cards[v.getId()]);
                    }

                    if (cardAndStack != null) {
                        movingCards.add(cardAndStack.getCard(), event.getX(), event.getY());
                        movingCards.moveToDestination(cardAndStack.getStack());
                        tappedStack = null;
                        return true;
                    }

                } else {
                    tappedStack = cards[v.getId()].getStack();
                    firstTapTime = System.currentTimeMillis();
                }
            }

            if (currentGame.addCardToMovementTest(cards[v.getId()])) {
                movingCards.add(cards[v.getId()], event.getX(), event.getY());
            }
        }
    } else if (event.getAction() == MotionEvent.ACTION_MOVE && movingCards.hasCards()) {
        movingCards.move(X, Y);
    } else if (event.getAction() == MotionEvent.ACTION_UP && movingCards.hasCards()) {
        for (Stack stack : stacks) {
            if (stack.isOnLocation(X, Y) && movingCards.first().getStack() != stack
                    && movingCards.first().test(stack)) {
                movingCards.moveToDestination(stack);
                return true;
            }
        }

        //if they aren't placed, return them to their old places
        movingCards.returnToPos();
    }
    return true;
}

From source file:individual.leobert.calendar.CalendarLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    //        mViewDragHelper.shouldInterceptTouchEvent(ev);
    boolean isflag = false;

    //?// www .ja  v a2 s.co m
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        oy = ev.getY();
        ox = ev.getX();
        isClickBtottomView = isClickView(view2, ev);
        cancel();
        activitPotionerId = ev.getPointerId(0);

        int top = view2.getTop();

        if (top < topHeigth) {
            type = TYPE_FOLD;
        } else {
            type = TYPE_OPEN;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        float y = ev.getY();
        float x = ev.getX();

        float xdiff = x - ox;
        float ydiff = y - oy;

        if (Math.abs(ydiff) > 5 && Math.abs(ydiff) > Math.abs(xdiff)) {
            isflag = true;

            if (isClickBtottomView) {
                boolean isScroll = isScroll(view2);
                if (ydiff > 0) {
                    //?
                    if (type == TYPE_OPEN) {
                        return super.onInterceptTouchEvent(ev);
                    } else {
                        if (isScroll) {
                            return super.onInterceptTouchEvent(ev);
                        }

                    }
                } else {
                    //?
                    if (type == TYPE_FOLD) {
                        return super.onInterceptTouchEvent(ev);
                    } else {
                        if (isScroll) {
                            return super.onInterceptTouchEvent(ev);
                        }
                    }
                }

            }
        }
        ox = x;
        oy = y;
        break;
    case MotionEvent.ACTION_UP:

        break;
    }
    return isSilde || isflag || super.onInterceptTouchEvent(ev);
}

From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java

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

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = (int) event.getX();
        mDownY = (int) event.getY();
        mActivePointerId = event.getPointerId(0);
        break;/*www. j av a2  s.co  m*/
    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == NOT_FOUND) {
            break;
        }

        int pointerIndex = event.findPointerIndex(mActivePointerId);

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

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

            handleCellSwitch();

            mIsMobileScrolling = false;
            handleMobileCellScroll();

            return false;
        }
        break;
    case MotionEvent.ACTION_UP:
        touchEventsEnded();
        setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        ((LayersListAdapter) getAdapter()).notifyDataChanged();
        break;
    case MotionEvent.ACTION_CANCEL:
        touchEventsCancelled();
        setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        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();
        }
        setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        break;
    default:
        break;
    }

    return super.onTouchEvent(event);
}

From source file:com.commonsware.cwac.crossport.design.widget.HeaderBehavior.java

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//from  w  w w .  j  a  v a2  s  . c  om

    switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();

        if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        } else {
            return false;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
        if (activePointerIndex == -1) {
            return false;
        }

        final int y = (int) ev.getY(activePointerIndex);
        int dy = mLastMotionY - y;

        if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) {
            mIsBeingDragged = true;
            if (dy > 0) {
                dy -= mTouchSlop;
            } else {
                dy += mTouchSlop;
            }
        }

        if (mIsBeingDragged) {
            mLastMotionY = y;
            // We're being dragged so scroll the ABL
            scroll(parent, child, dy, getMaxDragOffset(child), 0);
        }
        break;
    }

    case MotionEvent.ACTION_UP:
        if (mVelocityTracker != null) {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);
            float yvel = mVelocityTracker.getYVelocity(mActivePointerId);
            fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
        }
        // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return true;
}

From source file:android.support.design.widget.HeaderBehavior.java

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//from w ww .ja v  a2  s  .  co  m

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();

        if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        } else {
            return false;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
        if (activePointerIndex == -1) {
            return false;
        }

        final int y = (int) ev.getY(activePointerIndex);
        int dy = mLastMotionY - y;

        if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) {
            mIsBeingDragged = true;
            if (dy > 0) {
                dy -= mTouchSlop;
            } else {
                dy += mTouchSlop;
            }
        }

        if (mIsBeingDragged) {
            mLastMotionY = y;
            // We're being dragged so scroll the ABL
            scroll(parent, child, dy, getMaxDragOffset(child), 0);
        }
        break;
    }

    case MotionEvent.ACTION_UP:
        if (mVelocityTracker != null) {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);
            float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
            fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
        }
        // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return true;
}

From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = (int) event.getX();
        mDownY = (int) event.getY();
        mActivePointerId = event.getPointerId(0);
        break;/*from   w ww  .j a va  2s.co m*/
    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) {
            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:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = ev.getActionIndex();
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mInitialTouchX = ev.getX(newPointerIndex);
        mInitialTouchY = mLastTouchY = ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }//from ww w. j a  v a2s. com
}

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);
        xs[i] = event.getX(i);/*  w w w .  j a va 2 s  .c om*/
        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:com.example.customview.DynamicListView.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mDownX = (int) event.getX();
        mDownY = (int) event.getY();
        mActivePointerId = event.getPointerId(0);
        break;/*from ww  w . j av  a2s. c o m*/
    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) {
            mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
                    mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
            mHoverCell.setBounds(mHoverCellCurrentBounds);
            invalidate();

            handleCellSwitch();

            mIsMobileScrolling = false;
            handleMobileCellScroll();

            return false;
        }
        break;
    case MotionEvent.ACTION_UP:
        touchEventsEnded();
        drawLayoutSetUnlock();
        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();
        }
        drawLayoutSetUnlock();
        break;
    default:
        break;
    }

    return super.onTouchEvent(event);
}

From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mPreviousX = ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();//from  w  ww .  j  a  v  a 2  s  . c o m
        }
    }
}