Code example for View

Methods: getVisibility, setVisibility, startAnimation

0
 
				if (yDiff > mTouchSlop) {
					mIsBeingDragged = true;
					onPullStarted(y);
				} else if (yDiff < -mTouchSlop) {
					resetTouch(); 
				} 
			} 
			break; 
		} 
 
		case MotionEvent.ACTION_DOWN: {
			// If we're already refreshing, ignore 
			if (canRefresh(true, params.onRefreshListener)
					&& params.viewDelegate.isScrolledToTop(view)) {
				mInitialMotionY = (int) event.getY();
			} 
			break; 
		} 
 
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			resetTouch(); 
			break; 
		} 
		} 
 
		return mIsBeingDragged;
	} 
 
	final boolean onTouchEvent(View view, MotionEvent event) {
		if (DEBUG) {
			Log.d(LOG_TAG, "onTouchEvent: " + event.toString());
		} 
 
		// If we're not enabled or currently refreshing don't handle any touch 
		// events 
		if (!isEnabled()) { 
			return false; 
		} 
 
		final ViewParams params = mRefreshableViews.get(view);
		if (params == null) {
			return false; 
		} 
 
		switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE: {
			// If we're already refreshing ignore it 
			if (isRefreshing()) { 
				return false; 
			} 
 
			final int y = (int) event.getY();
 
			if (mIsBeingDragged && y != mLastMotionY) {
				final int yDx = y - mLastMotionY;
 
				/** 
				 * Check to see if the user is scrolling the right direction 
				 * (down). We allow a small scroll up which is the check against 
				 * negative touch slop. 
				 */ 
				if (yDx >= -mTouchSlop) {
					onPull(view, y);
					// Only record the y motion if the user has scrolled down. 
					if (yDx > 0) {
						mLastMotionY = y;
					} 
				} else { 
					onPullEnded(); 
					resetTouch(); 
				} 
			} 
			break; 
		} 
 
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			checkScrollForRefresh(view);
			if (mIsBeingDragged) {
				onPullEnded(); 
			} 
			resetTouch(); 
			break; 
		} 
		} 
 
		return true; 
	} 
 
	void resetTouch() { 
		mIsBeingDragged = false;
		mIsHandlingTouchEvent = false;
		mInitialMotionY = mLastMotionY = mPullBeginY = -1;
	} 
 
	void onPullStarted(int y) {
		if (DEBUG) {
			Log.d(LOG_TAG, "onPullStarted");
		} 
		showHeaderView(); 
		mPullBeginY = y;
	} 
 
	void onPull(View view, int y) {
		if (DEBUG) {
			Log.d(LOG_TAG, "onPull");
		} 
 
		final float pxScrollForRefresh = getScrollNeededForRefresh(view);
		final int scrollLength = y - mPullBeginY;
 
		if (scrollLength < pxScrollForRefresh) {
			mHeaderTransformer.onPulled(scrollLength / pxScrollForRefresh);
		} else { 
			if (mRefreshOnUp) {
				mHeaderTransformer.onReleaseToRefresh();