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:net.simonvt.staggeredgridview.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    velocityTracker.addMovement(ev);//from  www  .  ja v a  2  s .co m
    final int action = ev.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        if (tapReset != null) {
            removeCallbacks(tapReset);
            tapReset = null;
        }
        if (pendingTapCheck != null) {
            removeCallbacks(pendingTapCheck);
            pendingTapCheck = null;
        }

        velocityTracker.clear();
        scroller.abortAnimation();
        lastTouchY = ev.getY();
        lastTouchX = ev.getX();
        final int x = (int) ev.getX();
        activePointerId = ev.getPointerId(0);
        touchRemainderY = 0;
        motionPosition = getPositionAt(x, (int) lastTouchY);
        if (motionPosition != INVALID_POSITION && adapter != null && adapter.isEnabled(motionPosition)) {
            pendingTapCheck = new TapCheck();
            postDelayed(pendingTapCheck, ViewConfiguration.getTapTimeout());
            if (hasStableIds) {
                motionId = ((LayoutParams) getChildAt(motionPosition - firstPosition).getLayoutParams()).id;
            }
        }
        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 x = ev.getX(index);
        final float dy = y - lastTouchY + touchRemainderY;
        final int deltaY = (int) dy;
        touchRemainderY = dy - deltaY;

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

        if (touchMode == TOUCH_MODE_DRAGGING) {
            if (pendingTapCheck != null) {
                removeCallbacks(pendingTapCheck);
            }
            if (!selectorRect.isEmpty()) {
                selectorRect.setEmpty();
            }
            if (motionPosition != INVALID_POSITION) {
                final View child = getChildAt(motionPosition - firstPosition);
                if (child != null) {
                    child.setPressed(false);
                }
                setPressed(false);
                selector.setState(StateSet.NOTHING);
                motionPosition = INVALID_POSITION;
                motionId = -1L;
            }

            lastTouchY = y;
            lastTouchX = x;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                velocityTracker.clear();
            }
        }
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        touchMode = TOUCH_MODE_IDLE;

        if (motionPosition != INVALID_POSITION) {
            View child = getChildAt(motionPosition - firstPosition);
            child.setPressed(false);

            setPressed(false);
        }

        motionPosition = INVALID_POSITION;
        motionId = -1L;
        selectorRect.setEmpty();

        if (pendingTapCheck != null) {
            removeCallbacks(pendingTapCheck);
            pendingTapCheck = null;
        }
        if (tapReset != null) {
            removeCallbacks(tapReset);
            tapReset = null;
        }
        break;

    case MotionEvent.ACTION_UP: {
        velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
        final float velocity = velocityTracker.getYVelocity(activePointerId);

        if (pendingTapCheck != null) {
            removeCallbacks(pendingTapCheck);
            pendingTapCheck = null;
        }

        if (Math.abs(velocity) > flingVelocity) { // TODO
            touchMode = TOUCH_MODE_FLINGING;
            scroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            lastTouchY = 0;
            postInvalidateOnAnimation();

            if (motionPosition != INVALID_POSITION) {
                View child = getChildAt(motionPosition - firstPosition);
                if (child != null) {
                    child.setPressed(false);
                }

                setPressed(false);

                motionPosition = INVALID_POSITION;
                motionId = -1L;
                selectorRect.setEmpty();

                if (pendingTapCheck != null) {
                    removeCallbacks(pendingTapCheck);
                    pendingTapCheck = null;
                }
            }
        } else {
            if (touchMode != TOUCH_MODE_DRAGGING && motionPosition != INVALID_POSITION) {
                if (adapter != null && adapter.isEnabled(motionPosition)) {
                    new TapCheck().run();
                    tapReset = new TapReset();
                    postDelayed(tapReset, ViewConfiguration.getPressedStateDuration());
                } else {
                    motionPosition = INVALID_POSITION;
                    motionId = -1L;
                }
            }
            touchMode = TOUCH_MODE_IDLE;
        }
    }
        break;
    }
    return true;
}

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);//from w w  w  .  j a  v a 2 s  .com
        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.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView3.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    View v;/*from  w  w  w.j a  va  2s.c o  m*/

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionRow(y);
        if (touchMode != TOUCH_MODE_FLINGING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a fling).
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop=v.getTop();
            mLastTouchX = x;
            mLastTouchY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
            clearScrollingCache();
        }
        mTouchRemainderY = Integer.MIN_VALUE;
        if (touchMode == TOUCH_MODE_FLINGING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            final int pointerIndex = ev.findPointerIndex(mActivePointerId);
            final int y = (int) ev.getY(pointerIndex);
            if (startScrollIfNeeded((int) (y - mLastTouchX))) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_REST;
        mActivePointerId = INVALID_POINTER;
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        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   w  ww .j a v  a  2  s. 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:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java

@SuppressLint("ClickableViewAccessibility")
@Override//from  ww w  .ja v a 2  s . c o m
public boolean onTouch(View v, MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        initialX = x;
        initialY = y;
        dragIndex = TouchMap.UNMAPPED;
        dragging = false;
        dragAsset = "";

        if (AppData.IS_KITKAT && mGlobalPrefs.isImmersiveModeEnabled) {
            // ignore edge swipes.
            // unfortunately KitKat lacks a way to do this on its own,
            // so just ignore all touches along the edges.
            // http://stackoverflow.com/questions/20530333/ignore-immersive-mode-swipe
            View view = getWindow().getDecorView();
            if (y < 10 || y > view.getHeight() - 10 || x < 10 || x > view.getWidth() - 10)
                return false;
        }

        // Get the N64 index of the button that was pressed
        int index = mTouchscreenMap.getButtonPress(x, y);
        if (index != TouchMap.UNMAPPED) {
            dragIndex = index;
            dragAsset = TouchMap.ASSET_NAMES.get(index);
            dragFrame = mTouchscreenMap.getButtonFrame(dragAsset);
        } else {
            // See if analog was pressed
            Point point = mTouchscreenMap.getAnalogDisplacement(x, y);
            int dX = point.x;
            int dY = point.y;
            float displacement = (float) Math.sqrt((dX * dX) + (dY * dY));
            if (mTouchscreenMap.isInCaptureRange(displacement)) {
                dragAsset = ANALOG;
                dragFrame = mTouchscreenMap.getAnalogFrame();
            } else {
                int resId = R.menu.touchscreen_profile_activity;
                int stringId = R.string.touchscreenProfileActivity_menuTitle;

                MenuDialogFragment menuDialogFragment = MenuDialogFragment.newInstance(0, getString(stringId),
                        resId);

                FragmentManager fm = getSupportFragmentManager();
                menuDialogFragment.show(fm, STATE_MENU_DIALOG_FRAGMENT);
            }
        }

        dragX = mProfile.getInt(dragAsset + TAG_X, INITIAL_ASSET_POS);
        dragY = mProfile.getInt(dragAsset + TAG_Y, INITIAL_ASSET_POS);

        return true;
    } else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) {
        if (dragIndex != TouchMap.UNMAPPED || ANALOG.equals(dragAsset)) {
            if (!dragging) {
                int dX = x - initialX;
                int dY = y - initialY;
                float displacement = (float) Math.sqrt((dX * dX) + (dY * dY));
                if (displacement >= 10)
                    dragging = true;
            }
            if (!dragging)
                return false;

            // drag this button or analog stick around

            // calculate the X and Y percentage
            View view = getWindow().getDecorView();
            int newDragX = (x - (initialX - dragFrame.left)) * 100
                    / (view.getWidth() - (dragFrame.right - dragFrame.left));
            int newDragY = (y - (initialY - dragFrame.top)) * 100
                    / (view.getHeight() - (dragFrame.bottom - dragFrame.top));

            newDragX = Math.min(Math.max(newDragX, 0), 100);
            newDragY = Math.min(Math.max(newDragY, 0), 100);

            if (newDragX != dragX || newDragY != dragY) {
                dragX = newDragX;
                dragY = newDragY;
                mProfile.put(dragAsset + TAG_X, String.valueOf(newDragX));
                mProfile.put(dragAsset + TAG_Y, String.valueOf(newDragY));
                mTouchscreenMap.refreshButtonPosition(mProfile, dragAsset);
                mOverlay.postInvalidate();
            }
        }
    } else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        // if this touch was part of a drag/swipe gesture then don't tap the button
        if (dragging)
            return false;

        // show the editor for the tapped button
        if (ANALOG.equals(dragAsset)) {
            // play the standard button sound effect
            View view = getWindow().getDecorView();
            view.playSoundEffect(SoundEffectConstants.CLICK);

            popupDialog(dragAsset, getString(R.string.controller_analog), -1);
        } else if (dragIndex != TouchMap.UNMAPPED) {
            int index = dragIndex;
            String title = READABLE_NAMES.get(dragIndex);

            // D-pad buttons and TOGGLE_SENSOR are not holdable
            if (DPAD.equals(dragAsset) || TouchMap.TOGGLE_SENSOR == index)
                index = -1;

            // play the standard button sound effect
            View view = getWindow().getDecorView();
            view.playSoundEffect(SoundEffectConstants.CLICK);

            popupDialog(dragAsset, title, index);
        }

        return true;
    }

    return false;
}

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
        return false;
    }//from  www.java 2  s.  co m

    final int action = ev.getAction() & MotionEvent.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mIsDragging = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_VALUE;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsDragging) {
            return true;
        } else if (mIsUnableToDrag) {
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:

        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_VALUE) {
            break;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = getViewX(ev);
        final float dx = x - mLastX;
        final float xDiff = Math.abs(dx);
        final float y = getViewY(ev);
        final float dy = y - mLastY;
        final float yDiff = Math.abs(dy);

        if ((dx != 0 || dy != 0) && canScroll(this, false, (int) dx, (int) dy, (int) x, (int) y)) {
            mLastX = mInitialRawX = x;
            mLastY = mInitialRawY = y;
            mInitialX = ev.getX(pointerIndex);
            mInitialY = ev.getY(pointerIndex);
            return false;
        }

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

        if (validHorizontalDrag) {
            mLastX = x;
        } else if (validVerticalDrag) {
            mLastY = y;
        }

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

    case MotionEvent.ACTION_DOWN:
        mLastX = mInitialRawX = getViewX(ev);
        mLastY = mInitialRawY = getViewY(ev);
        mInitialX = ev.getX(0);
        mInitialY = ev.getY(0);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (touchPointIsWithinBounds(ev.getX(), ev.getY())) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // We don't want to do anything, send the event up
            return super.onInterceptTouchEvent(ev);
        } else {
            completeScroll();
            mIsDragging = false;
            mIsUnableToDrag = true;
        }
        break;
    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

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

    return mIsDragging;
}

From source file:org.stockchart.StockChartView.java

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

    switch (e) {//ww w  .  ja va2 s  .  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:com.albedinsky.android.ui.widget.ViewPagerWidget.java

/**
 *//*from w w  w.  j  av  a  2 s. c  o m*/
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    this.ensureDecorator();
    if (!mDecorator.hasPrivateFlag(PFLAG_PAGE_SWIPING_ENABLED)) {
        return false;
    }
    if (mDecorator.onTouchEvent(event)) {
        this.requestParentDisallowInterceptTouchEvent(true);
        return true;
    }
    if (mDecorator.hasPrivateFlag(PFLAG_PAGE_FLING_SWIPING_ENABLED)) {
        this.ensureVelocityTracker();
        mVelocityTracker.addMovement(event);
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mVelocityTracker.computeCurrentVelocity(UiConfig.VELOCITY_UNITS);
            final float xVelocity = mVelocityTracker.getXVelocity();
            if (Math.abs(xVelocity) > mPageFlingSwipingSensitivity) {
                super.onTouchEvent(event);
                this.handleFling(xVelocity);
                return true;
            }
        }
    }
    return super.onTouchEvent(event);
}

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

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*/*from  ww  w. ja  v a  2 s.com*/
     * 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;
}

From source file:com.example.piechart3d.PieChart3DView.java

@SuppressLint("NewApi")
@Override//from   w  ww  . j a  v  a  2  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;
}