Example usage for android.view MotionEvent getY

List of usage examples for android.view MotionEvent getY

Introduction

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

Prototype

public final float getY() 

Source Link

Document

#getY(int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:co.bytera.twodimensionalviewpager.fragment.TwoDimensionalViewPagerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_layout, container, false);

    viewPager = (ViewPager) v.findViewById(R.id.viewPager);

    /*/*from ww  w. j a v  a 2s .com*/
     * To detect the gesture (UP/DOWN/LEFT/RIGHT)
     */
    final GestureDetector gesture = new GestureDetector(getActivity(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onDown(MotionEvent e) {
                    return true;
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    final int SWIPE_MIN_DISTANCE = 120;
                    final int SWIPE_MAX_OFF_PATH = 250;
                    final int SWIPE_THRESHOLD_VELOCITY = 200;

                    try {
                        if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                            /*
                             * finger motion is UP side.  page is moving to next row
                             */
                            adapter.nextRow();
                            adapter.notifyDataSetChanged();
                        } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                            /*
                             * finger motion is DOWN side.  page is moving to previous row
                             */
                            adapter.previousRow();
                            adapter.notifyDataSetChanged();
                        } else if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                            /*
                             * more action can be done here
                             */

                        } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                            /*
                             * more action can be done here
                             */

                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    return super.onFling(e1, e2, velocityX, velocityY);
                }
            });

    /*
     *  set on touch listener to the viewPager
     */
    viewPager.setOnTouchListener(new View.OnTouchListener() {

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

            return gesture.onTouchEvent(event);
        }
    });

    return v;
}

From source file:com.aohuan.dodo.dispatchevent_about.dummy_demo.view1.NestedScrollWebView.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;//from w  w  w  .j  ava 2s  .  c  o  m
    }

    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];
            }
        }

        trackedEvent.recycle();
        result = super.onTouchEvent(trackedEvent);
        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.android.gallery3d.v5.filtershow.category.CategoryView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean ret = super.onTouchEvent(event);
    FilterShowActivity activity = (FilterShowActivity) getContext();

    if (event.getActionMasked() == MotionEvent.ACTION_UP) {
        activity.startTouchAnimation(this, event.getX(), event.getY());
    }/*from   w w  w  .  ja v a 2s . c  o  m*/
    if (!canBeRemoved()) {
        return ret;
    }
    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        mStartTouchY = event.getY();
        mStartTouchX = event.getX();
    }
    if (event.getActionMasked() == MotionEvent.ACTION_UP) {
        setTranslationX(0);
        setTranslationY(0);
    }
    if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        float delta = event.getY() - mStartTouchY;
        if (getOrientation() == CategoryView.VERTICAL) {
            delta = event.getX() - mStartTouchX;
        }
        if (Math.abs(delta) > mDeleteSlope) {
            activity.setHandlesSwipeForView(this, mStartTouchX, mStartTouchY);
        }
    }
    return true;
}

From source file:com.app.gongza.libs.view.scrollablelayout.ScrollableLayout.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentX = ev.getX();
    float currentY = ev.getY();
    float deltaY;
    int shiftX = (int) Math.abs(currentX - mDownX);
    int shiftY = (int) Math.abs(currentY - mDownY);
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mDisallowIntercept = false;//from w w w. j  a v  a 2s. c  o  m
        needCheckUpdown = true;
        updown = true;
        mDownX = currentX;
        mDownY = currentY;
        mLastY = currentY;
        checkIsClickHead((int) currentY, mHeadHeight, getScrollY());
        checkIsClickHeadExpand((int) currentY, mHeadHeight, getScrollY());
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        mScroller.forceFinished(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDisallowIntercept) {
            break;
        }
        initVelocityTrackerIfNotExists();
        mVelocityTracker.addMovement(ev);
        deltaY = mLastY - currentY;
        if (needCheckUpdown) {
            if (shiftX > mTouchSlop && shiftX > shiftY) {
                needCheckUpdown = false;
                updown = false;
            } else if (shiftY > mTouchSlop && shiftY > shiftX) {
                needCheckUpdown = false;
                updown = true;
            }
        }

        if (updown && shiftY > mTouchSlop && shiftY > shiftX
                && (!isSticked() || mHelper.isTop() || isClickHeadExpand)) {

            if (childViewPager != null) {
                childViewPager.requestDisallowInterceptTouchEvent(true);
            }
            scrollBy(0, (int) (deltaY + 0.5));
        }
        mLastY = currentY;
        break;
    case MotionEvent.ACTION_UP:
        if (updown && shiftY > shiftX && shiftY > mTouchSlop) {
            mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            float yVelocity = -mVelocityTracker.getYVelocity();
            boolean dislowChild = false;
            if (Math.abs(yVelocity) > mMinimumVelocity) {
                mDirection = yVelocity > 0 ? DIRECTION.UP : DIRECTION.DOWN;
                if ((mDirection == DIRECTION.UP && isSticked())
                        || (!isSticked() && getScrollY() == 0 && mDirection == DIRECTION.DOWN)) {
                    dislowChild = true;
                } else {
                    mScroller.fling(0, getScrollY(), 0, (int) yVelocity, 0, 0, -Integer.MAX_VALUE,
                            Integer.MAX_VALUE);
                    mScroller.computeScrollOffset();
                    mLastScrollerY = getScrollY();
                    invalidate();
                }
            }
            if (!dislowChild && (isClickHead || !isSticked())) {
                int action = ev.getAction();
                ev.setAction(MotionEvent.ACTION_CANCEL);
                boolean dispathResult = super.dispatchTouchEvent(ev);
                ev.setAction(action);
                return dispathResult;
            }
        }
        break;
    default:
        break;
    }
    super.dispatchTouchEvent(ev);
    return true;
}

From source file:com.cssweb.android.view.FTrendView.java

public void touchesBegan(MotionEvent event) {
    isTouched = true;
    isTouchMoved = false;
    startPositionX = event.getX();
    startPositionY = event.getY();
}

From source file:com.librelio.activity.StartupActivity.java

private void setOnAdvertisingImageClickListener(final String link) {
    if (advertisingImage != null) {
        advertisingImage.setOnTouchListener(new OnTouchListener() {
            //            @Override
            //            public void onClick(View v) {
            //               advertisingClickPerformed = true;
            ///*from  ww w .j  a v a 2 s .  c  o m*/
            //               startAdsActivity(link);
            //            }

            @Override
            public boolean onTouch(View pView, MotionEvent pEvent) {
                if (pEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    // check the Y coordinates of the touch event
                    float pY = pEvent.getY();
                    int pHeight = pView.getHeight();
                    if (Math.round(pY / 0.2) <= pHeight) {
                        // Skip ads
                        if (mStartupAdsTimer != null)
                            mStartupAdsTimer.cancel();
                        startMainMagazineActivity();
                    } else {
                        // Show ads
                        if (mStartupAdsTimer != null)
                            mStartupAdsTimer.cancel();
                        startAdsActivity(link);
                    }
                }
                return false;
            }
        });
    }
}

From source file:com.baoyz.dribble.widget.SuperRecyclerView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {

    boolean b = super.onInterceptTouchEvent(e);

    int actionMasked = MotionEventCompat.getActionMasked(e);
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN:
        mDownX = e.getX();/*from w w w. ja  va  2s  .co m*/
        mDownY = e.getY();
        mInterceptTouch = false;
        break;
    case MotionEvent.ACTION_MOVE:
        float offsetX = e.getX() - mDownX;
        if (!b && Math.abs(offsetX) > mTouchDistance)
            mInterceptTouch = true;
        break;
    }

    if (mInterceptTouch)
        return false;

    return b;
}

From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (this.sections == null || this.sections.size() < 1)
        return super.onTouchEvent(event);
    float eventY = event.getY();
    int action = event.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        this.setBackgroundColor(Color.TRANSPARENT);
        this.floatView.setVisibility(INVISIBLE);
        return true;
    }/*  w ww  .  ja  v a2 s .c  o  m*/
    if (this.touchWrapArea && eventY < this.drawBeginY || eventY > this.drawEndY) {
        return super.onTouchEvent(event);
    }
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        this.setBackgroundColor(this.viewBackground);
        this.floatView.setVisibility(VISIBLE);
        this.showFloatView(eventY);
        return true;
    case MotionEvent.ACTION_MOVE:
        this.showFloatView(eventY);
        return true;
    }
    return super.onTouchEvent(event);
}

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

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mMotionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
        break;//from  w ww  .  j  a va2 s.  c om
    }
    return super.onTouchEvent(ev);
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

    final float x = ev.getX();
    final float y = ev.getY();
    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_DOWN && touchTarget == null && stickyWrapper != null
            && isStickyViewTouched(stickyWrapper.view, x, y)) {
        touchTarget = stickyWrapper.view;
        touchPt.x = x;// w  w w  . j ava 2  s.co m
        touchPt.y = y;

        downEvent = MotionEvent.obtain(ev);
    }

    if (touchTarget != null) {
        if (isStickyViewTouched(touchTarget, x, y)) {
            // forward event to header view
            touchTarget.dispatchTouchEvent(ev);
        }

        if (action == MotionEvent.ACTION_UP) {
            super.dispatchTouchEvent(ev);
            clearTouchTarget();

        } else if (action == MotionEvent.ACTION_CANCEL) {
            clearTouchTarget();

        } else if (action == MotionEvent.ACTION_MOVE) {
            if (Math.abs(y - touchPt.y) > touchSlop) {

                MotionEvent event = MotionEvent.obtain(ev);
                event.setAction(MotionEvent.ACTION_CANCEL);
                touchTarget.dispatchTouchEvent(event);
                event.recycle();

                super.dispatchTouchEvent(downEvent);
                super.dispatchTouchEvent(ev);
                clearTouchTarget();

            }
        }

        return true;
    }

    return super.dispatchTouchEvent(ev);
}