Last active
August 28, 2015 04:57
-
-
Save KoMinkyu/7dcaa809b8ff77b63e5b to your computer and use it in GitHub Desktop.
TwoWayView PullToRefresh simple implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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