Example usage for android.view MotionEvent ACTION_CANCEL

List of usage examples for android.view MotionEvent ACTION_CANCEL

Introduction

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

Prototype

int ACTION_CANCEL

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

Click Source Link

Document

Constant for #getActionMasked : The current gesture has been aborted.

Usage

From source file:cardstream.CardActionButton.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        setPressed(true);/*www.  ja va 2 s. co  m*/
        Log.d("", "click");
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            animate().scaleX(0.98f).scaleY(0.98f).setDuration(100)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            ViewCompat.setElevation(this, 8.f);
        }
        break;
    }
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        setPressed(false);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            animate().scaleX(1.f).scaleY(1.f).setDuration(50).setInterpolator(new BounceInterpolator());
        } else {
            ViewCompat.setElevation(this, 0.f);
        }
        break;
    }
    }

    return super.onTouchEvent(event);
}

From source file:com.anysoftkeyboard.devicespecific.AskV8GestureDetector.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    int singleFingerEventPointerId = mSingleFingerEventPointerId;

    //I want to keep track on the first finger (https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300)
    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN:
        if (ev.getPointerCount() == 1) {
            mSingleFingerEventPointerId = ev.getPointerId(0);
            singleFingerEventPointerId = mSingleFingerEventPointerId;
        }//from w  ww. j  av a  2  s  .  c om
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (ev.getPointerCount() == 1)
            mSingleFingerEventPointerId = NOT_A_POINTER_ID;
    }
    try {
        //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/26
        mScaleGestureDetector.onTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        //I have nothing I can do here.
    } catch (ArrayIndexOutOfBoundsException e) {
        //I have nothing I can do here.
    }
    //I'm going to pass the event to the super, only if it is a single touch, and the event is for the first finger
    //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300
    if (ev.getPointerCount() == 1 && ev.getPointerId(0) == singleFingerEventPointerId)
        return super.onTouchEvent(ev);
    else
        return false;
}

From source file:com.dudka.rich.streamingmusicplayer.FragmentMusicPlayerUI.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View view = inflater.inflate(R.layout.fragment_music_player, container, false);

    playButton = (ImageView) view.findViewById(R.id.play);
    playButton.setOnClickListener(new View.OnClickListener() {
        @Override//  w  ww. j  a va 2s. c o  m
        public void onClick(View v) {
            mListener.togglePlayButton();
        }
    });

    view.findViewById(R.id.rewind).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mListener.startSeek();
                return true;
            } else if (event.getAction() == MotionEvent.ACTION_UP
                    || event.getAction() == MotionEvent.ACTION_CANCEL) {
                mListener.stopSeekBack();
            }
            return false;
        }
    });

    view.findViewById(R.id.fast_forward).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mListener.startSeek();
                return true;
            } else if (event.getAction() == MotionEvent.ACTION_UP
                    || event.getAction() == MotionEvent.ACTION_CANCEL) {
                mListener.stopSeekForward();
            }
            return false;
        }
    });

    view.findViewById(R.id.quit).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mListener.handleFinish();
        }
    });

    return view;
}

From source file:cn.nekocode.camerafilter.MainActivity.java

void setupCameraPreviewView() {
    renderer = new CameraRenderer(this);
    textureView = (TextureView) findViewById(R.id.textureView);
    assert textureView != null;
    textureView.setSurfaceTextureListener(renderer);

    // Show original frame when touch the view
    textureView.setOnTouchListener(new View.OnTouchListener() {
        @Override//w  w  w .  j a  v  a  2  s. c  o  m
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                renderer.setSelectedFilter(R.id.filter0);
                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                renderer.setSelectedFilter(filterId);
                break;
            }
            return true;
        }
    });

    textureView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            renderer.onSurfaceTextureSizeChanged(null, v.getWidth(), v.getHeight());
        }
    });
}

From source file:android.support.v7.widget.ForwardingListener.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final boolean wasForwarding = mForwarding;
    final boolean forwarding;
    if (wasForwarding) {
        forwarding = onTouchForwarded(event) || !onForwardingStopped();
    } else {//from   w w  w. ja  va2s  . c  o m
        forwarding = onTouchObserved(event) && onForwardingStarted();

        if (forwarding) {
            // Make sure we cancel any ongoing source event stream.
            final long now = SystemClock.uptimeMillis();
            final MotionEvent e = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
            mSrc.onTouchEvent(e);
            e.recycle();
        }
    }

    mForwarding = forwarding;
    return forwarding || wasForwarding;
}

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

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

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        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) {
            break;
        }

        final int y = (int) ev.getY(pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

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

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

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        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 = MotionEventCompat.findPointerIndex(ev, activePointerId);
        if (pointerIndex == -1) {
            break;
        }

        final int y = (int) MotionEventCompat.getY(ev, pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

From source file:akhil.alltrans.NestedScrollingListView.java

/**
 *
 * @see android.support.v4.widget.NestedScrollView#onTouchEvent(MotionEvent)
 *///  ww w  . j av a  2 s .c  om
@Override
public boolean onTouchEvent(MotionEvent ev) {
    boolean returnValue = false;

    MotionEvent event = MotionEvent.obtain(ev);
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_DOWN) {
        mNestedOffsetY = 0;
    }
    event.offsetLocation(0, mNestedOffsetY);
    int eventY = (int) event.getY();
    switch (action) {
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastY - eventY;
        // NestedPreScroll
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            mLastY = eventY - mScrollOffset[1];
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
        }
        returnValue = super.onTouchEvent(event);

        // NestedScroll
        if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
            mLastY -= mScrollOffset[1];
        }
        break;
    case MotionEvent.ACTION_DOWN:
        returnValue = super.onTouchEvent(event);
        mLastY = eventY;
        // start NestedScroll
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    case MotionEvent.ACTION_UP:
        // TODO: fling
        returnValue = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_CANCEL:
        returnValue = super.onTouchEvent(event);
        // end NestedScroll
        stopNestedScroll();
        break;
    }
    return returnValue;
}

From source file:akhil.alltrans.NestedScrollingMarkDownView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;//w  w  w  .j a v a  2  s.c  om
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        int oldY = getScrollY();
        mLastMotionY = y - mScrollOffset[1];
        if (deltaY < 0) {
            int newScrollY = Math.max(0, oldY + deltaY);
            deltaY -= newScrollY - oldY;
            if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
                mLastMotionY -= mScrollOffset[1];
                trackedEvent.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
        }

        result = super.onTouchEvent(trackedEvent);
        trackedEvent.recycle();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:com.augustosalazar.dragdroptest.DragFrameLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getActionMasked();
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();//from   w w  w .j  av a2s . c o m
        return false;
    }
    return mDragHelper.shouldInterceptTouchEvent(ev);
}