Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011, 2012 Chris Banes. Copyright 2013 Naver Business Platform Corp. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package com.handmark.pulltorefresh.library;
 
 
 
 
 
 
 	private boolean mListViewExtrasEnabled;
 
 	public PullToRefreshListView(Context context) {
 		super(context);
 	}
 
 	public PullToRefreshListView(Context contextAttributeSet attrs) {
 		super(contextattrs);
 	}
 
 	public PullToRefreshListView(Context contextMode mode) {
 		super(contextmode);
 	}
 
 	public PullToRefreshListView(Context contextMode modeClass<? extends LoadingLayoutloadingLayoutClazz) {
 		super(contextmodeloadingLayoutClazz);
 	}
 
 	}
 
 	protected void onRefreshing(final boolean doScroll) {
If we're not showing the Refreshing view, or the list is empty, the the header/footer views won't show so we use the normal method.
 
 		if (! || !getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty() || getCurrentMode() == .) {
 			super.onRefreshing(doScroll);
 			return;
 		}
 
 		super.onRefreshing(false);
 
 		final LoadingLayout origLoadingViewlistViewLoadingViewoppositeListViewLoadingView;
 		final int selectionscrollToY;
 
 		switch (getCurrentMode()) {
 			case :
 				origLoadingView = getFooterLayout();
 				listViewLoadingView = ;
 				oppositeListViewLoadingView = ;
 				selection = .getCount() - 1;
 				scrollToY = getScrollY() - getFooterSize();
 				break;
 			default:
 				origLoadingView = getHeaderLayout();
 				listViewLoadingView = ;
 				oppositeListViewLoadingView = ;
 				selection = 0;
 				scrollToY = getScrollY() + getHeaderSize();
 				break;
		}
		// Hide our original Loading View
		origLoadingView.reset();
		origLoadingView.hideAllViews();
		// Make sure the opposite end is hidden too
		oppositeListViewLoadingView.setVisibility(.);
		// Show the ListView Loading View and set it to refresh.
		listViewLoadingView.setVisibility(.);
		listViewLoadingView.refreshing();
		if (doScroll) {
			// We need to disable the automatic visibility changes for now
			// We scroll slightly so that the ListView's header/footer is at the
			// same Y position as our normal header/footer
			setHeaderScroll(scrollToY);
			// Make sure the ListView is scrolled to show the loading
			// header/footer
			// Smooth scroll as normal
		}
	}
	protected void onReset() {
If the extras are not enabled, just call up to super and return.
			super.onReset();
			return;
		}
		final LoadingLayout originalLoadingLayoutlistViewLoadingLayout;
		final int scrollToHeightselection;
		final boolean scrollLvToEdge;
		switch (getCurrentMode()) {
				originalLoadingLayout = getFooterLayout();
				listViewLoadingLayout = ;
				selection = .getCount() - 1;
				scrollToHeight = getFooterSize();
				scrollLvToEdge = Math.abs(.getLastVisiblePosition() - selection) <= 1;
				break;
			default:
				originalLoadingLayout = getHeaderLayout();
				listViewLoadingLayout = ;
				scrollToHeight = -getHeaderSize();
				selection = 0;
				scrollLvToEdge = Math.abs(.getFirstVisiblePosition() - selection) <= 1;
				break;
		}
		// If the ListView header loading layout is showing, then we need to
		// flip so that the original one is showing instead
		if (listViewLoadingLayout.getVisibility() == .) {
			// Set our Original View to Visible
			originalLoadingLayout.showInvisibleViews();
			// Hide the ListView Header/Footer
			listViewLoadingLayout.setVisibility(.);

Scroll so the View is at the same Y as the ListView header/footer, but only scroll if: we've pulled to refresh, it's positioned correctly
			if (scrollLvToEdge && getState() != .) {
				setHeaderScroll(scrollToHeight);
			}
		}
		// Finally, call up to super
		super.onReset();
	}
	protected LoadingLayoutProxy createLoadingLayoutProxy(final boolean includeStartfinal boolean includeEnd) {
		LoadingLayoutProxy proxy = super.createLoadingLayoutProxy(includeStartincludeEnd);
			final Mode mode = getMode();
			if (includeStart && mode.showHeaderLoadingLayout()) {
			}
			if (includeEnd && mode.showFooterLoadingLayout()) {
			}
		}
		return proxy;
	}
	protected ListView createListView(Context contextAttributeSet attrs) {
		final ListView lv;
			lv = new InternalListViewSDK9(contextattrs);
else {
			lv = new InternalListView(contextattrs);
		}
		return lv;
	}
	protected ListView createRefreshableView(Context contextAttributeSet attrs) {
		ListView lv = createListView(contextattrs);
		// Set it to this so it can be used in ListActivity/ListFragment
		return lv;
	}
	protected void handleStyledAttributes(TypedArray a) {
		if ( getMode() == .) {
		}
			// Create Loading Views ready for use later
			.addHeaderView(framenullfalse);
If the value for Scrolling While Refreshing hasn't been explicitly set via XML, enable Scrolling While Refreshing.
			}
		}
	}
	final class InternalListViewSDK9 extends InternalListView {
		public InternalListViewSDK9(Context contextAttributeSet attrs) {
			super(contextattrs);
		}
		protected boolean overScrollBy(int deltaXint deltaYint scrollXint scrollYint scrollRangeX,
				int scrollRangeYint maxOverScrollXint maxOverScrollYboolean isTouchEvent) {
			final boolean returnValue = super.overScrollBy(deltaXdeltaYscrollXscrollYscrollRangeX,
					scrollRangeYmaxOverScrollXmaxOverScrollYisTouchEvent);
			// Does all of the hard work...
			OverscrollHelper.overScrollBy(PullToRefreshListView.thisdeltaXscrollXdeltaYscrollYisTouchEvent);
			return returnValue;
		}
	}
	protected class InternalListView extends ListView implements EmptyViewMethodAccessor {
		private boolean mAddedLvFooter = false;
		public InternalListView(Context contextAttributeSet attrs) {
			super(contextattrs);
		}
		protected void dispatchDraw(Canvas canvas) {
This is a bit hacky, but Samsung's ListView has got a bug in it when using Header/Footer Views and the list is empty. This masks the issue so that it doesn't cause an FC. See Issue #66.
			try {
				super.dispatchDraw(canvas);
catch (IndexOutOfBoundsException e) {
			}
		}
		public boolean dispatchTouchEvent(MotionEvent ev) {
This is a bit hacky, but Samsung's ListView has got a bug in it when using Header/Footer Views and the list is empty. This masks the issue so that it doesn't cause an FC. See Issue #66.
			try {
				return super.dispatchTouchEvent(ev);
catch (IndexOutOfBoundsException e) {
				return false;
			}
		}
		public void setAdapter(ListAdapter adapter) {
			// Add the Footer View at the last possible moment
			if (null !=  && !) {
			}
			super.setAdapter(adapter);
		}
		public void setEmptyView(View emptyView) {
		}
		public void setEmptyViewInternal(View emptyView) {
			super.setEmptyView(emptyView);
		}
	}