Java Code Examples for android.view.MotionEvent#getEdgeFlags()

The following examples show how to use android.view.MotionEvent#getEdgeFlags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StickyGridHeadersGridView.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private MotionEvent transformEvent(MotionEvent e, int headerPosition) {
    if (headerPosition == MATCHED_STICKIED_HEADER) {
        return e;
    }

    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    MotionEvent.PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();

    View headerHolder = getChildAt(headerPosition);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].y -= headerHolder.getTop();
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
Example 2
Source File: PLAListView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mItemsCanFocus && ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // Don't handle edge touches immediately -- they may actually belong to one of our
        // descendants.
        return false;
    }
    return super.onTouchEvent(ev);
}
 
Example 3
Source File: TwoDScrollView.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
/*********************************************************
 * Touch processing
 *********************************************************/

@Override
public boolean onInterceptTouchEvent(MotionEvent event)
{
    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0)
    {
        // Don't handle edge touches immediately -- they may actually belong to one of our
        // descendants.
        return false;
    }
    onTouchEvent(event);
    return mGestureListener.isMoved;
}
 
Example 4
Source File: StickyGridHeadersGridView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private MotionEvent transformEvent(MotionEvent e, int headerPosition) {
    if (headerPosition == MATCHED_STICKIED_HEADER) {
        return e;
    }

    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    MotionEvent.PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();

    View headerHolder = getChildAt(headerPosition);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].y -= headerHolder.getTop();
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
Example 5
Source File: PullToRefreshBase.java    From FacebookNewsfeedSample-Android with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 6
Source File: PullToRefreshBase.java    From bmob-android-demo-paging with GNU General Public License v3.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 7
Source File: PullToRefreshBase.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 8
Source File: PullToRefreshBase.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 9
Source File: PullToRefreshBase.java    From GifAssistant with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 10
Source File: PullToZoomBase.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (!isPullToZoomEnabled() || isHideHeader()) {
        return false;
    }

    if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE: {
            if (mIsBeingDragged) {
                mLastMotionY = event.getY();
                mLastMotionX = event.getX();
                pullEvent();
                isZooming = true;
                return true;
            }
            break;
        }

        case MotionEvent.ACTION_DOWN: {
            if (isReadyForPullStart()) {
                mLastMotionY = mInitialMotionY = event.getY();
                mLastMotionX = mInitialMotionX = event.getX();
                return true;
            }
            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            if (mIsBeingDragged) {
                mIsBeingDragged = false;
                // If we're already refreshing, just scroll back to the top
                if (isZooming()) {
                    smoothScrollToTop();
                    if (onPullZoomListener != null) {
                        onPullZoomListener.onPullZoomEnd();
                    }
                    isZooming = false;
                    return true;
                }
                return true;
            }
            break;
        }
    }
    return false;
}
 
Example 11
Source File: PullToRefreshBase.java    From zen4android with MIT License 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 12
Source File: PullToRefreshBase.java    From SwipeMenuAndRefresh with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 13
Source File: PullToZoomBase.java    From likequanmintv with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent( MotionEvent event) {
    if (!isPullToZoomEnabled() || isHideHeader()) {
        return false;
    }

    if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE: {
            if (mIsBeingDragged) {
                mLastMotionY = event.getY();
                mLastMotionX = event.getX();
                pullEvent();
                isZooming = true;
                return true;
            }
            break;
        }

        case MotionEvent.ACTION_DOWN: {
            if (isReadyForPullStart()) {
                mLastMotionY = mInitialMotionY = event.getY();
                mLastMotionX = mInitialMotionX = event.getX();
                return true;
            }
            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            if (mIsBeingDragged) {
                mIsBeingDragged = false;
                // If we're already refreshing, just scroll back to the top
                if (isZooming()) {
                    smoothScrollToTop();
                    if (onPullZoomListener != null) {
                        onPullZoomListener.onPullZoomEnd();
                    }
                    isZooming = false;
                    return true;
                }
                return true;
            }
            break;
        }
    }
    return false;
}
 
Example 14
Source File: PullToRefreshBase.java    From handmarkPulltorefreshLibrary with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN
			&& event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
	case MotionEvent.ACTION_MOVE: {
		if (mIsBeingDragged) {
			mLastMotionY = event.getY();
			mLastMotionX = event.getX();
			pullEvent();
			return true;
		}
		break;
	}

	case MotionEvent.ACTION_DOWN: {
		if (isReadyForPull()) {
			mLastMotionY = mInitialMotionY = event.getY();
			mLastMotionX = mInitialMotionX = event.getX();
			return true;
		}
		break;
	}

	case MotionEvent.ACTION_CANCEL:
	case MotionEvent.ACTION_UP: {
		if (mIsBeingDragged) {
			mIsBeingDragged = false;

			if (mState == State.RELEASE_TO_REFRESH
					&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
				setState(State.REFRESHING, true);
				return true;
			}

			// If we're already refreshing, just scroll back to the top
			if (isRefreshing()) {
				smoothScrollTo(0);
				return true;
			}

			// If we haven't returned by here, then we're not in a state
			// to pull, so just reset
			setState(State.RESET);

			return true;
		}
		break;
	}
	}

	return false;
}
 
Example 15
Source File: PullToRefreshBase.java    From Social with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 16
Source File: ViewPager.java    From letv with Apache License 2.0 4 votes vote down vote up
public boolean onTouchEvent(MotionEvent ev) {
    if (this.mFakeDragging) {
        return true;
    }
    if (ev.getAction() == 0 && ev.getEdgeFlags() != 0) {
        return false;
    }
    if (this.mAdapter == null || this.mAdapter.getCount() == 0) {
        return false;
    }
    if (this.mVelocityTracker == null) {
        this.mVelocityTracker = VelocityTracker.obtain();
    }
    this.mVelocityTracker.addMovement(ev);
    boolean needsInvalidate = false;
    float x;
    switch (ev.getAction() & 255) {
        case 0:
            this.mScroller.abortAnimation();
            this.mPopulatePending = false;
            populate();
            x = ev.getX();
            this.mInitialMotionX = x;
            this.mLastMotionX = x;
            x = ev.getY();
            this.mInitialMotionY = x;
            this.mLastMotionY = x;
            this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            break;
        case 1:
            if (this.mIsBeingDragged) {
                VelocityTracker velocityTracker = this.mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000, (float) this.mMaximumVelocity);
                int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, this.mActivePointerId);
                this.mPopulatePending = true;
                int width = getClientWidth();
                int scrollX = getScrollX();
                ItemInfo ii = infoForCurrentScrollPosition();
                setCurrentItemInternal(determineTargetPage(ii.position, ((((float) scrollX) / ((float) width)) - ii.offset) / ii.widthFactor, initialVelocity, (int) (MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId)) - this.mInitialMotionX)), true, true, initialVelocity);
                needsInvalidate = resetTouch();
                break;
            }
            break;
        case 2:
            if (!this.mIsBeingDragged) {
                int pointerIndex = MotionEventCompat.findPointerIndex(ev, this.mActivePointerId);
                if (pointerIndex == -1) {
                    needsInvalidate = resetTouch();
                    break;
                }
                float x2 = MotionEventCompat.getX(ev, pointerIndex);
                float xDiff = Math.abs(x2 - this.mLastMotionX);
                float y = MotionEventCompat.getY(ev, pointerIndex);
                float yDiff = Math.abs(y - this.mLastMotionY);
                if (xDiff > ((float) this.mTouchSlop) && xDiff > yDiff) {
                    this.mIsBeingDragged = true;
                    requestParentDisallowInterceptTouchEvent(true);
                    if (x2 - this.mInitialMotionX > 0.0f) {
                        x = this.mInitialMotionX + ((float) this.mTouchSlop);
                    } else {
                        x = this.mInitialMotionX - ((float) this.mTouchSlop);
                    }
                    this.mLastMotionX = x;
                    this.mLastMotionY = y;
                    setScrollState(1);
                    setScrollingCacheEnabled(true);
                    ViewParent parent = getParent();
                    if (parent != null) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
            }
            if (this.mIsBeingDragged) {
                needsInvalidate = false | performDrag(MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId)));
                break;
            }
            break;
        case 3:
            if (this.mIsBeingDragged) {
                scrollToItem(this.mCurItem, true, 0, false);
                needsInvalidate = resetTouch();
                break;
            }
            break;
        case 5:
            int index = MotionEventCompat.getActionIndex(ev);
            this.mLastMotionX = MotionEventCompat.getX(ev, index);
            this.mActivePointerId = MotionEventCompat.getPointerId(ev, index);
            break;
        case 6:
            onSecondaryPointerUp(ev);
            this.mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId));
            break;
    }
    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(this);
    }
    return true;
}
 
Example 17
Source File: PullToRefreshBase.java    From Favorite-Android-Client with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 18
Source File: PullToRefreshBase.java    From letv with Apache License 2.0 4 votes vote down vote up
public final boolean onTouchEvent(MotionEvent event) {
    if (!isPullToRefreshEnabled()) {
        return false;
    }
    if (!this.mScrollingWhileRefreshingEnabled && isRefreshing()) {
        return true;
    }
    if (event.getAction() == 0 && event.getEdgeFlags() != 0) {
        return false;
    }
    switch (event.getAction()) {
        case 0:
            if (!isReadyForPull()) {
                return false;
            }
            float y = event.getY();
            this.mInitialMotionY = y;
            this.mLastMotionY = y;
            y = event.getX();
            this.mInitialMotionX = y;
            this.mLastMotionX = y;
            return true;
        case 1:
        case 3:
            if (!this.mIsBeingDragged) {
                return false;
            }
            this.mIsBeingDragged = false;
            if (this.mState == State.RELEASE_TO_REFRESH && (this.mOnRefreshListener != null || this.mOnRefreshListener2 != null)) {
                setState(State.REFRESHING, true);
                return true;
            } else if (isRefreshing()) {
                smoothScrollTo(0);
                return true;
            } else {
                setState(State.RESET, new boolean[0]);
                return true;
            }
        case 2:
            if (!this.mIsBeingDragged) {
                return false;
            }
            this.mLastMotionY = event.getY();
            this.mLastMotionX = event.getX();
            pullEvent();
            return true;
        default:
            return false;
    }
}
 
Example 19
Source File: PullToRefreshBase.java    From RefreashTabView with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

	if (!isPullToRefreshEnabled()) {
		return false;
	}

	// If we're refreshing, and the flag is set. Eat the event
	if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
		return true;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
		return false;
	}

	switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			if (mIsBeingDragged) {
				mLastMotionY = event.getY();
				mLastMotionX = event.getX();
				pullEvent();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_DOWN: {
			if (isReadyForPull()) {
				mLastMotionY = mInitialMotionY = event.getY();
				mLastMotionX = mInitialMotionX = event.getX();
				return true;
			}
			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			if (mIsBeingDragged) {
				mIsBeingDragged = false;

				if (mState == State.RELEASE_TO_REFRESH
						&& (null != mOnRefreshListener || null != mOnRefreshListener2)) {
					setState(State.REFRESHING, true);
					return true;
				}

				// If we're already refreshing, just scroll back to the top
				if (isRefreshing()) {
					smoothScrollTo(0);
					return true;
				}

				// If we haven't returned by here, then we're not in a state
				// to pull, so just reset
				setState(State.RESET);

				return true;
			}
			break;
		}
	}

	return false;
}
 
Example 20
Source File: PullToRefreshBase.java    From Roid-Library with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouchEvent(MotionEvent event) {

    if (!isPullToRefreshEnabled()) {
        return false;
    }

    // If we're refreshing, and the flag is set. Eat the event
    if (!mScrollingWhileRefreshingEnabled && isRefreshing()) {
        return true;
    }

    if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE: {
            if (mIsBeingDragged) {
                mLastMotionY = event.getY();
                mLastMotionX = event.getX();
                pullEvent();
                return true;
            }
            break;
        }

        case MotionEvent.ACTION_DOWN: {
            if (isReadyForPull()) {
                mLastMotionY = mInitialMotionY = event.getY();
                mLastMotionX = mInitialMotionX = event.getX();
                return true;
            }
            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            if (mIsBeingDragged) {
                mIsBeingDragged = false;

                if (mState == State.RELEASE_TO_REFRESH) {

                    if (null != mOnRefreshListener) {
                        setState(State.REFRESHING, true);
                        if (mCurrentMode == Mode.PULL_FROM_START) {
                            mOnRefreshListener.onPullDownToRefresh(this);
                        } else if (mCurrentMode == Mode.PULL_FROM_END) {
                            mOnRefreshListener.onPullUpToRefresh(this);
                        }
                        return true;
                    }
                }

                // If we're already refreshing, just scroll back to the
                // top
                if (isRefreshing()) {
                    smoothScrollTo(0);
                    return true;
                }

                // If we haven't returned by here, then we're not in a
                // state
                // to pull, so just reset
                setState(State.RESET);

                return true;
            }
            break;
        }
    }

    return false;
}