Skip to content

Commit 45bde0f

Browse files
committed
Add a demo for CoordinateLayout.
1 parent f2c6255 commit 45bde0f

File tree

8 files changed

+200
-19
lines changed

8 files changed

+200
-19
lines changed

TODO_list.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
2. 依赖太旧的问题->选择去除依赖还是更新依赖 done 以去除依赖
44
3. 自动刷新动画生硬 todo 问题待验证
55
4. 加载更多闪烁问题 done 做了优化
6-
5. layout_behavior支持问题
7-
6. 是否要支持ViewPager回弹问题
8-
7. 是否要支持所有的View
9-
8. 测试事件监听冲突问题
6+
5. layout_behavior支持问题 添加了Demo但未完成任何逻辑处理
7+
6. 是否要支持ViewPager回弹问题 TODO
8+
7. 是否要支持所有的View TODO
9+
8. 测试事件监听冲突问题 理论上修改后已经不存在这个问题
1010
9. 内存泄漏问题 -> 解决ValueAnimator潜在的内存泄漏问题;WebView内存泄漏问题;done
1111
10. 仿QQ视差效果
12-
11. 测试加载更多后不添加数据
12+
11. 测试加载更多后不添加数据 done
13+
12. 考虑是否要给Loadmore添加完成延时
1314

1415
## 新发现的问题
1516
1. beizierlayout主动调用刷新时会一片白
16-
2. BallPulseView引入了内存泄漏
17-
3. 新的方案,怎么让scroll更平滑;计算Footer降低与TargetView显示距离是否一致:结论,一致,问题在每次滚动的距离上
17+
2. BallPulseView引入了内存泄漏 done
18+
3. 新的方案,怎么让scroll更平滑;计算Footer降低与TargetView显示距离是否一致:结论,一致,问题在每次滚动的距离上 done
1819
4. requestLayout时提示 **improperly called by android.support.v7.widget.AppCompatTextView**
1920
5. WebView上拉不起作用
2021

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.lcodecore.twinklingrefreshlayout">
44

55
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
67

78
<application
89
android:name=".TkApplication"
@@ -25,6 +26,7 @@
2526
<activity android:name=".StoryActivity" />
2627
<activity android:name=".WebActivity"/>
2728
<activity android:name=".NestedLayoutActivity"/>
29+
<activity android:name=".CoordinateActivity"/>
2830
</application>
2931

3032
</manifest>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.lcodecore.twinklingrefreshlayout;
2+
3+
import android.os.Bundle;
4+
import android.os.Handler;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.support.v7.widget.RecyclerView;
7+
import android.support.v7.widget.StaggeredGridLayoutManager;
8+
import android.view.WindowManager;
9+
10+
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
11+
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
12+
import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout;
13+
import com.lcodecore.twinklingrefreshlayout.adapter.PhotoAdapter;
14+
import com.lcodecore.twinklingrefreshlayout.beans.Photo;
15+
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
19+
/**
20+
* Created by lcodecore on 2017/3/8.
21+
*/
22+
23+
public class CoordinateActivity extends AppCompatActivity {
24+
private PhotoAdapter photoAdapter;
25+
26+
@Override
27+
protected void onCreate(Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.activity_coordinate);
30+
31+
setupRecyclerView((RecyclerView) findViewById(R.id.recyclerview));
32+
33+
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
34+
}
35+
36+
private void setupRecyclerView(RecyclerView rv) {
37+
rv.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
38+
photoAdapter = new PhotoAdapter();
39+
rv.setAdapter(photoAdapter);
40+
41+
final TwinklingRefreshLayout refreshLayout = (TwinklingRefreshLayout) findViewById(R.id.refresh);
42+
ProgressLayout header = new ProgressLayout(this);
43+
refreshLayout.setHeaderView(header);
44+
refreshLayout.setFloatRefresh(true);
45+
refreshLayout.setEnableOverScroll(false);
46+
refreshLayout.setHeaderHeight(140);
47+
refreshLayout.setWaveHeight(240);
48+
refreshLayout.setTargetView(rv);
49+
50+
refreshCard();
51+
52+
refreshLayout.setOnRefreshListener(new RefreshListenerAdapter() {
53+
@Override
54+
public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
55+
new Handler().postDelayed(new Runnable() {
56+
@Override
57+
public void run() {
58+
refreshCard();
59+
refreshLayout.finishRefreshing();
60+
}
61+
}, 2000);
62+
}
63+
64+
@Override
65+
public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {
66+
new Handler().postDelayed(new Runnable() {
67+
@Override
68+
public void run() {
69+
loadMoreCard();
70+
refreshLayout.finishLoadmore();
71+
}
72+
}, 2000);
73+
}
74+
});
75+
76+
}
77+
78+
void refreshCard() {
79+
List<Photo> photos = new ArrayList<>();
80+
photos.add(new Photo("chest nut", R.drawable.photo1));
81+
photos.add(new Photo("fish", R.drawable.photo2));
82+
photos.add(new Photo("cat", R.drawable.photo10));
83+
photos.add(new Photo("guitar", R.drawable.photo3));
84+
photos.add(new Photo("common-hazel", R.drawable.photo4));
85+
photos.add(new Photo("cherry", R.drawable.photo5));
86+
photos.add(new Photo("flower details", R.drawable.photo6));
87+
photos.add(new Photo("tree", R.drawable.photo7));
88+
photos.add(new Photo("blue berries", R.drawable.photo8));
89+
photos.add(new Photo("snow man", R.drawable.photo9));
90+
photoAdapter.setDataList(photos);
91+
}
92+
93+
void loadMoreCard() {
94+
List<Photo> photos = new ArrayList<>();
95+
photos.add(new Photo("chest nut", R.drawable.photo1));
96+
photos.add(new Photo("fish", R.drawable.photo2));
97+
photos.add(new Photo("cat", R.drawable.photo10));
98+
photos.add(new Photo("guitar", R.drawable.photo3));
99+
photos.add(new Photo("common-hazel", R.drawable.photo4));
100+
photos.add(new Photo("cherry", R.drawable.photo5));
101+
photos.add(new Photo("flower details", R.drawable.photo6));
102+
photos.add(new Photo("tree", R.drawable.photo7));
103+
photos.add(new Photo("blue berries", R.drawable.photo8));
104+
photos.add(new Photo("snow man", R.drawable.photo9));
105+
photoAdapter.addItems(photos);
106+
}
107+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public void init() {
2121
findViewById(R.id.bt_photo).setOnClickListener(this);
2222
findViewById(R.id.bt_story).setOnClickListener(this);
2323
findViewById(R.id.bt_enjoy).setOnClickListener(this);
24+
findViewById(R.id.bt_coordinate).setOnClickListener(this);
2425
}
2526

2627
@Override
@@ -44,6 +45,9 @@ public void onClick(View v) {
4445
case R.id.bt_enjoy:
4546
startActivity(new Intent(MainActivity.this, WebActivity.class));
4647
break;
48+
case R.id.bt_coordinate:
49+
startActivity(new Intent(MainActivity.this,CoordinateActivity.class));
50+
break;
4751
}
4852
}
4953
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public void run() {
2929
}
3030
}, 4000);
3131
}
32+
33+
@Override
34+
public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {
35+
new Handler().postDelayed(new Runnable() {
36+
@Override
37+
public void run() {
38+
refreshLayout.finishLoadmore();
39+
}
40+
}, 4000);
41+
}
3242
});
3343
}
3444
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected void onCreate(Bundle savedInstanceState) {
3535
// header.setColorSchemeColors(0xff4674e7,0xff0ba62c);
3636

3737
mWebView = (WebView) findViewById(R.id.webView);
38+
mWebView.getSettings().setJavaScriptEnabled(true);
3839
mWebView.loadUrl("https://dribbble.com/shots");
3940

4041
refreshLayout.startRefresh();
@@ -51,18 +52,6 @@ public void run() {
5152
});
5253
}
5354

54-
@Override
55-
protected void onPause() {
56-
mWebView.onPause();
57-
super.onPause();
58-
}
59-
60-
@Override
61-
protected void onResume() {
62-
mWebView.onResume();
63-
super.onResume();
64-
}
65-
6655
@Override
6756
protected void onDestroy() {
6857
destroyWebView();
@@ -77,6 +66,7 @@ private void destroyWebView() {
7766
ViewParent parent = mWebView.getParent();
7867
if (parent != null) ((ViewGroup) parent).removeView(mWebView);
7968
mWebView.stopLoading();
69+
mWebView.getSettings().setJavaScriptEnabled(false);
8070
mWebView.clearHistory();
8171
mWebView.clearView();
8272
mWebView.removeAllViews();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/refresh"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:addStatesFromChildren="true"
8+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
9+
10+
<android.support.design.widget.CoordinatorLayout
11+
android:id="@+id/coord_container"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:fitsSystemWindows="true">
15+
16+
<android.support.design.widget.AppBarLayout
17+
android:id="@+id/appbar_layout"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:clipChildren="false">
21+
22+
<android.support.design.widget.CollapsingToolbarLayout
23+
android:id="@+id/collapsing_toolbar_layout"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:clipChildren="false"
27+
android:theme="@style/AppTheme.AppBarOverlay"
28+
app:contentScrim="?attr/colorPrimary"
29+
app:expandedTitleMarginStart="10dp"
30+
app:layout_scrollFlags="scroll|exitUntilCollapsed">
31+
32+
<ImageView
33+
android:layout_width="match_parent"
34+
android:layout_height="200dp"
35+
android:src="@drawable/photo9"
36+
android:scaleType="centerCrop"
37+
app:layout_collapseParallaxMultiplier="1"/>
38+
39+
<android.support.v7.widget.Toolbar
40+
android:id="@+id/toolbar"
41+
android:layout_width="match_parent"
42+
android:layout_height="?attr/actionBarSize"
43+
app:layout_collapseMode="pin"
44+
app:layout_scrollFlags="scroll|enterAlways">
45+
46+
</android.support.v7.widget.Toolbar>
47+
48+
</android.support.design.widget.CollapsingToolbarLayout>
49+
50+
</android.support.design.widget.AppBarLayout>
51+
52+
<android.support.v7.widget.RecyclerView
53+
android:id="@+id/recyclerview"
54+
android:layout_width="match_parent"
55+
android:layout_height="match_parent"
56+
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
57+
58+
</android.support.design.widget.CoordinatorLayout>
59+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
android:textAllCaps="false"
5757
android:text="Dribbble - WebView - FloatRefresh"/>
5858

59+
<Button
60+
android:id="@+id/bt_coordinate"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:layout_gravity="center"
64+
android:textAllCaps="false"
65+
android:text="Photo - CoordinateLayout-Beta - FloatRefresh"/>
66+
5967

6068
<android.support.design.widget.TabLayout
6169
android:id="@+id/tab_layout"

0 commit comments

Comments
 (0)