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.github.barteksc.pdfviewpager.view.ScrollBar.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_POINTER_DOWN:
        float y = event.getY();
        if (y < 0 || y > getHeight())
            return true;

        int pageNum = (int) Math.floor(y / handleHeight);

        float handleY = pageNum * handleHeight;
        if (handleY < 0) {
            handleY = 0;/*w w w .ja  v  a2s  .co m*/
        } else if (y + handleHeight / 2 > getHeight()) {
            handleY = getHeight() - handleHeight;
        }
        handlePos.y = handleY;

        if (pageNum != currentPage) {
            indicator.setPageNum(pageNum + 1);
        }
        currentPage = pageNum;
        indicator.setVisibility(VISIBLE);
        indicator.setScroll(handleY);
        invalidate();
        return true;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        int pgNum = (int) Math.floor(event.getY() / handleHeight);
        programmaticPageChangeLocked = true;
        viewPager.setCurrentItem(pgNum);
        currentPage = pgNum;
        indicator.setVisibility(INVISIBLE);
        invalidate();
        return true;
    }

    return super.onTouchEvent(event);
}

From source file:it.sephiroth.android.library.imagezoom.ScaleGestureDetector.java

public boolean onTouchEvent(final MotionEvent event) {
    final int action = event.getAction();
    final boolean handled = true;

    if (!mGestureInProgress) {
        switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_DOWN: {
            // We have a new multi-finger gesture

            // as orientation can change, query the metrics in touch
            // down
            final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
            mRightSlopEdge = metrics.widthPixels - mEdgeSlop;
            mBottomSlopEdge = metrics.heightPixels - mEdgeSlop;

            // Be paranoid in case we missed an event
            reset();// w  w w .ja va  2 s.  c om

            mPrevEvent = MotionEvent.obtain(event);
            mTimeDelta = 0;

            setContext(event);

            // Check if we have a sloppy gesture. If so, delay
            // the beginning of the gesture until we're sure that's
            // what the user wanted. Sloppy gestures can happen if the
            // edge of the user's hand is touching the screen, for
            // example.
            final float edgeSlop = mEdgeSlop;
            final float rightSlop = mRightSlopEdge;
            final float bottomSlop = mBottomSlopEdge;
            final float x0 = event.getRawX();
            final float y0 = event.getRawY();
            final float x1 = getRawX(event, 1);
            final float y1 = getRawY(event, 1);

            final boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop || x0 > rightSlop || y0 > bottomSlop;
            final boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > rightSlop || y1 > bottomSlop;

            if (p0sloppy && p1sloppy) {
                mFocusX = -1;
                mFocusY = -1;
                mSloppyGesture = true;
            } else if (p0sloppy) {
                mFocusX = MotionEventCompat.getX(event, 1);
                mFocusY = MotionEventCompat.getY(event, 1);
                mSloppyGesture = true;
            } else if (p1sloppy) {
                mFocusX = MotionEventCompat.getX(event, 0);
                mFocusY = MotionEventCompat.getY(event, 0);
                mSloppyGesture = true;
            } else {
                mGestureInProgress = mListener.onScaleBegin(this);
            }
        }
            break;

        case MotionEvent.ACTION_MOVE:
            if (mSloppyGesture) {
                // Initiate sloppy gestures if we've moved outside of
                // the slop area.
                final float edgeSlop = mEdgeSlop;
                final float rightSlop = mRightSlopEdge;
                final float bottomSlop = mBottomSlopEdge;
                final float x0 = event.getRawX();
                final float y0 = event.getRawY();
                final float x1 = getRawX(event, 1);
                final float y1 = getRawY(event, 1);

                final boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop || x0 > rightSlop || y0 > bottomSlop;
                final boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > rightSlop || y1 > bottomSlop;

                if (p0sloppy && p1sloppy) {
                    mFocusX = -1;
                    mFocusY = -1;
                } else if (p0sloppy) {
                    mFocusX = MotionEventCompat.getX(event, 1);
                    mFocusY = MotionEventCompat.getY(event, 1);
                } else if (p1sloppy) {
                    mFocusX = MotionEventCompat.getX(event, 0);
                    mFocusY = MotionEventCompat.getY(event, 0);
                } else {
                    mSloppyGesture = false;
                    mGestureInProgress = mListener.onScaleBegin(this);
                }
            }
            break;

        case MotionEvent.ACTION_POINTER_UP:
            if (mSloppyGesture) {
                // Set focus point to the remaining finger
                final int id = (action
                        & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT == 0
                                ? 1
                                : 0;
                mFocusX = event.getX(id);
                mFocusY = event.getY(id);
            }
            break;
        }
    } else {
        // Transform gesture in progress - attempt to handle it
        switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_UP:
            // Gesture ended
            setContext(event);

            // Set focus point to the remaining finger
            final int id = (action
                    & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT == 0 ? 1
                            : 0;
            mFocusX = event.getX(id);
            mFocusY = event.getY(id);

            if (!mSloppyGesture) {
                mListener.onScaleEnd(this);
            }

            reset();
            break;

        case MotionEvent.ACTION_CANCEL:
            if (!mSloppyGesture) {
                mListener.onScaleEnd(this);
            }

            reset();
            break;

        case MotionEvent.ACTION_MOVE:
            setContext(event);

            // Only accept the event if our relative pressure is within
            // a certain limit - this can help filter shaky data as a
            // finger is lifted.
            if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) {
                final boolean updatePrevious = mListener.onScale(this);

                if (updatePrevious) {
                    mPrevEvent.recycle();
                    mPrevEvent = MotionEvent.obtain(event);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:de.lmu.ifi.medien.probui.system.ProbUIManager.java

public void manageHelper(MotionEvent ev) throws WrongObservationDelegationException {

    this.currentTouchObservations.clear();

    int action = MotionEventCompat.getActionMasked(ev);
    int index = MotionEventCompat.getActionIndex(ev);
    int pointerID = ev.getPointerId(index);

    int type = -1;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        type = ProbObservationTouch.TYPE_TOUCH_DOWN;
        break;//  w  w w .  jav  a2  s  .  c  o m
    case MotionEvent.ACTION_MOVE:
        type = ProbObservationTouch.TYPE_TOUCH_MOVE;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        type = ProbObservationTouch.TYPE_TOUCH_UP;
        break;
    default:
        type = -1;
        break;
    }

    long timestamp = ev.getEventTime();

    ProbObservationTouch observation = ProbObservationFactory.createTouchObservation(ev.getX(index),
            ev.getY(index), ev.getX(index) * 1.0 / container.getWidth(),
            ev.getY(index) * 1.0 / container.getHeight(), ev.getOrientation(index),
            ev.getTouchMinor(index) * 1.0 / container.getWidth(),
            ev.getTouchMajor(index) * 1.0 / container.getHeight(), ev.getPressure(index), type, pointerID,
            timestamp);
    this.currentTouchObservations.add(observation);

    // Since move is always associated with the first pointer,
    // we need to manually duplicate it for the second one
    // (TODO: and for further pointers, if we change it to more than 2):
    if (ev.getPointerCount() == 2 && type == ProbObservationTouch.TYPE_TOUCH_MOVE) {
        ProbObservationTouch observation2 = ProbObservationFactory.createTouchObservation(ev.getX(index),
                ev.getY(index), ev.getX(1) * 1.0 / container.getWidth(),
                ev.getY(1) * 1.0 / container.getHeight(), ev.getOrientation(1),
                ev.getToolMinor(1) * 1.0 / container.getWidth(),
                ev.getToolMajor(1) * 1.0 / container.getHeight(), ev.getPressure(1), type, ev.getPointerId(1),
                timestamp);
        this.currentTouchObservations.add(observation2);
    }

    //Log.d("MULTITOUCH", "type: " + type + ", index: " + pointerID + ", size: " + ev.getTouchMajor(index) * 1.0 / container.getHeight());

    // Distribute touch observation to the cores of all probInteractors
    // (for reasoning by these interactor cores!, not for visual feedback etc. - that comes below: interactor.onTouchDown etc.)
    boolean passedOn = false;
    for (ProbInteractor interactor : this.probInteractors) {

        for (int i = 0; i < this.currentTouchObservations.size(); i++) {
            ProbObservationTouch obs = this.currentTouchObservations.get(i);
            if (obs == null)
                continue;
            if (obs.getNominalFeatures()[0] != ProbObservationTouch.TYPE_TOUCH_MOVE
                    || this.currentTouchObservations.size() != this.previousTouchObservations.size()) {
                interactor.getCore().onTouchObservation(obs);
                passedOn = true;
            } else { // This code filters out move events that moved very little (potentially improves performance):
                double[] obsXY = this.currentTouchObservations.get(i).getRealFeatures();
                double[] obsPrevXY = this.previousTouchObservations.get(i).getRealFeatures();
                double dx = obsXY[0] - obsPrevXY[0];
                double dy = obsXY[1] - obsPrevXY[1];
                double dist = Math.sqrt(dx * dx + dy * dy);
                if (dist > 0.0125) { // TODO: movement threshold currently hardcoded: 0.0125
                    interactor.getCore().onTouchObservation(obs);
                    passedOn = true;
                } else {
                }
            }
        }

    }

    if (passedOn) {
        this.previousTouchObservations.clear();
        this.previousTouchObservations.addAll(this.currentTouchObservations);
    }

    // Forward the touch observation for probInteractors
    // to react (e.g. visual feedback, triggering actions, nothing to do with the mediation):
    for (ProbInteractor interactor : this.probInteractors) {
        for (ProbObservationTouch obs : this.currentTouchObservations) {
            if (obs != null) {
                switch (obs.getNominalFeatures()[0]) {

                case ProbObservationTouch.TYPE_TOUCH_DOWN:
                    interactor.onTouchDown(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_MOVE:
                    interactor.onTouchMove(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_UP:
                    interactor.onTouchUp(obs, ev.getPointerCount() - 1);
                    break;
                default:
                    break;
                }
            }
        }
    }

    // If no element is determined yet (i.e. no decision yet), update the reasoning process.
    if (!isOneDetermined() && passedOn) {
        this.mediator.mediate(false);
    }

    // Post mediation: Forward the touch observation again
    // to the post-mediation versions of the onTouch... methods
    for (ProbInteractor interactor : this.probInteractors) {
        for (ProbObservationTouch obs : this.currentTouchObservations) {
            if (obs != null) {
                switch (obs.getNominalFeatures()[0]) {

                case ProbObservationTouch.TYPE_TOUCH_DOWN:
                    interactor.onTouchDownPost(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_MOVE:
                    interactor.onTouchMovePost(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_UP:
                    interactor.onTouchUpPost(obs, ev.getPointerCount() - 1);
                    break;
                default:
                    break;
                }
            }
        }
    }

    // Pass on to other GUI elements:
    if (!isOneDetermined()) {
        for (View view : this.nonProbInteractors) {
            if (view.isFocusable() && view.isEnabled())
                view.onTouchEvent(ev);
        }
    }
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.StageView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabled()) {
        // Ignore touch events if not enabled.
        return false;
    }/*  ww w  .  j  av  a2  s  .c o m*/

    final int action = event.getAction();
    final int pointerCount = event.getPointerCount();
    final Handler handler = getHandler();

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN: {
        // Throw away event if we have already seen at least this many
        // fingers before.
        if (mMaxFingersDown > pointerCount) {
            return true;
        }

        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForTap);
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        mPendingCheckForTap = new CheckForTap();
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());

        mMaxFingersDown = pointerCount;

        mMotionPosition = INVALID_POSITION;
        updateMotionCoords(event, pointerCount);

        mTouchMode = TOUCH_MODE_DOWN;

        return true;
    }

    case MotionEvent.ACTION_DOWN: {
        mMaxFingersDown = pointerCount;

        if (mPendingCheckForTap == null) {
            mPendingCheckForTap = new CheckForTap();
        }
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());

        updateMotionCoords(event, pointerCount);
        mMotionPosition = pointToPosition(mMotionX.get(0).intValue(), mMotionY.get(0).intValue());

        mTouchMode = TOUCH_MODE_DOWN;

        return true;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mMaxFingersDown == 1 && mMotionPosition != NO_MATCHED_CHILD
                && mMotionPosition == pointToPosition((int) event.getX(), (int) event.getY())) {
            // Ignore movement in single touch mode until the user has
            // moved out of the prop hit area.
            return true;
        }

        boolean moveIsOverSlop = false;
        int touchSlop = mMaxFingersDown > 1 ? mTouchSlop * 6 : mTouchSlop;
        for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
            int pointerId = event.getPointerId(pointerIndex);
            moveIsOverSlop = moveIsOverSlop
                    || Math.abs(event.getY(pointerIndex) - mMotionY.get(pointerId)) > touchSlop
                    || Math.abs(event.getX(pointerIndex) - mMotionX.get(pointerId)) > touchSlop;
        }

        if (mTouchMode != TOUCH_MODE_AT_REST && moveIsOverSlop) {
            // Too much movement to be a tap event.
            mTouchMode = TOUCH_MODE_AT_REST;
            final View child = getChildAt(mMotionPosition);
            if (child != null) {
                child.setPressed(false);
            }
            setPressed(false);
            if (handler != null) {
                handler.removeCallbacks(mPendingCheckForLongPress);
            }
            mMotionPosition = NO_MATCHED_CHILD;
            updateSelectorState();
            invalidate();
        }
        return true;
    }

    case MotionEvent.ACTION_UP: {
        if (mTouchMode == TOUCH_MODE_FINISHED_LONG_PRESS) {
            return true;
        }

        if (mTouchMode == TOUCH_MODE_AT_REST) {
            break;
        }

        // Handle stage multi-touch.

        if (mMotionPosition == NO_MATCHED_CHILD) {
            if (mPerformPropClick == null) {
                mPerformPropClick = new PerformClick();
            }

            final PerformClick performPropClick = mPerformPropClick;
            performPropClick.mClickMotionPosition = mMotionPosition;
            performPropClick.rememberWindowAttachCount();

            if (mTouchMode != TOUCH_MODE_DOWN || mTouchMode != TOUCH_MODE_TAP) {
                if (handler != null) {
                    handler.removeCallbacks(
                            mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
                }

                if (!mDataChanged) {
                    // Got here so must be a tap. The long press would
                    // have triggered inside the delayed runnable.
                    mTouchMode = TOUCH_MODE_TAP;
                    positionSelector(this);
                    setPressed(true);
                    updateSelectorState();
                    invalidate();

                    resetSelectorTransition(getVirtualFingers());

                    if (mTouchModeReset != null) {
                        removeCallbacks(mTouchModeReset);
                    }
                    mTouchModeReset = new Runnable() {
                        @Override
                        public void run() {
                            mTouchMode = TOUCH_MODE_AT_REST;
                            setPressed(false);
                            if (!mDataChanged) {
                                performPropClick.run();
                            }
                            updateSelectorState();
                            invalidate();
                        }
                    };
                    postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());
                } else {
                    mTouchMode = TOUCH_MODE_AT_REST;
                }
            } else if (!mDataChanged) {
                performPropClick.run();
            }
        } else {
            // Handle touch on child.
            final View child = getChildAt(mMotionPosition);
            if (child != null && !child.hasFocusable()) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformPropClick == null) {
                    mPerformPropClick = new PerformClick();
                }

                final PerformClick performPropClick = mPerformPropClick;
                performPropClick.mClickMotionPosition = mMotionPosition;
                performPropClick.rememberWindowAttachCount();

                if (mTouchMode != TOUCH_MODE_DOWN || mTouchMode != TOUCH_MODE_TAP) {
                    if (handler != null) {
                        handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap
                                : mPendingCheckForLongPress);
                    }

                    if (!mDataChanged) {
                        // Got here so must be a tap. The long press
                        // would
                        // have triggered inside the delayed runnable.
                        mTouchMode = TOUCH_MODE_TAP;
                        child.setPressed(true);
                        positionSelector(child);
                        setPressed(true);
                        updateSelectorState();
                        invalidate();

                        resetSelectorTransition(getVirtualFingers());

                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchMode = TOUCH_MODE_AT_REST;
                                child.setPressed(false);
                                setPressed(false);
                                updateSelectorState();
                                invalidate();
                                if (!mDataChanged) {
                                    performPropClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());
                    } else {
                        mTouchMode = TOUCH_MODE_AT_REST;
                        updateSelectorState();
                        invalidate();
                    }
                } else if (!mDataChanged) {
                    performPropClick.run();
                }
            }
        }
        return true;
    }
    }
    return true;
}

From source file:de.gobro.andreas.pa.pa_cleint_java.SendTouch.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.d("down", "action_down");
        break;//from w ww  .ja  v a2 s. co  m
    }
    case MotionEvent.ACTION_MOVE: {
        for (Integer i = 0; (i < ev.getPointerCount()) && (i < maxPoints); i++) {
            //final Integer pointerIndex = MotionEventCompat.getActionIndex(ev);

            Integer id = ev.getPointerId(i);
            Log.d("ind", "pinterindex" + i.toString());
            Log.d("ind", "ID" + id.toString());
            Log.d("pos", "(" + String.valueOf(MotionEventCompat.getX(ev, i)) + ";"
                    + String.valueOf(MotionEventCompat.getY(ev, i)) + ")");
            Log.d("test", "action_move");

            try {
                serializer.startTag("", "touch");
                serializer.startTag("", "dx");
                serializer.text(String.valueOf(MotionEventCompat.getX(ev, i) / size.x));
                serializer.endTag("", "dx");
                serializer.startTag("", "dy");
                serializer.text(String.valueOf(MotionEventCompat.getY(ev, i) / size.y));
                serializer.endTag("", "dy");
                serializer.startTag("", "id");
                serializer.text(id.toString());
                serializer.endTag("", "id");
                serializer.endTag("", "touch");

            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            //             try {
            //               writer.writeStartElement("touch");
            //                  writer.writeStartElement("dx");
            //                     writer.writeCharacters(String.valueOf(MotionEventCompat.getX(ev, i)/size.x));
            //                  writer.writeEndElement();
            //                  writer.writeStartElement("dy");
            //                     writer.writeCharacters(String.valueOf(MotionEventCompat.getY(ev, i)/size.y));
            //                  writer.writeEndElement();
            //                  writer.writeStartElement("id");
            //                     writer.writeCharacters(id.toString());
            //                  writer.writeEndElement();                  
            //               writer.writeEndElement();
            //            } catch (XMLStreamException e) {
            //               // TODO Auto-generated catch block
            //               e.printStackTrace();
            //            }

        }

        //write the stuff to the network
        try {
            serializer.flush();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            finish();

        }
        break;
    }
    case MotionEvent.ACTION_UP: {
        Log.d("test", "action_up");
        break;
    }
    case MotionEvent.ACTION_CANCEL: {
        Log.d("test", "action_cancel");
        break;
    }
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.d("down", "action_p_down");
        break;
    }
    case MotionEvent.ACTION_POINTER_UP: {
        Log.d("test", "action_p_up");
        break;
    }
    }
    return true;
}

From source file:study.com.s_sxl.carelib.pullRefreshView.layout.FlingLayout.java

/******************************************************************/

@Override/*  w ww.j a  v a 2s.co  m*/
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) {
        float moveY = getMoveY();
        int pointerCount = ev.getPointerCount();
        int pointerIndex = ev.getActionIndex();
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
        switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            float x = ev.getX(pointerIndex);
            float y = ev.getY(pointerIndex);
            tempY = downY = y;
            tempX = downX = x;
            tempStateType = SCROLL_STATE_TOUCH_SCROLL;
            if (moveY != 0) {
                return true;
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            tempX = ev.getX(pointerIndex);
            tempY = ev.getY(pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            pointerIndex = ev.findPointerIndex(mPointerId);
            float mx;
            float my;
            if (pointerCount > pointerIndex && pointerIndex >= 0) {
                mx = ev.getX(pointerIndex);
                my = ev.getY(pointerIndex);
            } else {
                mx = ev.getX();
                my = ev.getY();
            }
            //?????
            int dataX = (int) (mx - tempX);
            int dataY = (int) (my - tempY);
            tempX = mx;
            tempY = my;
            if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) {
                isScrolling = true;
                if (moveY == 0) {
                    // 0,0
                    //??
                    if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) {
                        moveBy(dataY);
                        return true;
                    }
                } else {
                    //?0,0
                    ev.setAction(MotionEvent.ACTION_CANCEL);//?

                    if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) {
                        //0,0
                        ev.setAction(MotionEvent.ACTION_DOWN);
                        moveTo(0);
                    } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) {
                        //??
                        if (maxDistance == 0 || Math.abs(moveY) < maxDistance) {
                            int ps = 0;
                            int hDataY = dataY / 2;
                            if (maxDistance == 0) {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY;
                            } else {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY;
                            }
                            moveBy(ps + dataY);
                        } else if (moveY > maxDistance) {
                            moveTo(maxDistance);
                        } else if (moveY < -maxDistance) {
                            moveTo(-maxDistance);
                        }
                    } else {
                        moveBy(dataY);
                    }
                }
            } else {
                ev.setLocation(mx, downY);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            startFling();
            isScrolling = false;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // ??
            int pointerIdLeave = ev.getPointerId(pointerIndex);
            if (mPointerId == pointerIdLeave) {
                // ??????VelocityTracker
                int reIndex = pointerIndex == 0 ? 1 : 0;
                mPointerId = ev.getPointerId(reIndex);
                // ?
                tempY = ev.getY(reIndex);
            }
        }
        return super.dispatchTouchEvent(ev) || isScrolling;
    } else {
        return super.dispatchTouchEvent(ev);
    }

}

From source file:com.leap.mini.widget.pullrefresh.base.layout.FlingLayout.java

/******************************************************************/

@Override//  w  ww .  j a v  a 2 s .co  m
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) {
        float moveY = getMoveY();
        int pointerCount = ev.getPointerCount();
        int pointerIndex = ev.getActionIndex();
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
        switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            float x = ev.getX(pointerIndex);
            float y = ev.getY(pointerIndex);
            tepmY = downY = y;
            tepmX = downX = x;
            tempStateType = SCROLL_STATE_TOUCH_SCROLL;
            if (moveY != 0) {
                return true;
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            tepmX = ev.getX(pointerIndex);
            tepmY = ev.getY(pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            pointerIndex = ev.findPointerIndex(mPointerId);
            float mx;
            float my;
            if (pointerCount > pointerIndex && pointerIndex >= 0) {
                mx = ev.getX(pointerIndex);
                my = ev.getY(pointerIndex);
            } else {
                mx = ev.getX();
                my = ev.getY();
            }
            // ?????
            int dataX = (int) (mx - tepmX);
            int dataY = (int) (my - tepmY);
            tepmX = mx;
            tepmY = my;
            if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) {
                isScrolling = true;
                if (moveY == 0) {
                    //  0,0
                    // ??
                    if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) {
                        moveBy(dataY);
                        return true;
                    }
                } else {
                    // ?0,0
                    ev.setAction(MotionEvent.ACTION_CANCEL);// ?

                    if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) {
                        // 0,0
                        ev.setAction(MotionEvent.ACTION_DOWN);
                        moveTo(0);
                    } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) {
                        // ??
                        if (maxDistance == 0 || Math.abs(moveY) < maxDistance) {
                            int ps = 0;
                            int hDataY = dataY / 2;
                            if (maxDistance == 0) {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY;
                            } else {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY;
                            }
                            moveBy(ps + dataY);
                        } else if (moveY > maxDistance) {
                            moveTo(maxDistance);
                        } else if (moveY < -maxDistance) {
                            moveTo(-maxDistance);
                        }
                    } else {
                        moveBy(dataY);
                    }
                }
            } else {
                ev.setLocation(mx, downY);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            startFling();
            isScrolling = false;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // ??
            int pointerIdLeave = ev.getPointerId(pointerIndex);
            if (mPointerId == pointerIdLeave) {
                // ??????VelocityTracker
                int reIndex = pointerIndex == 0 ? 1 : 0;
                mPointerId = ev.getPointerId(reIndex);
                // ?
                tepmY = ev.getY(reIndex);
            }
        }
        return super.dispatchTouchEvent(ev) || isScrolling;
    } else {
        return super.dispatchTouchEvent(ev);
    }

}

From source file:com.intel.xdk.multitouch.MultiTouch.java

public void queueMultitouchData(String js, int id, int maskedAction) {
    //Log.i("[appMobi]", "queueMultitouchData:"+js);

    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN || maskedAction == MotionEvent.ACTION_DOWN) {
        //touchstart: create list
        //this.multitouchMap.put(id, new ArrayList<String>());

    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP || maskedAction == MotionEvent.ACTION_UP) {
        //touchend: remove list
        this.multitouchMap.remove(id);

    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
        //touchmove: flush stale touchmove events and and update list
        String stale = this.multitouchMap.get(id);
        this.multitouchQueue.remove(stale);
        this.multitouchMap.put(id, js);
    }//from w  w  w .java 2 s  .co m

    this.multitouchQueue.add(js);
}

From source file:com.ybao.pullrefreshview.layout.FlingLayout.java

/******************************************************************/

@Override//from w w  w .java 2  s.c  o  m
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) {
        float moveY = getMoveY();
        int pointerCount = ev.getPointerCount();
        int pointerIndex = ev.getActionIndex();
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
        switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            float x = ev.getX(pointerIndex);
            float y = ev.getY(pointerIndex);
            tepmY = downY = y;
            tepmX = downX = x;
            tempStateType = SCROLL_STATE_TOUCH_SCROLL;
            if (moveY != 0) {
                return true;
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            tepmX = ev.getX(pointerIndex);
            tepmY = ev.getY(pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            pointerIndex = ev.findPointerIndex(mPointerId);
            float mx;
            float my;
            if (pointerCount > pointerIndex && pointerIndex >= 0) {
                mx = ev.getX(pointerIndex);
                my = ev.getY(pointerIndex);
            } else {
                mx = ev.getX();
                my = ev.getY();
            }
            //?????
            int dataX = (int) (mx - tepmX);
            int dataY = (int) (my - tepmY);
            tepmX = mx;
            tepmY = my;
            if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) {
                isScrolling = true;
                if (moveY == 0) {
                    // 0,0
                    //??
                    if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) {
                        moveBy(dataY);
                        return true;
                    }
                } else {
                    //?0,0
                    ev.setAction(MotionEvent.ACTION_CANCEL);//?

                    if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) {
                        //0,0
                        ev.setAction(MotionEvent.ACTION_DOWN);
                        moveTo(0);
                    } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) {
                        //??
                        if (maxDistance == 0 || Math.abs(moveY) < maxDistance) {
                            int ps = 0;
                            int hDataY = dataY / 2;
                            if (maxDistance == 0) {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY;
                            } else {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY;
                            }
                            moveBy(ps + dataY);
                        } else if (moveY > maxDistance) {
                            moveTo(maxDistance);
                        } else if (moveY < -maxDistance) {
                            moveTo(-maxDistance);
                        }
                    } else {
                        moveBy(dataY);
                    }
                }
            } else {
                ev.setLocation(mx, downY);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            startFling();
            isScrolling = false;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // ??
            int pointerIdLeave = ev.getPointerId(pointerIndex);
            if (mPointerId == pointerIdLeave) {
                // ??????VelocityTracker
                int reIndex = pointerIndex == 0 ? 1 : 0;
                mPointerId = ev.getPointerId(reIndex);
                // ?
                tepmY = ev.getY(reIndex);
            }
        }
        return super.dispatchTouchEvent(ev) || isScrolling;
    } else {
        return super.dispatchTouchEvent(ev);
    }

}

From source file:com.cocarechina.pullrefreshview.layout.FlingLayout.java

/******************************************************************/

@Override//from   ww w  . jav  a  2 s .c o m
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) {
        float moveY = getMoveY();
        int pointerCount = ev.getPointerCount();
        int pointerIndex = ev.getActionIndex();
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
        switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            float x = ev.getX(pointerIndex);
            float y = ev.getY(pointerIndex);
            tepmY = downY = y;
            tepmX = downX = x;
            tempStateType = SCROLL_STATE_TOUCH_SCROLL;
            if (moveY != 0) {
                return true;
            }
            lastY = ev.getY();
            Log.v("lastY", moveY + "");
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mPointerId = ev.getPointerId(pointerIndex);
            tepmX = ev.getX(pointerIndex);
            tepmY = ev.getY(pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            pointerIndex = ev.findPointerIndex(mPointerId);
            float mx;
            float my;
            if (pointerCount > pointerIndex && pointerIndex >= 0) {
                mx = ev.getX(pointerIndex);
                my = ev.getY(pointerIndex);
            } else {
                mx = ev.getX();
                my = ev.getY();
            }
            //?????
            int dataX = (int) (mx - tepmX);
            int dataY = (int) (my - tepmY);
            tepmX = mx;
            tepmY = my;
            if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) {
                isScrolling = true;
                if (moveY == 0) {
                    // 0,0
                    //??
                    if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) {
                        moveBy(dataY);
                        return true;
                    }
                } else {
                    //?0,0
                    ev.setAction(MotionEvent.ACTION_CANCEL);//?

                    if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) {
                        //0,0
                        ev.setAction(MotionEvent.ACTION_DOWN);
                        moveTo(0);
                    } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) {
                        //??
                        if (maxDistance == 0 || Math.abs(moveY) < maxDistance) {
                            int ps = 0;
                            int hDataY = dataY / 2;
                            if (maxDistance == 0) {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY;
                            } else {
                                ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY;
                            }
                            moveBy(ps + dataY);
                        } else if (moveY > maxDistance) {

                            moveTo(maxDistance);
                        } else if (moveY < -maxDistance) {
                            moveTo(-maxDistance);
                        }
                    } else {
                        moveBy(dataY);
                    }
                }
            } else {
                ev.setLocation(mx, downY);
            }

            Log.v("flingLayout", "ev.getY()" + ev.getY() + "  ---  lastY " + lastY);
            if (ev.getY() - lastY > 5) {
                if (monScrollHeadListener != null) {
                    monScrollHeadListener.onScrollBottom();
                }
            } else if (ev.getY() - lastY < -10) {
                if (monScrollHeadListener != null) {
                    monScrollHeadListener.onScrollTop();
                }
            }

            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            startFling();
            isScrolling = false;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // ??
            int pointerIdLeave = ev.getPointerId(pointerIndex);
            if (mPointerId == pointerIdLeave) {
                // ??????VelocityTracker
                int reIndex = pointerIndex == 0 ? 1 : 0;
                mPointerId = ev.getPointerId(reIndex);
                // ?
                tepmY = ev.getY(reIndex);
            }
        }
        return super.dispatchTouchEvent(ev) || isScrolling;
    } else {
        return super.dispatchTouchEvent(ev);
    }

}