diff --git a/pulltorefresh/res/layout/pull_to_refresh_header.xml b/pulltorefresh/res/layout/pull_to_refresh_header.xml index 3f9256a..cfa45b6 100644 --- a/pulltorefresh/res/layout/pull_to_refresh_header.xml +++ b/pulltorefresh/res/layout/pull_to_refresh_header.xml @@ -17,8 +17,8 @@ @@ -47,7 +47,7 @@ /> = mRefreshViewHeight - || mRefreshView.getTop() >= 0) - && mRefreshState == RELEASE_TO_REFRESH) { + if ((mRefreshView.getBottom() >= mRefreshViewHeight || mRefreshView.getTop() >= 0) && mRefreshState == RELEASE_TO_REFRESH) { // Initiate the refresh mRefreshState = REFRESHING; prepareForRefresh(); onRefresh(); - } else if (mRefreshView.getBottom() < mRefreshViewHeight - || mRefreshView.getTop() <= 0) { + } else if (mRefreshView.getBottom() < mRefreshViewHeight || mRefreshView.getTop() <= 0) { // Abort refresh and scroll down below the refresh view resetHeader(); setSelection(1); @@ -201,24 +190,17 @@ private void applyHeaderPadding(MotionEvent ev) { int pointerCount = ev.getHistorySize(); for (int p = 0; p < pointerCount; p++) { - if (mRefreshState == RELEASE_TO_REFRESH) { - if (isVerticalFadingEdgeEnabled()) { - setVerticalScrollBarEnabled(false); - } + if (isVerticalFadingEdgeEnabled()) { + setVerticalScrollBarEnabled(false); + } - int historicalY = (int) ev.getHistoricalY(p); + int historicalY = (int) ev.getHistoricalY(p); - // Calculate the padding to apply, we divide by 1.7 to - // simulate a more resistant effect during pull. - int topPadding = (int) (((historicalY - mLastMotionY) - - mRefreshViewHeight) / 1.7); + // Calculate the padding to apply, we divide by 1.7 to + // simulate a more resistant effect during pull. + int topPadding = (int) (((historicalY - mLastMotionY) - mRefreshViewHeight) / 1.7); - mRefreshView.setPadding( - mRefreshView.getPaddingLeft(), - topPadding, - mRefreshView.getPaddingRight(), - mRefreshView.getPaddingBottom()); - } + mRefreshView.setPadding(mRefreshView.getPaddingLeft(), topPadding, mRefreshView.getPaddingRight(), mRefreshView.getPaddingBottom()); } } @@ -226,44 +208,37 @@ private void applyHeaderPadding(MotionEvent ev) { * Sets the header padding back to original size. */ private void resetHeaderPadding() { - mRefreshView.setPadding( - mRefreshView.getPaddingLeft(), - mRefreshOriginalTopPadding, - mRefreshView.getPaddingRight(), - mRefreshView.getPaddingBottom()); + mLastMotionY = 0; + mRefreshView.setPadding(mRefreshView.getPaddingLeft(), mRefreshOriginalTopPadding, mRefreshView.getPaddingRight(), mRefreshView.getPaddingBottom()); } /** * Resets the header to the original state. */ private void resetHeader() { - if (mRefreshState != TAP_TO_REFRESH) { - mRefreshState = TAP_TO_REFRESH; - - resetHeaderPadding(); - - // Set refresh view text to the pull label - mRefreshViewText.setText(R.string.pull_to_refresh_tap_label); - // Replace refresh drawable with arrow drawable - mRefreshViewImage.setImageResource(R.drawable.ic_pulltorefresh_arrow); - // Clear the full rotation animation - mRefreshViewImage.clearAnimation(); - // Hide progress bar and arrow. - mRefreshViewImage.setVisibility(View.GONE); - mRefreshViewProgress.setVisibility(View.GONE); - } + mRefreshState = PULL_TO_REFRESH; + + resetHeaderPadding(); + + // Set refresh view text to the pull label + mRefreshViewText.setText(R.string.pull_to_refresh_pull_label); + mRefreshViewText.setVisibility(View.GONE); + // Replace refresh drawable with arrow drawable + mRefreshViewImage.setImageResource(R.drawable.ic_pulltorefresh_arrow); + // Clear the full rotation animation + mRefreshViewImage.clearAnimation(); + // Hide progress bar and arrow. + mRefreshViewImage.setVisibility(View.GONE); + mRefreshViewProgress.setVisibility(View.GONE); } private void measureView(View child) { ViewGroup.LayoutParams p = child.getLayoutParams(); if (p == null) { - p = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.FILL_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT); + p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } - int childWidthSpec = ViewGroup.getChildMeasureSpec(0, - 0 + 0, p.width); + int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width); int lpHeight = p.height; int childHeightSpec; if (lpHeight > 0) { @@ -275,37 +250,29 @@ private void measureView(View child) { } @Override - public void onScroll(AbsListView view, int firstVisibleItem, - int visibleItemCount, int totalItemCount) { + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // When the refresh view is completely visible, change the text to say // "Release to refresh..." and flip the arrow drawable. - if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL - && mRefreshState != REFRESHING) { + if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING) { if (firstVisibleItem == 0) { mRefreshViewImage.setVisibility(View.VISIBLE); - if ((mRefreshView.getBottom() >= mRefreshViewHeight + 20 - || mRefreshView.getTop() >= 0) - && mRefreshState != RELEASE_TO_REFRESH) { + if ((mRefreshView.getBottom() >= mRefreshViewHeight + 20 || mRefreshView.getTop() >= 0) && mRefreshState != RELEASE_TO_REFRESH) { mRefreshViewText.setText(R.string.pull_to_refresh_release_label); + mRefreshViewText.setVisibility(View.VISIBLE); mRefreshViewImage.clearAnimation(); mRefreshViewImage.startAnimation(mFlipAnimation); mRefreshState = RELEASE_TO_REFRESH; - } else if (mRefreshView.getBottom() < mRefreshViewHeight + 20 - && mRefreshState != PULL_TO_REFRESH) { + } else if (mRefreshView.getBottom() < mRefreshViewHeight + 20 && mRefreshState != PULL_TO_REFRESH) { mRefreshViewText.setText(R.string.pull_to_refresh_pull_label); - if (mRefreshState != TAP_TO_REFRESH) { - mRefreshViewImage.clearAnimation(); - mRefreshViewImage.startAnimation(mReverseFlipAnimation); - } + mRefreshViewImage.clearAnimation(); + mRefreshViewImage.startAnimation(mReverseFlipAnimation); mRefreshState = PULL_TO_REFRESH; } } else { mRefreshViewImage.setVisibility(View.GONE); resetHeader(); } - } else if (mCurrentScrollState == SCROLL_STATE_FLING - && firstVisibleItem == 0 - && mRefreshState != REFRESHING) { + } else if (mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0 && mRefreshState != REFRESHING) { setSelection(1); mBounceHack = true; } else if (mBounceHack && mCurrentScrollState == SCROLL_STATE_FLING) { @@ -313,8 +280,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, } if (mOnScrollListener != null) { - mOnScrollListener.onScroll(view, firstVisibleItem, - visibleItemCount, totalItemCount); + mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } } @@ -355,7 +321,9 @@ public void onRefresh() { /** * Resets the list to a normal state after a refresh. - * @param lastUpdated Last updated at. + * + * @param lastUpdated + * Last updated at. */ public void onRefreshComplete(CharSequence lastUpdated) { setLastUpdated(lastUpdated); @@ -365,7 +333,7 @@ public void onRefreshComplete(CharSequence lastUpdated) { /** * Resets the list to a normal state after a refresh. */ - public void onRefreshComplete() { + public void onRefreshComplete() { Log.d(TAG, "onRefreshComplete"); resetHeader(); @@ -403,8 +371,7 @@ public interface OnRefreshListener { /** * Called when the list should be refreshed. *

- * A call to {@link PullToRefreshListView #onRefreshComplete()} is - * expected to indicate that the refresh has completed. + * A call to {@link PullToRefreshListView #onRefreshComplete()} is expected to indicate that the refresh has completed. */ public void onRefresh(); }