Skip to content

Instantly share code, notes, and snippets.

@KoMinkyu
Last active August 28, 2015 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KoMinkyu/7dcaa809b8ff77b63e5b to your computer and use it in GitHub Desktop.
Save KoMinkyu/7dcaa809b8ff77b63e5b to your computer and use it in GitHub Desktop.
TwoWayView PullToRefresh simple implementation
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="gridview" />
<item type="id" name="webview" />
<item type="id" name="scrollview" />
<item type="id" name="twowayview" />
</resources>
package com.handmark.pulltorefresh.library;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import org.lucasr.twowayview.widget.TwoWayView;
public class SimplePullToRefreshTwoWayView extends PullToRefreshBase<TwoWayView> {
public SimplePullToRefreshTwoWayView(Context context) {
super(context);
}
public SimplePullToRefreshTwoWayView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SimplePullToRefreshTwoWayView(Context context, Mode mode) {
super(context, mode);
}
@Override
public Orientation getPullToRefreshScrollDirection() {
return Orientation.VERTICAL;
}
@Override
protected TwoWayView createRefreshableView(Context context, AttributeSet attrs) {
TwoWayView twoWayView;
twoWayView = new TwoWayView(context, attrs);
twoWayView.setId(R.id.twowayview);
return twoWayView;
}
@Override
protected boolean isReadyForPullEnd() {
if (mRefreshableView.getChildCount() <= 0) {
return true;
}
int firstVisiblePosition = mRefreshableView.getChildAdapterPosition(mRefreshableView.getChildAt(0));
return firstVisiblePosition == 0 && mRefreshableView.getChildAt(0).getTop() == mRefreshableView.getPaddingTop();
}
@Override
protected boolean isReadyForPullStart() {
int firstVisiblePosition = mRefreshableView.getFirstVisiblePosition();
if (firstVisiblePosition > 0) {
return false;
}
final View firstVisibleChildView = mRefreshableView.getChildAt(firstVisiblePosition);
if (firstVisibleChildView.getTop() < mRefreshableView.getTop()) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment