Example usage for android.view MotionEvent ACTION_OUTSIDE

List of usage examples for android.view MotionEvent ACTION_OUTSIDE

Introduction

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

Prototype

int ACTION_OUTSIDE

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

Click Source Link

Document

Constant for #getActionMasked : A movement has happened outside of the normal bounds of the UI element.

Usage

From source file:org.zywx.wbpalmstar.engine.EBounceView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }/*from w  ww  . j  a v  a2s  .com*/
    mVelocityTracker.addMovement(event);
    int y = (int) event.getRawY();
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastY = y;
        break;
    case MotionEvent.ACTION_MOVE:
        int m = y - mLastY;
        if (mIsTop) {
            moveDown(m);
        } else if (mIsBottom) {
            moveUp(m);
        }
        mLastY = y;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        reverse();
        handlerTracker();
        break;
    }
    return true;
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

@Override
public void onTouchEvent(final RecyclerView recyclerView, final MotionEvent event) {
    // We should only be here if we intercepted the touch due to swipe.
    Assert.isTrue(mIsSwiping);/*w  w w.jav a  2  s.c  om*/

    // We are now tracking a swipe gesture.
    mVelocityTracker.addMovement(event);

    final int action = event.getActionMasked();
    switch (action) {
    case MotionEvent.ACTION_OUTSIDE:
    case MotionEvent.ACTION_MOVE:
        if (hasValidGestureSwipeTarget()) {
            mListItemView.setSwipeTranslationX(event.getX() - mInitialX);
        }
        break;
    case MotionEvent.ACTION_UP:
        if (hasValidGestureSwipeTarget()) {
            final float maxVelocity = mMaximumFlingVelocity;
            mVelocityTracker.computeCurrentVelocity(UNIT_SECONDS, maxVelocity);
            final float velocityX = getLastComputedXVelocity();

            final float translationX = mListItemView.getSwipeTranslationX();

            int swipeDirection = SWIPE_DIRECTION_NONE;
            if (translationX != 0) {
                swipeDirection = translationX > 0 ? SWIPE_DIRECTION_RIGHT : SWIPE_DIRECTION_LEFT;
            } else if (velocityX != 0) {
                swipeDirection = velocityX > 0 ? SWIPE_DIRECTION_RIGHT : SWIPE_DIRECTION_LEFT;
            }

            final boolean fastEnough = isTargetSwipedFastEnough();
            final boolean farEnough = isTargetSwipedFarEnough();

            final boolean shouldDismiss = (fastEnough || farEnough);

            if (shouldDismiss) {
                if (fastEnough) {
                    animateDismiss(mListItemView, velocityX);
                } else {
                    animateDismiss(mListItemView, swipeDirection);
                }
            } else {
                animateRestore(mListItemView, velocityX);
            }

            onSwipeGestureEnd(mListItemView, shouldDismiss ? swipeDirection : SWIPE_DIRECTION_NONE);
        } else {
            onGestureEnd();
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (hasValidGestureSwipeTarget()) {
            animateRestore(mListItemView, 0f);
            onSwipeGestureEnd(mListItemView, SWIPE_DIRECTION_NONE);
        } else {
            onGestureEnd();
        }
        break;
    }
}

From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    int action = event.getAction();
    action = action & MotionEvent.ACTION_MASK;

    mGestureDetector.onTouchEvent(event);
    mScaleGestureDetector.onTouchEvent(event);
    if (mInteractionMode == InteractionMode.SCALE) {
        return true;
    }/*  w  w w . j  a v  a2s.c o  m*/

    int ex = (int) event.getX();
    int ey = (int) event.getY();
    if (action == MotionEvent.ACTION_DOWN) {
        mInteractionMode = InteractionMode.MOVE;
        mTouchDown.x = ex;
        mTouchDown.y = ey;
        System.currentTimeMillis();
        mMasterImage.setOriginalTranslation(mMasterImage.getTranslation());
    }

    if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) {
        mTouch.x = ex;
        mTouch.y = ey;

        float scaleFactor = mMasterImage.getScaleFactor();
        if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) {
            float translateX = (mTouch.x - mTouchDown.x) / scaleFactor;
            float translateY = (mTouch.y - mTouchDown.y) / scaleFactor;
            Point originalTranslation = mMasterImage.getOriginalTranslation();
            Point translation = mMasterImage.getTranslation();
            translation.x = (int) (originalTranslation.x + translateX);
            translation.y = (int) (originalTranslation.y + translateY);
            mMasterImage.setTranslation(translation);
        }
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mInteractionMode = InteractionMode.NONE;
        mTouchDown.x = 0;
        mTouchDown.y = 0;
        mTouch.x = 0;
        mTouch.y = 0;
        if (mMasterImage.getScaleFactor() <= 1) {
            mMasterImage.setScaleFactor(1);
            mMasterImage.resetTranslation();
        }
    }
    float scaleFactor = mMasterImage.getScaleFactor();
    Point translation = mMasterImage.getTranslation();
    constrainTranslation(translation, scaleFactor);
    mMasterImage.setTranslation(translation);

    invalidate();
    return true;
}

From source file:com.cnh.library.materialdrawer.view.BezelImageView.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Check for clickable state and do nothing if disabled
    if (!this.isClickable()) {
        this.isSelected = false;
        return super.onTouchEvent(event);
    }//w w w .  java  2s .  co m

    // Set selected state based on Motion Event
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        this.isSelected = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_SCROLL:
    case MotionEvent.ACTION_OUTSIDE:
    case MotionEvent.ACTION_CANCEL:
        this.isSelected = false;
        break;
    }

    // Redraw image and return super type
    this.invalidate();
    return super.dispatchTouchEvent(event);
}

From source file:com.freegeek.android.materialbanner.MaterialBanner.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

    int action = ev.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        if (canTurn)
            startTurning(autoTurningTime);
    } else if (action == MotionEvent.ACTION_DOWN) {
        if (canTurn)
            stopTurning();/* ww  w .  j  av  a2 s  .c o  m*/
    }
    return super.dispatchTouchEvent(ev);
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void handleChild(View child, int columnCount, LinearLayout keyContainer, int keyHeight) {
    child.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.amharic_key_bg));
    child.setOnTouchListener(new OnTouchListener() {
        @Override/*  w w w . java 2  s .c  om*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (shouldVibrate) {
                    Vibrator vb = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    if (vb != null) {
                        vb.vibrate(20);
                    }
                }
                mPressedKeyView = v;
                mHandler.removeCallbacks(mKeyPressRunnable);
                mHandler.postAtTime(mKeyPressRunnable, mPressedKeyView,
                        SystemClock.uptimeMillis() + INITIAL_INTERVAL);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_OUTSIDE:
                mHandler.removeCallbacksAndMessages(mPressedKeyView);
                mPressedKeyView = null;
                mNormalInterval = 100;
                break;
            }
            return false;
        }
    });
    child.setOnClickListener(mKeyClickListener);
    int margin = getCustomSize(1.5f);
    int tempKeyHeight = keyHeight - (margin * 2);
    LayoutParams params = new LayoutParams(0, tempKeyHeight, columnCount);
    params.setMargins(margin, margin, margin, margin);
    keyContainer.addView(child, params);
}

From source file:com.waz.zclient.ui.audiomessage.AudioMessageRecordingView.java

public void onMotionEventFromAudioMessageButton(MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
    case MotionEvent.ACTION_MOVE:
        if (slidedUpToSend(motionEvent)) {
            setSlideControlState(SlideControlState.SEND_FROM_RECORDING);
        } else {/* w  ww.  j av a  2 s .c  om*/
            setSlideControlState(SlideControlState.RECORDING);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
    case MotionEvent.ACTION_UP:
        if (recordingControls == null) {
            // recordingControls might be gone while user is long pressing e.g. when cancel is clicked at same time
            break;
        }
        if (slideControlState == SlideControlState.SEND_FROM_RECORDING) {
            // SLIDE UP TO INSTANT SEND
            sendImmediately = true;
        } else if (slideControlState == SlideControlState.RECORDING) {
            sendImmediately = false;
            setSlideControlState(SlideControlState.PREVIEW);
        }
        if (recordingControls != null) {
            recordingControls.stop();
        }
        break;
    }
}

From source file:com.slidinglayer.SlidingPanel.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
        return false;
    }//from   w ww  . ja  v a2 s.  c  om

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

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

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsDragging = true;
                mLastX = x;
                setDrawingCacheEnabled(true);
            } else if (yDiff > mTouchSlop && yDiff > xDiff) {
                mIsDragging = true;
                mLastY = y;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final float deltaX = mLastX - x;
            final float deltaY = mLastY - y;
            mLastX = x;
            mLastY = y;
            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY));
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            topBound = getHeight();
            bottomBound = rightBound = leftBound = 0;
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;
            scrollTo((int) scrollX, (int) scrollY);
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final int totalDeltaX = (int) (x - mInitialX);
            final int totalDeltaY = (int) (y - mInitialY);

            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX,
                    initialVelocityY, totalDeltaX, totalDeltaY);
            switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
            openLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:com.kaplandroid.colorbook.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHere(ev)) {
        return false;
    }/*from  ww w.jav  a 2 s.  c  o  m*/

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

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

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsDragging = true;
                mLastX = x;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float deltaX = mLastX - x;
            mLastX = x;
            float oldScrollX = getScrollX();
            float scrollX = oldScrollX + deltaX;
            final float leftBound = mScreenSide < STICK_TO_RIGHT ? getWidth() : 0;
            final float rightBound = mScreenSide == STICK_TO_LEFT ? 0 : -getWidth();
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            scrollTo((int) scrollX, getScrollY());
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
            final int scrollX = getScrollX();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final int totalDelta = (int) (x - mInitialX);
            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, initialVelocity, totalDelta);
            switchLayer(nextStateOpened, true, true, initialVelocity);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastX = x;
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:org.ligi.gobandroid_hd.ui.GoActivity.java

public void doTouch(MotionEvent event) {

    // calculate position on the field by position on the touchscreen

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
        interaction_scope.setTouchPosition(getBoard().pixel2cell(event.getX(), event.getY()));
        break;/*from  w ww .j a v  a  2  s .  c o  m*/

    case MotionEvent.ACTION_OUTSIDE:
        interaction_scope.setTouchPosition(null);
        break;

    case MotionEvent.ACTION_UP:

        if (go_board.move_stone_mode) {
            // TODO check if this is an illegal move ( e.g. in variants )

            if (getGame().getVisualBoard().isCellFree(interaction_scope.getTouchCell())) {
                getGame().getActMove().setCell(interaction_scope.getTouchCell());
                getGame().getActMove().setDidCaptures(true); // TODO check if we harm sth with that
                getGame().refreshBoards();
            }
            go_board.move_stone_mode = false; // moving of stone done
        } else if ((getGame().getActMove().isOnCell(interaction_scope.getTouchCell()))) {
            initializeStoneMove();
        } else {
            doMoveWithUIFeedback(interaction_scope.getTouchCell());
        }

        interaction_scope.setTouchPosition(null);
        break;
    }

    getGame().notifyGameChange();
}