Skip to content

Commit

Permalink
New Layout mechanism is now finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Banes committed Dec 21, 2012
1 parent 3429998 commit 1ff49a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.handmark.pulltorefresh.library.internal.CallbackFrameLayout.OnSizeChangedListener;
import com.handmark.pulltorefresh.library.internal.FlipLoadingLayout;
import com.handmark.pulltorefresh.library.internal.LoadingLayout;
import com.handmark.pulltorefresh.library.internal.RotateLoadingLayout;
Expand Down Expand Up @@ -92,9 +91,6 @@ public abstract class PullToRefreshBase<T extends View> extends LinearLayout imp
private LoadingLayout mHeaderLayout;
private LoadingLayout mFooterLayout;

private int mHeaderDimension;
private int mFooterDimension;

private OnRefreshListener<T> mOnRefreshListener;
private OnRefreshListener2<T> mOnRefreshListener2;
private OnPullEventListener<T> mOnPullEventListener;
Expand Down Expand Up @@ -146,10 +142,10 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
@Override
public final boolean demo() {
if (mMode.showHeaderLoadingLayout() && isReadyForPullStart()) {
smoothScrollToAndBack(-mHeaderDimension * 2);
smoothScrollToAndBack(-getHeaderSize() * 2);
return true;
} else if (mMode.showFooterLoadingLayout() && isReadyForPullEnd()) {
smoothScrollToAndBack(mFooterDimension * 2);
smoothScrollToAndBack(getFooterSize() * 2);
return true;
}

Expand Down Expand Up @@ -587,11 +583,11 @@ void onRefreshing(final boolean doScroll) {
switch (mCurrentMode) {
case MANUAL_REFRESH_ONLY:
case PULL_FROM_END:
smoothScrollTo(mFooterDimension);
smoothScrollTo(getFooterSize());
break;
default:
case PULL_FROM_START:
smoothScrollTo(-mHeaderDimension);
smoothScrollTo(-getHeaderSize());
break;
}
} else {
Expand Down Expand Up @@ -724,22 +720,22 @@ protected final void disableLoadingLayoutVisibilityChanges() {
mLayoutVisibilityChangesEnabled = false;
}

protected final int getFooterHeight() {
return mFooterDimension;
}

protected final LoadingLayout getFooterLayout() {
return mFooterLayout;
}

protected final int getHeaderHeight() {
return mHeaderDimension;
protected final int getFooterSize() {
return mFooterLayout.getContentSize();
}

protected final LoadingLayout getHeaderLayout() {
return mHeaderLayout;
}

protected final int getHeaderSize() {
return mHeaderLayout.getContentSize();
}

protected int getPullToRefreshScrollDuration() {
return SMOOTH_SCROLL_DURATION_MS;
}
Expand Down Expand Up @@ -860,8 +856,6 @@ protected final void onSizeChanged(int w, int h, int oldw, int oldh) {
protected final void refreshLoadingViewsSize() {
final int maximumPullScroll = (int) (getMaximumPullScroll() * 1.2f);

mHeaderDimension = mFooterDimension = 0;

int pLeft = getPaddingLeft();
int pTop = getPaddingTop();
int pRight = getPaddingRight();
Expand All @@ -870,15 +864,13 @@ protected final void refreshLoadingViewsSize() {
switch (getPullToRefreshScrollDirection()) {
case HORIZONTAL:
if (mMode.showHeaderLoadingLayout()) {
mHeaderDimension = mHeaderLayout.getContentWidth();
mHeaderLayout.setWidth(maximumPullScroll);
pLeft = -maximumPullScroll;
} else {
pLeft = 0;
}

if (mMode.showFooterLoadingLayout()) {
mFooterDimension = mFooterLayout.getContentWidth();
mFooterLayout.setWidth(maximumPullScroll);
pRight = -maximumPullScroll;
} else {
Expand All @@ -888,15 +880,13 @@ protected final void refreshLoadingViewsSize() {

case VERTICAL:
if (mMode.showHeaderLoadingLayout()) {
mHeaderDimension = mHeaderLayout.getContentHeight();
mHeaderLayout.setHeight(maximumPullScroll);
pTop = -maximumPullScroll;
} else {
pTop = 0;
}

if (mMode.showFooterLoadingLayout()) {
mFooterDimension = mFooterLayout.getContentHeight();
mFooterLayout.setHeight(maximumPullScroll);
pBottom = -maximumPullScroll;
} else {
Expand Down Expand Up @@ -1075,11 +1065,6 @@ private void init(Context context, AttributeSet attrs) {
mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);

// LoadingLayout.OnSizeChangedListener listener = new
// OnLoadingLayoutSizeChangedListener();
// mHeaderLayout.setOnSizeChangedListener(listener);
// mFooterLayout.setOnSizeChangedListener(listener);

/**
* Styleables from XML
*/
Expand Down Expand Up @@ -1153,12 +1138,12 @@ private void pullEvent() {
switch (mCurrentMode) {
case PULL_FROM_END:
newScrollValue = Math.round(Math.max(initialMotionValue - lastMotionValue, 0) / FRICTION);
itemDimension = mFooterDimension;
itemDimension = getFooterSize();
break;
case PULL_FROM_START:
default:
newScrollValue = Math.round(Math.min(initialMotionValue - lastMotionValue, 0) / FRICTION);
itemDimension = mHeaderDimension;
itemDimension = getHeaderSize();
break;
}

Expand Down Expand Up @@ -1424,28 +1409,6 @@ public static interface OnLastItemVisibleListener {

}

final class OnLoadingLayoutSizeChangedListener implements OnSizeChangedListener {

@Override
public void onSizeChanged(View view, int newWidth, int newHeight) {
if (DEBUG) {
String viewString = view == mHeaderLayout ? "Header" : "Footer";
Log.d(LOG_TAG, "onSizeChanged. " + viewString + ": " + newWidth + " x " + newHeight);
}

/**
* We're currently in a layout pass, so we need to post so it gets
* called after the pass has finished.
*/
post(new Runnable() {
@Override
public void run() {
refreshLoadingViewsSize();
}
});
}
}

/**
* Listener that allows you to be notified when the user has started or
* finished a touch event. Useful when you want to append extra UI events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ void onRefreshing(final boolean doScroll) {
listViewLoadingView = mFooterLoadingView;
oppositeListViewLoadingView = mHeaderLoadingView;
selection = mRefreshableView.getCount() - 1;
scrollToY = getScrollY() - getFooterHeight();
scrollToY = getScrollY() - getFooterSize();
break;
case PULL_FROM_START:
default:
origLoadingView = getHeaderLayout();
listViewLoadingView = mHeaderLoadingView;
oppositeListViewLoadingView = mFooterLoadingView;
selection = 0;
scrollToY = getScrollY() + getHeaderHeight();
scrollToY = getScrollY() + getHeaderSize();
break;
}

Expand Down Expand Up @@ -152,14 +152,14 @@ void onReset() {
originalLoadingLayout = getFooterLayout();
listViewLoadingLayout = mFooterLoadingView;
selection = mRefreshableView.getCount() - 1;
scrollToHeight = getFooterHeight();
scrollToHeight = getFooterSize();
scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1;
break;
case PULL_FROM_START:
default:
originalLoadingLayout = getHeaderLayout();
listViewLoadingLayout = mHeaderLoadingView;
scrollToHeight = -getHeaderHeight();
scrollToHeight = -getHeaderSize();
selection = 0;
scrollLvToEdge = Math.abs(mRefreshableView.getFirstVisiblePosition() - selection) <= 1;
break;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.handmark.pulltorefresh.library.R;

@SuppressLint("ViewConstructor")
public abstract class LoadingLayout extends CallbackFrameLayout implements ILoadingLayout {
public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout {

static final String LOG_TAG = "PullToRefresh-LoadingLayout";

Expand Down Expand Up @@ -192,12 +192,14 @@ public final void setWidth(int width) {
requestLayout();
}

public final int getContentHeight() {
return mInnerLayout.getHeight();
}

public final int getContentWidth() {
return mInnerLayout.getWidth();
public final int getContentSize() {
switch (mScrollDirection) {
case HORIZONTAL:
return mInnerLayout.getWidth();
case VERTICAL:
default:
return mInnerLayout.getHeight();
}
}

public final void hideAllViews() {
Expand Down

0 comments on commit 1ff49a0

Please sign in to comment.