Skip to content

Commit

Permalink
add set the pull-down refresh resisitance factor interface
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklygaj committed Feb 14, 2017
1 parent e7d7b3a commit b695353
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ task clean(type: Delete) {
* You need to add library dependencies infomation to build.gradle in your module.

```
compile 'com.github.anzaizai:EasyRefreshLayout:1.1.3'
compile 'com.github.anzaizai:EasyRefreshLayout:1.1.4'
```
* last releases version is 1.1.3 can be use
* last releases version is 1.1.4 can be use

## step 3

Expand Down
26 changes: 23 additions & 3 deletions library/src/main/java/com/ajguan/library/EasyRefreshLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.os.Handler;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -40,6 +39,8 @@ public class EasyRefreshLayout extends ViewGroup {
private static long SHOW_COMPLETED_TIME = 500;
private static long SCROLL_TO_LOADING_DURATION = 500;
private static long SHOW_SCROLL_DOWN_DURATION = 300;
private static double PUll_RESISTANCE = 2;

private State state = State.RESET;

private boolean isEnablePullToRefresh = true;
Expand Down Expand Up @@ -139,7 +140,13 @@ public void setRefreshHeadView(View headerView) {

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//获取父控件高度
// int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
// System.out.println(">>>>>parentHeight = "+parentHeight);
// int expandParentHeight = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
// super.onMeasure(widthMeasureSpec, expandParentHeight);

super.onMeasure(widthMeasureSpec,heightMeasureSpec);
if (contentView == null) {
initContentView();
}
Expand Down Expand Up @@ -388,7 +395,7 @@ private void moveSpinner(float offsetY) {
float extraOS = nextOffsetTop - totalDragDistance;
float slingshotDist = totalDragDistance;
float tensionSlingshotPercent = Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
float tensionPercent = (float) (tensionSlingshotPercent - Math.pow(tensionSlingshotPercent / 2, 2));
float tensionPercent = (float) (tensionSlingshotPercent - Math.pow(tensionSlingshotPercent / PUll_RESISTANCE, 2));

if (offset > 0) { // 下拉的时候才添加阻力
offset = (int) (offset * (1f - tensionPercent));
Expand Down Expand Up @@ -667,6 +674,7 @@ private void initERVH() {
mRecyclerView = (RecyclerView) contentView;
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {


@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
Expand Down Expand Up @@ -987,4 +995,16 @@ public void setHideLoadViewAnimatorDuration(long showCompletedTime) {
SHOW_COMPLETED_TIME = showCompletedTime;
}


public static double getPUll_RESISTANCE() {
return PUll_RESISTANCE;
}

/**
* Set the pull-down refresh resistance factor
* @param PUll_RESISTANCE resistance factor
*/
public static void setPUll_RESISTANCE(double PUll_RESISTANCE) {
EasyRefreshLayout.PUll_RESISTANCE = PUll_RESISTANCE;
}
}

0 comments on commit b695353

Please sign in to comment.