Skip to content

Commit 1ff49a0

Browse files
author
Chris Banes
committed
New Layout mechanism is now finished
1 parent 3429998 commit 1ff49a0

4 files changed

Lines changed: 25 additions & 97 deletions

File tree

library/src/com/handmark/pulltorefresh/library/PullToRefreshBase.java

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import android.widget.FrameLayout;
3535
import android.widget.LinearLayout;
3636

37-
import com.handmark.pulltorefresh.library.internal.CallbackFrameLayout.OnSizeChangedListener;
3837
import com.handmark.pulltorefresh.library.internal.FlipLoadingLayout;
3938
import com.handmark.pulltorefresh.library.internal.LoadingLayout;
4039
import com.handmark.pulltorefresh.library.internal.RotateLoadingLayout;
@@ -92,9 +91,6 @@ public abstract class PullToRefreshBase<T extends View> extends LinearLayout imp
9291
private LoadingLayout mHeaderLayout;
9392
private LoadingLayout mFooterLayout;
9493

95-
private int mHeaderDimension;
96-
private int mFooterDimension;
97-
9894
private OnRefreshListener<T> mOnRefreshListener;
9995
private OnRefreshListener2<T> mOnRefreshListener2;
10096
private OnPullEventListener<T> mOnPullEventListener;
@@ -146,10 +142,10 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
146142
@Override
147143
public final boolean demo() {
148144
if (mMode.showHeaderLoadingLayout() && isReadyForPullStart()) {
149-
smoothScrollToAndBack(-mHeaderDimension * 2);
145+
smoothScrollToAndBack(-getHeaderSize() * 2);
150146
return true;
151147
} else if (mMode.showFooterLoadingLayout() && isReadyForPullEnd()) {
152-
smoothScrollToAndBack(mFooterDimension * 2);
148+
smoothScrollToAndBack(getFooterSize() * 2);
153149
return true;
154150
}
155151

@@ -587,11 +583,11 @@ void onRefreshing(final boolean doScroll) {
587583
switch (mCurrentMode) {
588584
case MANUAL_REFRESH_ONLY:
589585
case PULL_FROM_END:
590-
smoothScrollTo(mFooterDimension);
586+
smoothScrollTo(getFooterSize());
591587
break;
592588
default:
593589
case PULL_FROM_START:
594-
smoothScrollTo(-mHeaderDimension);
590+
smoothScrollTo(-getHeaderSize());
595591
break;
596592
}
597593
} else {
@@ -724,22 +720,22 @@ protected final void disableLoadingLayoutVisibilityChanges() {
724720
mLayoutVisibilityChangesEnabled = false;
725721
}
726722

727-
protected final int getFooterHeight() {
728-
return mFooterDimension;
729-
}
730-
731723
protected final LoadingLayout getFooterLayout() {
732724
return mFooterLayout;
733725
}
734726

735-
protected final int getHeaderHeight() {
736-
return mHeaderDimension;
727+
protected final int getFooterSize() {
728+
return mFooterLayout.getContentSize();
737729
}
738730

739731
protected final LoadingLayout getHeaderLayout() {
740732
return mHeaderLayout;
741733
}
742734

735+
protected final int getHeaderSize() {
736+
return mHeaderLayout.getContentSize();
737+
}
738+
743739
protected int getPullToRefreshScrollDuration() {
744740
return SMOOTH_SCROLL_DURATION_MS;
745741
}
@@ -860,8 +856,6 @@ protected final void onSizeChanged(int w, int h, int oldw, int oldh) {
860856
protected final void refreshLoadingViewsSize() {
861857
final int maximumPullScroll = (int) (getMaximumPullScroll() * 1.2f);
862858

863-
mHeaderDimension = mFooterDimension = 0;
864-
865859
int pLeft = getPaddingLeft();
866860
int pTop = getPaddingTop();
867861
int pRight = getPaddingRight();
@@ -870,15 +864,13 @@ protected final void refreshLoadingViewsSize() {
870864
switch (getPullToRefreshScrollDirection()) {
871865
case HORIZONTAL:
872866
if (mMode.showHeaderLoadingLayout()) {
873-
mHeaderDimension = mHeaderLayout.getContentWidth();
874867
mHeaderLayout.setWidth(maximumPullScroll);
875868
pLeft = -maximumPullScroll;
876869
} else {
877870
pLeft = 0;
878871
}
879872

880873
if (mMode.showFooterLoadingLayout()) {
881-
mFooterDimension = mFooterLayout.getContentWidth();
882874
mFooterLayout.setWidth(maximumPullScroll);
883875
pRight = -maximumPullScroll;
884876
} else {
@@ -888,15 +880,13 @@ protected final void refreshLoadingViewsSize() {
888880

889881
case VERTICAL:
890882
if (mMode.showHeaderLoadingLayout()) {
891-
mHeaderDimension = mHeaderLayout.getContentHeight();
892883
mHeaderLayout.setHeight(maximumPullScroll);
893884
pTop = -maximumPullScroll;
894885
} else {
895886
pTop = 0;
896887
}
897888

898889
if (mMode.showFooterLoadingLayout()) {
899-
mFooterDimension = mFooterLayout.getContentHeight();
900890
mFooterLayout.setHeight(maximumPullScroll);
901891
pBottom = -maximumPullScroll;
902892
} else {
@@ -1075,11 +1065,6 @@ private void init(Context context, AttributeSet attrs) {
10751065
mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
10761066
mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);
10771067

1078-
// LoadingLayout.OnSizeChangedListener listener = new
1079-
// OnLoadingLayoutSizeChangedListener();
1080-
// mHeaderLayout.setOnSizeChangedListener(listener);
1081-
// mFooterLayout.setOnSizeChangedListener(listener);
1082-
10831068
/**
10841069
* Styleables from XML
10851070
*/
@@ -1153,12 +1138,12 @@ private void pullEvent() {
11531138
switch (mCurrentMode) {
11541139
case PULL_FROM_END:
11551140
newScrollValue = Math.round(Math.max(initialMotionValue - lastMotionValue, 0) / FRICTION);
1156-
itemDimension = mFooterDimension;
1141+
itemDimension = getFooterSize();
11571142
break;
11581143
case PULL_FROM_START:
11591144
default:
11601145
newScrollValue = Math.round(Math.min(initialMotionValue - lastMotionValue, 0) / FRICTION);
1161-
itemDimension = mHeaderDimension;
1146+
itemDimension = getHeaderSize();
11621147
break;
11631148
}
11641149

@@ -1424,28 +1409,6 @@ public static interface OnLastItemVisibleListener {
14241409

14251410
}
14261411

1427-
final class OnLoadingLayoutSizeChangedListener implements OnSizeChangedListener {
1428-
1429-
@Override
1430-
public void onSizeChanged(View view, int newWidth, int newHeight) {
1431-
if (DEBUG) {
1432-
String viewString = view == mHeaderLayout ? "Header" : "Footer";
1433-
Log.d(LOG_TAG, "onSizeChanged. " + viewString + ": " + newWidth + " x " + newHeight);
1434-
}
1435-
1436-
/**
1437-
* We're currently in a layout pass, so we need to post so it gets
1438-
* called after the pass has finished.
1439-
*/
1440-
post(new Runnable() {
1441-
@Override
1442-
public void run() {
1443-
refreshLoadingViewsSize();
1444-
}
1445-
});
1446-
}
1447-
}
1448-
14491412
/**
14501413
* Listener that allows you to be notified when the user has started or
14511414
* finished a touch event. Useful when you want to append extra UI events

library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ void onRefreshing(final boolean doScroll) {
9292
listViewLoadingView = mFooterLoadingView;
9393
oppositeListViewLoadingView = mHeaderLoadingView;
9494
selection = mRefreshableView.getCount() - 1;
95-
scrollToY = getScrollY() - getFooterHeight();
95+
scrollToY = getScrollY() - getFooterSize();
9696
break;
9797
case PULL_FROM_START:
9898
default:
9999
origLoadingView = getHeaderLayout();
100100
listViewLoadingView = mHeaderLoadingView;
101101
oppositeListViewLoadingView = mFooterLoadingView;
102102
selection = 0;
103-
scrollToY = getScrollY() + getHeaderHeight();
103+
scrollToY = getScrollY() + getHeaderSize();
104104
break;
105105
}
106106

@@ -152,14 +152,14 @@ void onReset() {
152152
originalLoadingLayout = getFooterLayout();
153153
listViewLoadingLayout = mFooterLoadingView;
154154
selection = mRefreshableView.getCount() - 1;
155-
scrollToHeight = getFooterHeight();
155+
scrollToHeight = getFooterSize();
156156
scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1;
157157
break;
158158
case PULL_FROM_START:
159159
default:
160160
originalLoadingLayout = getHeaderLayout();
161161
listViewLoadingLayout = mHeaderLoadingView;
162-
scrollToHeight = -getHeaderHeight();
162+
scrollToHeight = -getHeaderSize();
163163
selection = 0;
164164
scrollLvToEdge = Math.abs(mRefreshableView.getFirstVisiblePosition() - selection) <= 1;
165165
break;

library/src/com/handmark/pulltorefresh/library/internal/CallbackFrameLayout.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

library/src/com/handmark/pulltorefresh/library/internal/LoadingLayout.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import com.handmark.pulltorefresh.library.R;
4242

4343
@SuppressLint("ViewConstructor")
44-
public abstract class LoadingLayout extends CallbackFrameLayout implements ILoadingLayout {
44+
public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout {
4545

4646
static final String LOG_TAG = "PullToRefresh-LoadingLayout";
4747

@@ -192,12 +192,14 @@ public final void setWidth(int width) {
192192
requestLayout();
193193
}
194194

195-
public final int getContentHeight() {
196-
return mInnerLayout.getHeight();
197-
}
198-
199-
public final int getContentWidth() {
200-
return mInnerLayout.getWidth();
195+
public final int getContentSize() {
196+
switch (mScrollDirection) {
197+
case HORIZONTAL:
198+
return mInnerLayout.getWidth();
199+
case VERTICAL:
200+
default:
201+
return mInnerLayout.getHeight();
202+
}
201203
}
202204

203205
public final void hideAllViews() {

0 commit comments

Comments
 (0)