Skip to content

Commit 495fbfa

Browse files
committed
add new Attributes and support for NestedScroll.
1. add TestActivity for testing settings. 2. support for nestedscroll with CoordinatorLayout. 3. keep header/footer. 4. fixed some bugs.
1 parent a277696 commit 495fbfa

File tree

13 files changed

+692
-287
lines changed

13 files changed

+692
-287
lines changed

TODO_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- 刷新时禁止加载更多,去加载更多底部空白没回去
1414
- 空白View下拉无效
1515
- 不停下拉导致head悬浮
16-
16+
- 测试autoLoadMore
1717

1818

1919
# v1.06开发计划

app/src/main/java/com/lcodecore/twinklingrefreshlayout/CoordinateActivity.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import android.os.Bundle;
44
import android.os.Handler;
5-
import android.support.v4.widget.SwipeRefreshLayout;
5+
import android.support.design.widget.AppBarLayout;
66
import android.support.v7.app.AppCompatActivity;
77
import android.support.v7.widget.RecyclerView;
88
import android.support.v7.widget.StaggeredGridLayoutManager;
@@ -74,6 +74,19 @@ public void run() {
7474
}
7575
});
7676

77+
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout);
78+
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
79+
@Override
80+
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
81+
if (verticalOffset >= 0) {
82+
refreshLayout.setEnableRefresh(true);
83+
refreshLayout.setEnableOverScroll(false);
84+
} else {
85+
refreshLayout.setEnableRefresh(false);
86+
refreshLayout.setEnableOverScroll(false);
87+
}
88+
}
89+
});
7790
}
7891

7992
void refreshCard() {

app/src/main/java/com/lcodecore/twinklingrefreshlayout/FoodActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void setupRecyclerView(RecyclerView rv) {
4545
BezierLayout headerView = new BezierLayout(this);
4646
refreshLayout.setHeaderView(headerView);
4747
// refreshLayout.setFloatRefresh(false);
48-
refreshLayout.setPureScrollModeOn(true);
48+
refreshLayout.setPureScrollModeOn();
4949
// refreshLayout.setEnableOverlayRefreshView(false);
5050
// refreshLayout.setAutoLoadMore(true);
5151

app/src/main/java/com/lcodecore/twinklingrefreshlayout/TestActivity.java

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.support.v7.app.AppCompatActivity;
66
import android.view.View;
77
import android.widget.AdapterView;
8+
import android.widget.Button;
89
import android.widget.GridView;
910

1011
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
@@ -18,14 +19,18 @@
1819
* Created by lcodecore on 2017/3/27.
1920
*/
2021

21-
public class TestActivity extends AppCompatActivity {
22+
public class TestActivity extends AppCompatActivity implements View.OnClickListener {
2223

2324
private ScienceAdapter adapter;
25+
private TwinklingRefreshLayout refreshLayout;
26+
27+
private TestButton toggle_enableLoadmore, toggle_pureScrollMode_on, toggle_overScrollTopShow, toggle_osFooterShow, toggle_enableOverScroll, toggle_enableKeepIView,
28+
toggle_showRefreshingWhenOverScroll, toggle_showLoadingWhenOverScroll, toggle_floatRefresh, toggle_autoLoadMore;
2429

2530
@Override
2631
protected void onCreate(Bundle savedInstanceState) {
2732
super.onCreate(savedInstanceState);
28-
setContentView(R.layout.activity_science);
33+
setContentView(R.layout.activity_test);
2934
setupGridView((GridView) findViewById(R.id.gridView));
3035

3136
findViewById(R.id.bt_back).setOnClickListener(new View.OnClickListener() {
@@ -34,10 +39,21 @@ public void onClick(View v) {
3439
finish();
3540
}
3641
});
42+
43+
toggle_enableLoadmore = new TestButton(R.id.toggle_enableLoadmore, "enableLoadmore", true);
44+
toggle_pureScrollMode_on = new TestButton(R.id.toggle_pureScrollMode_on, "pureScrollMode_on", false);
45+
toggle_overScrollTopShow = new TestButton(R.id.toggle_overScrollTopShow, "overScrollTopShow", true);
46+
toggle_osFooterShow = new TestButton(R.id.toggle_osFooterShow, "osFooterShow", true);
47+
toggle_enableOverScroll = new TestButton(R.id.toggle_enableOverScroll, "enableOverScroll", true);
48+
toggle_enableKeepIView = new TestButton(R.id.toggle_enableKeepIView, "enableKeepIView", true);
49+
toggle_showRefreshingWhenOverScroll = new TestButton(R.id.toggle_showRefreshingWhenOverScroll, "showRefreshingWhenOS", true);
50+
toggle_showLoadingWhenOverScroll = new TestButton(R.id.toggle_showLoadingWhenOverScroll, "showLoadingWhenOS", true);
51+
toggle_floatRefresh = new TestButton(R.id.toggle_floatRefresh, "floatRefresh", false);
52+
toggle_autoLoadMore = new TestButton(R.id.toggle_autoLoadMore, "autoLoadMore", false);
3753
}
3854

3955
private void setupGridView(GridView gridView) {
40-
final TwinklingRefreshLayout refreshLayout = (TwinklingRefreshLayout) findViewById(R.id.refresh);
56+
refreshLayout = (TwinklingRefreshLayout) findViewById(R.id.refresh);
4157
SinaRefreshView headerView = new SinaRefreshView(this);
4258
headerView.setArrowResource(R.drawable.arrow);
4359
headerView.setTextColor(0xff745D5C);
@@ -61,13 +77,13 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
6177
refreshLayout.setOnRefreshListener(new RefreshListenerAdapter() {
6278
@Override
6379
public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
64-
// new Handler().postDelayed(new Runnable() {
65-
// @Override
66-
// public void run() {
67-
// adapter.refreshCard();
68-
// refreshLayout.finishRefreshing();
69-
// }
70-
// }, 2000);
80+
new Handler().postDelayed(new Runnable() {
81+
@Override
82+
public void run() {
83+
adapter.refreshCard();
84+
refreshLayout.finishRefreshing();
85+
}
86+
}, 2000);
7187
}
7288

7389
@Override
@@ -82,4 +98,69 @@ public void run() {
8298
}
8399
});
84100
}
101+
102+
@Override
103+
public void onClick(View v) {
104+
switch (v.getId()) {
105+
case R.id.toggle_enableLoadmore:
106+
toggle_enableLoadmore.toggle();
107+
refreshLayout.setEnableLoadmore(toggle_enableLoadmore.flag);
108+
break;
109+
case R.id.toggle_pureScrollMode_on:
110+
toggle_pureScrollMode_on.toggle();
111+
refreshLayout.setPureScrollModeOn();
112+
break;
113+
case R.id.toggle_overScrollTopShow:
114+
toggle_overScrollTopShow.toggle();
115+
refreshLayout.setOverScrollTopShow(toggle_overScrollTopShow.flag);
116+
break;
117+
case R.id.toggle_osFooterShow:
118+
toggle_osFooterShow.toggle();
119+
refreshLayout.setOverScrollBottomShow(toggle_osFooterShow.flag);
120+
break;
121+
case R.id.toggle_enableOverScroll:
122+
toggle_enableOverScroll.toggle();
123+
refreshLayout.setEnableOverScroll(toggle_enableOverScroll.flag);
124+
break;
125+
case R.id.toggle_enableKeepIView:
126+
toggle_enableKeepIView.toggle();
127+
refreshLayout.setEnableKeepIView(toggle_enableKeepIView.flag);
128+
break;
129+
case R.id.toggle_showRefreshingWhenOverScroll:
130+
toggle_showRefreshingWhenOverScroll.toggle();
131+
refreshLayout.showRefreshingWhenOverScroll(toggle_showRefreshingWhenOverScroll.flag);
132+
break;
133+
case R.id.toggle_showLoadingWhenOverScroll:
134+
toggle_showLoadingWhenOverScroll.toggle();
135+
refreshLayout.showLoadingWhenOverScroll(toggle_showLoadingWhenOverScroll.flag);
136+
break;
137+
case R.id.toggle_floatRefresh:
138+
toggle_floatRefresh.toggle();
139+
refreshLayout.setFloatRefresh(toggle_floatRefresh.flag);
140+
break;
141+
case R.id.toggle_autoLoadMore:
142+
toggle_autoLoadMore.toggle();
143+
refreshLayout.setAutoLoadMore(toggle_autoLoadMore.flag);
144+
break;
145+
}
146+
}
147+
148+
class TestButton {
149+
private Button button;
150+
private boolean flag;
151+
private String text;
152+
153+
public TestButton(int id, String text, boolean flag) {
154+
button = (Button) findViewById(id);
155+
this.text = text;
156+
this.flag = flag;
157+
button.setOnClickListener(TestActivity.this);
158+
button.setText(text + "->" + flag);
159+
}
160+
161+
public void toggle() {
162+
flag = !flag;
163+
button.setText(text + "->" + flag);
164+
}
165+
}
85166
}

app/src/main/res/layout/activity_coordinate.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:id="@+id/refresh"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
android:addStatesFromChildren="true">
6+
android:layout_height="match_parent">
87

98
<android.support.design.widget.CoordinatorLayout
109
android:id="@+id/coord_container"
1110
android:layout_width="match_parent"
1211
android:layout_height="match_parent"
12+
android:addStatesFromChildren="true"
1313
android:fitsSystemWindows="true">
1414

1515
<android.support.design.widget.AppBarLayout
@@ -55,5 +55,4 @@
5555
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
5656

5757
</android.support.design.widget.CoordinatorLayout>
58-
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
59-
58+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/activity_music"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:background="#ff9800"
7+
android:orientation="vertical">
8+
9+
<RelativeLayout
10+
android:layout_width="match_parent"
11+
android:layout_height="56dp">
12+
13+
<ImageButton
14+
android:id="@+id/bt_back"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_centerVertical="true"
18+
android:layout_marginLeft="12dp"
19+
android:background="@null"
20+
android:src="@drawable/back_pink" />
21+
22+
<TextView
23+
android:id="@+id/tv_spacing"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_centerInParent="true"
27+
android:text="S C I E N C E"
28+
android:textColor="#FFEEEE"
29+
android:textSize="14sp"
30+
android:textStyle="bold" />
31+
32+
<ImageButton
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:layout_alignParentRight="true"
36+
android:layout_centerVertical="true"
37+
android:layout_marginRight="12dp"
38+
android:background="@null"
39+
android:src="@drawable/map" />
40+
</RelativeLayout>
41+
42+
<ScrollView
43+
android:layout_width="match_parent"
44+
android:layout_height="140dp">
45+
46+
<LinearLayout
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:orientation="vertical">
50+
51+
<LinearLayout
52+
android:layout_width="match_parent"
53+
android:layout_height="wrap_content"
54+
android:orientation="horizontal">
55+
56+
<Button
57+
android:id="@+id/toggle_enableLoadmore"
58+
android:layout_width="wrap_content"
59+
android:layout_height="wrap_content"
60+
android:text="enableLoadmore->true"
61+
android:textAllCaps="false" />
62+
63+
<Button
64+
android:id="@+id/toggle_pureScrollMode_on"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:text="pureScrollMode_on->false"
68+
android:textAllCaps="false" />
69+
</LinearLayout>
70+
71+
<LinearLayout
72+
android:layout_width="match_parent"
73+
android:layout_height="wrap_content"
74+
android:orientation="horizontal">
75+
76+
<Button
77+
android:id="@+id/toggle_overScrollTopShow"
78+
android:layout_width="wrap_content"
79+
android:layout_height="wrap_content"
80+
android:text="overScrollTopShow->true"
81+
android:textAllCaps="false" />
82+
83+
<Button
84+
android:id="@+id/toggle_osFooterShow"
85+
android:layout_width="wrap_content"
86+
android:layout_height="wrap_content"
87+
android:text="overScrollBottomShow->true"
88+
android:textAllCaps="false" />
89+
</LinearLayout>
90+
91+
<LinearLayout
92+
android:layout_width="match_parent"
93+
android:layout_height="wrap_content"
94+
android:orientation="horizontal">
95+
96+
<Button
97+
android:id="@+id/toggle_enableOverScroll"
98+
android:layout_width="wrap_content"
99+
android:layout_height="wrap_content"
100+
android:text="enableOverScroll->true"
101+
android:textAllCaps="false" />
102+
103+
<Button
104+
android:id="@+id/toggle_enableKeepIView"
105+
android:layout_width="wrap_content"
106+
android:layout_height="wrap_content"
107+
android:text="enableKeepIView->true"
108+
android:textAllCaps="false" />
109+
</LinearLayout>
110+
111+
<LinearLayout
112+
android:layout_width="match_parent"
113+
android:layout_height="wrap_content"
114+
android:orientation="horizontal">
115+
116+
<Button
117+
android:id="@+id/toggle_showRefreshingWhenOverScroll"
118+
android:layout_width="wrap_content"
119+
android:layout_height="wrap_content"
120+
android:text="showRefreshingWhenOS->true"
121+
android:textAllCaps="false" />
122+
123+
<Button
124+
android:id="@+id/toggle_showLoadingWhenOverScroll"
125+
android:layout_width="wrap_content"
126+
android:layout_height="wrap_content"
127+
android:text="showLoadingWhenOS->true"
128+
android:textAllCaps="false" />
129+
</LinearLayout>
130+
131+
<LinearLayout
132+
android:layout_width="match_parent"
133+
android:layout_height="wrap_content"
134+
android:orientation="horizontal">
135+
136+
<Button
137+
android:id="@+id/toggle_floatRefresh"
138+
android:layout_width="wrap_content"
139+
android:layout_height="wrap_content"
140+
android:text="floatRefresh->false"
141+
android:textAllCaps="false" />
142+
143+
<Button
144+
android:id="@+id/toggle_autoLoadMore"
145+
android:layout_width="wrap_content"
146+
android:layout_height="wrap_content"
147+
android:text="autoLoadMore->false"
148+
android:textAllCaps="false" />
149+
</LinearLayout>
150+
</LinearLayout>
151+
</ScrollView>
152+
153+
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
154+
android:id="@+id/refresh"
155+
android:layout_width="match_parent"
156+
android:layout_height="match_parent">
157+
158+
<GridView
159+
android:id="@+id/gridView"
160+
android:layout_width="match_parent"
161+
android:layout_height="wrap_content"
162+
android:columnWidth="164dp"
163+
android:numColumns="2"
164+
android:overScrollMode="never"
165+
android:stretchMode="spacingWidthUniform"
166+
android:verticalSpacing="12dp" />
167+
168+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
169+
170+
</LinearLayout>

0 commit comments

Comments
 (0)