1
1
package com .heartblood .nucdemo ;
2
2
3
+ import android .os .Build ;
3
4
import android .os .Bundle ;
4
5
import android .support .design .widget .FloatingActionButton ;
5
6
import android .support .design .widget .Snackbar ;
9
10
import android .support .v7 .widget .Toolbar ;
10
11
import android .util .Log ;
11
12
import android .view .View ;
13
+ import android .view .animation .Animation ;
14
+
15
+ import com .facebook .drawee .backends .pipeline .Fresco ;
12
16
import com .heartblood .nucdemo .adapter .NewsListAdapter ;
13
17
import com .heartblood .nucdemo .common .ui .BaseActivity ;
18
+ import com .heartblood .nucdemo .common .ui .MountainScenceView ;
14
19
import com .loopj .android .http .AsyncHttpClient ;
15
20
import com .loopj .android .http .JsonHttpResponseHandler ;
21
+
16
22
import org .json .JSONArray ;
17
23
import org .json .JSONObject ;
18
24
19
25
import cz .msebera .android .httpclient .Header ;
26
+ import in .srain .cube .views .ptr .PtrFrameLayout ;
27
+ import in .srain .cube .views .ptr .PtrHandler ;
28
+ import in .srain .cube .views .ptr .header .StoreHouseHeader ;
20
29
21
30
public class NewsActivity extends BaseActivity {
22
31
23
32
private RecyclerView mRecyclerView ;
24
33
private NewsListAdapter mNewsListAdapter ;
25
34
private JSONArray mJsonData ;
35
+ private PtrFrameLayout mPtrFrameLayout ;
36
+ private MountainScenceView mMountainScenceView ;
26
37
@ Override
27
38
protected void onCreate (Bundle savedInstanceState ) {
28
39
super .onCreate (savedInstanceState );
40
+ Fresco .initialize (this );
29
41
setContentView (R .layout .activity_news );
30
42
Toolbar toolbar = (Toolbar ) findViewById (R .id .toolbar );
31
43
setSupportActionBar (toolbar );
32
-
44
+ mMountainScenceView = ( MountainScenceView ) findViewById ( R . id . mountain_scence_view );
33
45
mRecyclerView = (RecyclerView ) findViewById (R .id .news_list );
34
46
mRecyclerView .setLayoutManager (new LinearLayoutManager (this ));
35
47
getNewsJson ("http://119.29.58.43/api/getSfBlog/getPage=1" , this );
48
+ mPtrFrameLayout = (PtrFrameLayout ) findViewById (R .id .news_card_ptr_frame );
49
+ mPtrFrameLayout .setPtrHandler (new PtrHandler () {
50
+ public int getScrollHeight () {
51
+ View c = mRecyclerView .getChildAt (0 );
52
+ if (c == null ) {
53
+ return 0 ;
54
+ }
55
+ int top = c .getTop ();
56
+ return top ;
57
+ }
58
+
59
+ @ Override
60
+ public boolean checkCanDoRefresh (PtrFrameLayout frame , View content , View header ) {
61
+
62
+ mMountainScenceView .updateFactor (content .getTop ());
63
+ if (getScrollHeight () >= 0 )
64
+ return true ;
65
+ return false ;
66
+ }
67
+
68
+ @ Override
69
+ public void onRefreshBegin (PtrFrameLayout frame ) {
70
+ frame .postDelayed (new Runnable () {
71
+ @ Override
72
+ public void run () {
73
+ mPtrFrameLayout .refreshComplete ();
74
+ }
75
+ }, 1800 );
76
+ }
77
+ });
36
78
FloatingActionButton fab = (FloatingActionButton ) findViewById (R .id .fab );
37
79
fab .setOnClickListener (new View .OnClickListener () {
38
80
@ Override
@@ -52,12 +94,14 @@ public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
52
94
mJsonData = response ;
53
95
mRecyclerView .setAdapter (mNewsListAdapter = new NewsListAdapter (newsActivity , mJsonData ));
54
96
}
97
+
55
98
@ Override
56
99
public void onFailure (int statusCode , Header [] headers , Throwable throwable , JSONObject errorResponse ) {
57
100
// TODO: 16/5/9 获取json失败
58
101
super .onFailure (statusCode , headers , throwable , errorResponse );
59
- Log .e ("测试" ,"报错报错啦" );
102
+ Log .e ("测试" , "报错报错啦" );
60
103
}
61
104
});
62
105
}
106
+
63
107
}
0 commit comments