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:com.andview.refreshview.swipe.SwipeMenuLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mVelocityTracker == null)
        mVelocityTracker = VelocityTracker.obtain();
    mVelocityTracker.addMovement(ev);//  w ww  .  j  a  va  2s . c o m
    int dx;
    int dy;
    int action = ev.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastX = (int) ev.getX();
        mLastY = (int) ev.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (!isSwipeEnable())
            break;
        int disX = (int) (mLastX - ev.getX());
        int disY = (int) (mLastY - ev.getY());
        if (!mDragging && Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY)) {
            mDragging = true;
        }
        if (mDragging) {
            if (mSwipeCurrentHorizontal == null || shouldResetSwipe) {
                if (disX < 0) {
                    if (mSwipeLeftHorizontal != null)
                        mSwipeCurrentHorizontal = mSwipeLeftHorizontal;
                    else
                        mSwipeCurrentHorizontal = mSwipeRightHorizontal;
                } else {
                    if (mSwipeRightHorizontal != null)
                        mSwipeCurrentHorizontal = mSwipeRightHorizontal;
                    else
                        mSwipeCurrentHorizontal = mSwipeLeftHorizontal;
                }
            }
            scrollBy(disX, 0);
            mLastX = (int) ev.getX();
            mLastY = (int) ev.getY();
            shouldResetSwipe = false;
        }
        break;
    case MotionEvent.ACTION_UP:
        dx = (int) (mDownX - ev.getX());
        dy = (int) (mDownY - ev.getY());
        mDragging = false;
        mVelocityTracker.computeCurrentVelocity(1000, mScaledMaximumFlingVelocity);
        int velocityX = (int) mVelocityTracker.getXVelocity();
        int velocity = Math.abs(velocityX);
        if (velocity > mScaledMinimumFlingVelocity) {
            if (mSwipeCurrentHorizontal != null) {
                int duration = getSwipeDuration(ev, velocity);
                if (mSwipeCurrentHorizontal instanceof SwipeRightHorizontal) {
                    if (velocityX < 0) {
                        smoothOpenMenu(duration);
                    } else {
                        smoothCloseMenu(duration);
                    }
                } else {
                    if (velocityX > 0) {
                        smoothOpenMenu(duration);
                    } else {
                        smoothCloseMenu(duration);
                    }
                }
                ViewCompat.postInvalidateOnAnimation(this);
            }
        } else {
            judgeOpenClose(dx, dy);
        }
        mVelocityTracker.clear();
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        if (Math.abs(mDownX - ev.getX()) > mScaledTouchSlop || Math.abs(mDownY - ev.getY()) > mScaledTouchSlop
                || isMenuOpen()) {
            ev.setAction(MotionEvent.ACTION_CANCEL);
            super.onTouchEvent(ev);
            return true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        mDragging = false;
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        } else {
            dx = (int) (mDownX - ev.getX());
            dy = (int) (mDownY - ev.getY());
            judgeOpenClose(dx, dy);
        }
        break;
    }
    return super.onTouchEvent(ev);
}

From source file:br.com.halph.agendafeliz.util.SwipeableRecyclerViewTouchListener.java

private boolean handleTouchEvent(MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }// w ww  .j  av a  2s .  co  m

    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            break;
        }

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mRecyclerView.getChildCount();
        int[] listViewCoords = new int[2];
        mRecyclerView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = mRecyclerView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                mDownView = child;
                break;
            }
        }

        if (mDownView != null && mAnimatingPosition != mRecyclerView.getChildLayoutPosition(mDownView)) {
            mAlpha = ViewCompat.getAlpha(mDownView);
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildLayoutPosition(mDownView);
            mSwipingLeft = mSwipeListener.canSwipeLeft(mDownPosition);
            mSwipingRight = mSwipeListener.canSwipeRight(mDownPosition);
            if (mSwipingLeft || mSwipingRight) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        if (mDownView != null && mSwiping) {
            // cancel
            ViewCompat.animate(mDownView).translationX(0).alpha(mAlpha).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        mFinalDelta = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(mFinalDelta) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = mFinalDelta > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (mFinalDelta < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != mAnimatingPosition && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            mAnimatingPosition = mDownPosition;
            ViewCompat.animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new ViewPropertyAnimatorListener() {
                        @Override
                        public void onAnimationStart(View view) {
                            // Do nothing.
                        }

                        @Override
                        public void onAnimationEnd(View view) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                performDismiss(downView, downPosition);
                            }
                        }

                        @Override
                        public void onAnimationCancel(View view) {
                            // Do nothing.
                        }
                    });
        } else {
            // cancel
            ViewCompat.animate(mDownView).translationX(0).alpha(mAlpha).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
        }

        if (deltaX < 0 && !mSwipingLeft)
            mSwiping = false;
        if (deltaX > 0 && !mSwipingRight)
            mSwiping = false;

        if (mSwiping) {
            ViewCompat.setTranslationX(mDownView, deltaX - mSwipingSlop);
            ViewCompat.setAlpha(mDownView,
                    Math.max(0f, Math.min(mAlpha, mAlpha * (1f - Math.abs(deltaX) / mViewWidth))));
            return true;
        }
        break;
    }
    }

    return false;
}

From source file:com.android_mobile.core.ui.comp.banner.LoopViewPager.java

/**
 * ??//from  w  ww .  j  a  va 2 s .c  o  m
 */
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        // 
        if (getAdapter().getCount() > 0 && autoable) {
            startImageTimerTask();
        }
    } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // ?
        stopImageTimerTask();
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!mCanPickRange) {
        return super.onInterceptTouchEvent(ev);
    }/* ww w  .j  ava 2s .  co m*/

    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        if (Config.DEBUG) {
            Log.i(TAG, "OITE: DOWN");
        }

        mInitialDownX = ev.getX();
        mInitialDownY = ev.getY();

        if (mCheckForLongPress == null) {
            mCheckForLongPress = new CheckForLongPress();
        }

        postDelayed(mCheckForLongPress, ViewConfiguration.getLongPressTimeout());
    } else if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
        if (Config.DEBUG) {
            Log.i(TAG, "OITE: (UP || CANCEL)");
        }

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

        mIsLongPressed = false;
        mInitialDownX = -1;
        mInitialDownY = -1;
    } else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
        if (Config.DEBUG) {
            Log.i(TAG, "OITE: MOVE");
        }

        if (!isStillALongPress((int) ev.getX(), (int) ev.getY())) {
            if (Config.DEBUG) {
                Log.i(TAG, "OITE: MOVED TOO MUCH, CANCELLING CheckForLongPress Runnable");
            }

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

    return mIsLongPressed || super.onInterceptTouchEvent(ev);
}

From source file:com.audionote.widget.SlideSwitch.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (slideable == false)
        return super.onTouchEvent(event);
    int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        eventStartX = (int) event.getRawX();
        break;/*  w ww  .  ja  v  a 2 s .  c om*/
    case MotionEvent.ACTION_MOVE:
        eventLastX = (int) event.getRawX();
        diffX = eventLastX - eventStartX;
        int tempX = diffX + frontRect_left_begin;
        tempX = (tempX > max_left ? max_left : tempX);
        tempX = (tempX < min_left ? min_left : tempX);
        if (tempX >= min_left && tempX <= max_left) {
            frontRect_left = tempX;
            alpha = (int) (255 * (float) tempX / (float) max_left);
            invalidateView();
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        int wholeX = (int) (event.getRawX() - eventStartX);
        frontRect_left_begin = frontRect_left;
        boolean toRight;
        toRight = (frontRect_left_begin > max_left / 2 ? true : false);
        if (Math.abs(wholeX) < 3) {
            toRight = !toRight;
        }
        moveToDest(toRight);
        break;
    default:
        Log.d("motion", action + "");
        break;
    }
    return true;
}

From source file:com.timemachine.controller.ControllerActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Detect the general touch event of the entire screen
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        try {//from   www . j  av  a2s  .  c  om
            if (isEditorEnabled)
                stopHideEditorTimer();
            else
                locationSlider.loadUrl("javascript:stopScreenIdleTimeout()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (!isAutoModeDelayTimeoutRunning && event.getAction() == MotionEvent.ACTION_UP) {
        try {
            if (isEditorEnabled)
                runHideEditorTimer();
            else
                locationSlider.loadUrl("javascript:startScreenIdleTimeout()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(@NonNull MotionEvent event) {
    ensureTarget();// ww  w  . j ava  2  s  . co  m

    if (!isEnabled() || canChildScrollUp() || isRefreshing()) {
        return false;
    }

    final int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(event, 0);
        mFirstTouchDownPointY = getMotionEventY(event, mActivePointerId);
        break;

    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
            return false;
        }

        final float currentY = getMotionEventY(event, mActivePointerId);

        if (currentY == -1) {
            return false;
        }

        if (mFirstTouchDownPointY == -1) {
            mFirstTouchDownPointY = currentY;
        }

        final float yDiff = currentY - mFirstTouchDownPointY;

        // State is changed to drag if over slop
        if (yDiff > ViewConfiguration.get(getContext()).getScaledTouchSlop() && !isRefreshing()) {
            mCircleView.makeProgressTransparent();
            return true;
        }

        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return false;
}

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  ww .  j a  v a 2s  . c  o m*/

    this.multitouchQueue.add(js);
}

From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_anm);
    orgnlImageView = (ImageView) findViewById(R.id.imageView);
    orgnlImageView.setMaxHeight(800);/*w  w  w . j  av  a2s.  c om*/
    orgnlImageView.setMaxWidth(600);
    crt_ctx = this;

    BitmapFactory.Options bmp_opt = new BitmapFactory.Options();
    bmp_opt.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;

    // - Now we need to set the GUI ImageView data with data read from the picked file.
    DcodRszdBmpFil dcodRszdBmpFil = new DcodRszdBmpFil();
    Bitmap bmp = dcodRszdBmpFil.DcodRszdBmpFil(SelectImageActivity.orgFil, bmp_opt);

    // Now we need to set the GUI ImageView data with the orginal file selection.
    orgnlImageView.setImageBitmap(bmp);
    orgnl_iv_wdth = bmp.getWidth();
    orgnl_iv_hght = bmp.getHeight();
    final RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo);
    scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener());

    orgnlImageView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getPointerCount() > 1 || flgInScale) {

                scaleGestureDetector.onTouchEvent(event);
                return true;
            }

            int end_hrz;
            int end_vrt;
            final int pointerIndex;

            switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                bgn_hrz = (int) MotionEventCompat.getX(event, pointerIndex);
                bgn_vrt = (int) MotionEventCompat.getY(event, pointerIndex);

                String log_str = "Beginning coordinates: Horz = " + String.valueOf(bgn_hrz) + "; Vert = "
                        + String.valueOf(bgn_vrt);

                Log.d("OnTouchListener", log_str);
                orlp = (RelativeLayout.LayoutParams) orgnlImageView.getLayoutParams();
                bgn_top = (int) orlp.topMargin;
                bgn_lft = (int) orlp.leftMargin;

                // To prevent an initial jump of the magnifier, aposX and aPosY must
                // have the values from the magnifier frame
                if (aPosX == 0)
                    aPosX = orgnlImageView.getX();
                if (aPosY == 0)
                    aPosY = orgnlImageView.getY();
                break;

            case MotionEvent.ACTION_MOVE:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                float crt_hrz = MotionEventCompat.getX(event, pointerIndex);
                float crt_vrt = MotionEventCompat.getY(event, pointerIndex);
                final float dx = crt_hrz - bgn_hrz;
                final float dy = crt_vrt - bgn_vrt;
                aPosX += dx;
                aPosY += dy;
                orgnlImageView.setX(aPosX);
                orgnlImageView.setY(aPosY);

                log_str = "Current Position: Horz = " + String.valueOf(crt_hrz) + "; Vert = "
                        + String.valueOf(crt_vrt);

                Log.d("OnTouchListener", log_str);

                break;

            case MotionEvent.ACTION_UP:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                end_hrz = (int) MotionEventCompat.getX(event, pointerIndex);
                end_vrt = (int) MotionEventCompat.getY(event, pointerIndex);
            }

            rel_anm_lo.invalidate();
            return true;
        }
    });

    sav_anm_btn = (Button) findViewById(R.id.sav_btn);

    sav_anm_btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View vw) {

            onClickFlg = 1;
            RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo);
            rel_anm_lo.removeView(vw);
            Bitmap tnBmp = getWrtBmp("thumbnail", rel_anm_lo, 40);
            tnBmp.recycle();
            int vw_nmbr = anmViews.size();

            for (int vw_mbr = 1; vw_mbr < vw_nmbr; vw_mbr += 1) {

                anim_view = anmViews.get(vw_mbr);

                if (anim_view != null) {

                    Animation crt_anm = anim_view.getAnimation();

                    if (crt_anm != null)
                        crt_anm.cancel();

                    anim_view.setAnimation(null);
                    rel_anm_lo.removeView(anim_view);

                    // Garbage collect the bitmap
                    Drawable drawable = anim_view.getDrawable();

                    if (drawable instanceof BitmapDrawable) {
                        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                        Bitmap anim_bmp = bitmapDrawable.getBitmap();
                        anim_bmp.recycle();
                    }
                }
            }

            Bitmap orgnlImageBmp = getWrtBmp("bgimg", rel_anm_lo, 90);
            orgnlImageWdth = Integer.toString(orgnlImageBmp.getWidth());
            orgnlImageHght = Integer.toString(orgnlImageBmp.getHeight());
            anmViews.clear();
            unbindDrawables(rel_anm_lo);
            ((RelativeLayout) rel_anm_lo).removeAllViews();
            orgnlImageBmp.recycle();
            crt_ctx = null;
            orgnlImageView = null;

            Intent intent = new Intent(AnimActivity.this, com.acceleratedio.pac_n_zoom.SaveAnmActivity.class);

            startActivity(intent);
        }
    });

    progress = ProgressDialog.show(crt_ctx, "Loading the animation", "dialog message", true);
    GetRequest get_svg_img = new GetRequest();
    get_svg_img.execute("");
}

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

/**
 * Handles forwarded motion events and determines when to stop
 * forwarding./*from ww w  .j  a  va  2  s . co  m*/
 *
 * @param srcEvent motion event in source view coordinates
 * @return true to continue forwarding motion events, false to cancel
 */
private boolean onTouchForwarded(MotionEvent srcEvent) {
    final View src = mSrc;
    final ShowableListMenu popup = getPopup();
    if (popup == null || !popup.isShowing()) {
        return false;
    }

    final DropDownListView dst = (DropDownListView) popup.getListView();
    if (dst == null || !dst.isShown()) {
        return false;
    }

    // Convert event to destination-local coordinates.
    final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
    toGlobalMotionEvent(src, dstEvent);
    toLocalMotionEvent(dst, dstEvent);

    // Forward converted event to destination view, then recycle it.
    final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId);
    dstEvent.recycle();

    // Always cancel forwarding when the touch stream ends.
    final int action = MotionEventCompat.getActionMasked(srcEvent);
    final boolean keepForwarding = action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_CANCEL;

    return handled && keepForwarding;
}