Example usage for android.view MotionEvent ACTION_UP

List of usage examples for android.view MotionEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Usage

From source file:androidx.media.widget.VideoView2.java

@Override
public boolean onTrackballEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_UP && mMediaControlView != null) {
        if (!mIsMusicMediaType || mSizeType != SIZE_TYPE_FULL) {
            toggleMediaControlViewVisibility();
        }/*w w w . ja  va2  s. co  m*/
    }

    return super.onTrackballEvent(ev);
}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    final int action = ev.getAction();

    if (!isEnabled()) {
        return false; // We don't want the events. Let them fall through to the all
                      // apps view.
    }/* ww w . jav  a  2 s .  co  m*/

    if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
        return true;
    }

    acquireVelocityTrackerAndAddMovement(ev);

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_MOVE: {

        /*
         * Locally do absolute value. mLastMotionX is set to the y value of the
         * down event.
         */
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);

        if (pointerIndex < 0) {
            // invalid pointer
            return true;
        }

        final float x = ev.getX(pointerIndex);
        final float y = ev.getY(pointerIndex);
        final int xDiff = (int) Math.abs(x - mLastMotionX);
        final int yDiff = (int) Math.abs(y - mLastMotionY);

        final int touchSlop = mTouchSlop;
        boolean xMoved = xDiff > touchSlop;
        boolean yMoved = yDiff > touchSlop;
        mLastMotionX2 = x;

        if (xMoved || yMoved) {

            if (xMoved) {
                // Scroll if the user moved far enough along the X axis
                mTouchState = TOUCH_STATE_SCROLLING;
                mLastMotionX = x;
                mTouchX = getScrollX();
                mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
                enableChildrenCache(mCurrentScreen - 1, mCurrentScreen + 1);
            }

        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        // Remember location of down touch
        mLastMotionX = x;
        mLastMotionX2 = x;
        mLastMotionY = y;
        mActivePointerId = ev.getPointerId(0);
        mAllowLongPress = true;

        mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        // Release the drag
        clearChildrenCache();
        mTouchState = TOUCH_STATE_REST;
        mActivePointerId = INVALID_POINTER;
        mAllowLongPress = false;
        releaseVelocityTracker();
        break;

    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

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

From source file:com.albedinsky.android.ui.widget.SearchView.java

/**
 *//*from  w  w  w .j a  v a2s  .  c om*/
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    // SearchView is expected to be used mainly above or at the place of toolbar so it will handle
    // touch events like the Toolbar widget.
    final int action = event.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_DOWN) {
        this.mEatingTouch = false;
    }
    if (!mEatingTouch) {
        final boolean handled = super.onTouchEvent(event);
        if (action == MotionEvent.ACTION_DOWN && !handled) {
            this.mEatingTouch = true;
        }
    }
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        this.mEatingTouch = false;
    }
    return true;
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

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

    // Preserve the open state based on the last view that was touched.
    if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) {
        // After the first things will be slideable.
        final View secondChild = getChildAt(1);
        if (secondChild != null) {
            mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY());
        }//from w ww  . j av a 2 s  .  c om
    }

    if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

    boolean interceptTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;

        if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) {
            interceptTap = true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float adx = Math.abs(x - mInitialMotionX);
        final float deltaX = x - mInitialMotionX;
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        if ((adx > slop && ady > adx) || deltaX < 0) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
    }
    }

    final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev);

    return interceptForDrag || interceptTap;
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
public boolean onTouchEvent(MotionEvent me) {
    try {/* ww  w.  j  a v  a  2s  . co m*/
        killOnError(); // ?  ?

        //  ? x, y  
        float xPress = me.getX();
        float yPress = me.getY();

        // ?? ??  ?? ? ?? 
        if (me.getAction() == MotionEvent.ACTION_UP) {
            dataView.clickEvent(xPress, yPress);
        }

        return true;

    } catch (Exception ex) { //  
        //doError(ex);
        ex.printStackTrace();
        return super.onTouchEvent(me);
    }
}

From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    try {//w w w .  ja  v a 2s.c  o  m
        if (!mCanSlide) {
            return super.onTouchEvent(ev);
        }

        mDragHelper.processTouchEvent(ev);

        final int action = ev.getAction();
        boolean wantTouchEvents = true;

        switch (action & MotionEventCompat.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN: {
            final float x = ev.getX();
            final float y = ev.getY();
            mInitialMotionX = x;
            mInitialMotionY = y;
            break;
        }

        case MotionEvent.ACTION_UP: {
            if (isDimmed(mSlideableView)) {
                final float x = ev.getX();
                final float y = ev.getY();
                final float dx = x - mInitialMotionX;
                final float dy = y - mInitialMotionY;
                final int slop = mDragHelper.getTouchSlop();
                if (dx * dx + dy * dy < slop * slop
                        && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) {
                    // Taps close a dimmed open pane.
                    closePane(mSlideableView, 0);
                    break;
                }
            }
            break;
        }
        }

        return wantTouchEvents;
    } catch (ArrayIndexOutOfBoundsException e) {
        LogManager.logE(BugFixedSlidingPaneLayout.class,
                "internal bug in SlidingPaneLayout,this bug can be ignored in most cases.", e);
        return false;
    } catch (IllegalArgumentException e) {
        LogManager.logE(BugFixedSlidingPaneLayout.class,
                "internal bug in SlidingPaneLayout,this bug can be ignored in most cases.", e);
        return false;
    }
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    // Return if animation is running
    if (mAnimator.isRunning())
        return true;
    // If is not idle state, return
    if (mScrollState != ViewPager.SCROLL_STATE_IDLE)
        return true;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // Action down touch
        mIsActionDown = true;// w  w w .  j a  v a 2 s. c o m
        if (!mIsViewPagerMode)
            break;
        if (!mIsSwiped)
            break;
        // Detect if we touch down on pointer, later to move
        if (mIsHorizontalOrientation)
            mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex;
        else
            mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex;
        break;
    case MotionEvent.ACTION_MOVE:
        // If pointer touched, so move
        if (mIsPointerActionDown) {
            if (mIsHorizontalOrientation)
                mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true);
            else
                mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true);
            break;
        }
        if (mIsActionDown)
            break;
    case MotionEvent.ACTION_UP:
        // Press up and set model index relative to current coordinate
        if (mIsActionDown) {
            playSoundEffect(SoundEffectConstants.CLICK);
            if (mIsHorizontalOrientation)
                setModelIndex((int) (event.getX() / mModelSize));
            else
                setModelIndex((int) (event.getY() / mModelSize));
        }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
    default:
        // Reset action touch variables
        mIsPointerActionDown = false;
        mIsActionDown = false;
        break;
    }

    return true;
}

From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    Log.i(TAG, "onInterceptTouchEvent()");
    final int action = MotionEventCompat.getActionMasked(ev);
    final boolean interceptForDrag = mBottomDragger.shouldInterceptTouchEvent(ev);

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN");
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;//from   ww w  .  ja va  2 s.  c o  m
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE");
        if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2");
            mBottomCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }
    boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    Log.i(TAG, "onInterceptTouchEvent() -- result = " + result);
    return result;
}

From source file:com.aidy.launcher3.support.views.bottomdrawer.BottomDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    Log.i(TAG, "onInterceptTouchEvent()");
    final int action = MotionEventCompat.getActionMasked(ev);
    final boolean interceptForDrag = mBottomDragger.shouldInterceptTouchEvent(ev);

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN");
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;//  ww w  .  j  a va 2s  . co m
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;

        break;
    }

    case MotionEvent.ACTION_MOVE: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE");
        if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2");
            mBottomCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }
    boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    Log.i(TAG, "onInterceptTouchEvent() -- result = " + result);
    return result;
}