Code example for MotionEvent

Methods: getActiongetYsetAction

0
        return super.onTouchEvent(ev);
    } 
 
    @Override 
    public boolean dispatchTouchEvent(final MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_MOVE && getFirstVisiblePosition() == 0) {
            float direction = ev.getY() - mHistoricalY;
            int height = (int) (ev.getY() - mY) / 2 + mInitialHeight;
            if (height < 0) {
                height = 0;
            } 
 
            float deltaY = Math.abs(mY - ev.getY());
            ViewConfiguration config = ViewConfiguration.get(getContext());
            if (deltaY > config.getScaledTouchSlop()) {
 
                // Scrolling downward 
                if (direction > 0) {
                    // Refresh bar is extended if top pixel of the first item is 
                    // visible 
                    if (getChildAt(0).getTop() == 0) {
                        if (mHistoricalTop < 0) {
 
                            // mY = ev.getY(); // TODO works without 
                            // this?mHistoricalTop = 0; 
                        } 
 
                        // Extends refresh bar 
                        setHeaderHeight(height);
 
                        // Stop list scroll to prevent the list from 
                        // overscrolling 
                        ev.setAction(MotionEvent.ACTION_CANCEL);
                        mFlag = false;
                    } 
                } else if (direction < 0) {
                    // Scrolling upward 
 
                    // Refresh bar is shortened if top pixel of the first item 
                    // is 
                    // visible 
                    if (getChildAt(0).getTop() == 0) {
                        setHeaderHeight(height);
 
                        // If scroll reaches top of the list, list scroll is 
                        // enabled 
                        if (getChildAt(1) != null && getChildAt(1).getTop() <= 1 && !mFlag) {
                            ev.setAction(MotionEvent.ACTION_DOWN);
                            mFlag = true;
                        } 
                    } 
                } 
            } 
 
            mHistoricalY = ev.getY();
        } 
        try { 
            return super.dispatchTouchEvent(ev);
        } catch (Exception e) {
            return false;