xuxiuxi
2017-08-01 21e08324c323d0c5d1e7cedc36323c554857a239
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package cn.com.basic.face.pulltorefresh;
 
 
import android.content.Context;
import android.util.AttributeSet;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.widget.ListView;
 
public class PullToRefreshListView extends PullToRefreshAdapterViewBase<ListView> {
 
//    private LoadingLayout headerLoadingView;
//    private LoadingLayout footerLoadingView;
 
    class InternalListView extends ListView implements EmptyViewMethodAccessor {
 
        public InternalListView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
 
        @Override
        public void setEmptyView(View emptyView) {
            PullToRefreshListView.this.setEmptyView(emptyView);
        }
 
        @Override
        public void setEmptyViewInternal(View emptyView) {
            super.setEmptyView(emptyView);
        }
 
        public ContextMenuInfo getContextMenuInfo() {
            return super.getContextMenuInfo();
        }
    }
 
    public PullToRefreshListView(Context context) {
        super(context);
        this.setDisableScrollingWhileRefreshing(false);
    }
 
    public PullToRefreshListView(Context context, int mode) {
        super(context, mode);
        this.setDisableScrollingWhileRefreshing(false);
    }
 
    public PullToRefreshListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setDisableScrollingWhileRefreshing(false);
    }
 
    @Override
    public ContextMenuInfo getContextMenuInfo() {
        return ((InternalListView) getRefreshableView()).getContextMenuInfo();
    }
 
//    public void setReleaseLabel(String releaseLabel) {
//        super.setReleaseLabel(releaseLabel);
//        if (null != headerLoadingView) {
//            headerLoadingView.setReleaseLabel(releaseLabel);
//        }
//        if (null != footerLoadingView) {
//            footerLoadingView.setReleaseLabel(releaseLabel);
//        }
//    }
//
//    public void setPullLabel(String pullLabel) {
//        super.setPullLabel(pullLabel);
//
//        if (null != headerLoadingView) {
//            headerLoadingView.setPullLabel(pullLabel);
//        }
//        if (null != footerLoadingView) {
//            footerLoadingView.setPullLabel(pullLabel);
//        }
//    }
//
//    public void setRefreshingLabel(String refreshingLabel) {
//        super.setRefreshingLabel(refreshingLabel);
//
//        if (null != headerLoadingView) {
//            headerLoadingView.setRefreshingLabel(refreshingLabel);
//        }
//        if (null != footerLoadingView) {
//            footerLoadingView.setRefreshingLabel(refreshingLabel);
//        }
//    }
 
    @Override
    protected final ListView createRefreshableView(Context context, AttributeSet attrs) {
        ListView lv = new InternalListView(context, attrs);
//        final int mode = this.getMode();
//
//        // Loading View Strings
//        String pullLabel = context.getString(R.string.pull_to_refresh_pull_label);
//        String refreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
//        String releaseLabel = context.getString(R.string.pull_to_refresh_release_label);
 
        // Add Loading Views
//        if (mode == MODE_PULL_DOWN_TO_REFRESH || mode == MODE_BOTH) {
//            FrameLayout frame = new FrameLayout(context);
//            headerLoadingView = new LoadingLayout(context, MODE_PULL_DOWN_TO_REFRESH, releaseLabel, pullLabel,
//                    refreshingLabel);
//            frame.addView(headerLoadingView, FrameLayout.LayoutParams.FILL_PARENT,
//                    FrameLayout.LayoutParams.WRAP_CONTENT);
//            headerLoadingView.setVisibility(View.GONE);
//            lv.addHeaderView(frame);
//        }
//        if (mode == MODE_PULL_UP_TO_REFRESH || mode == MODE_BOTH) {
//            FrameLayout frame = new FrameLayout(context);
//            footerLoadingView = new LoadingLayout(context, MODE_PULL_UP_TO_REFRESH, releaseLabel, pullLabel,
//                    refreshingLabel);
//            frame.addView(footerLoadingView, FrameLayout.LayoutParams.FILL_PARENT,
//                    FrameLayout.LayoutParams.WRAP_CONTENT);
//            footerLoadingView.setVisibility(View.GONE);
//            lv.addFooterView(frame);
//        }
 
        // Set it to this so it can be used in ListActivity/ListFragment
        lv.setId(android.R.id.list);
        return lv;
    }
 
//    @Override
//    protected void setRefreshingInternal(boolean doScroll) {
//        super.setRefreshingInternal(false);
//
//        final LoadingLayout originalLoadingLayout, listViewLoadingLayout;
//        final int selection, scrollToY;
//
//        switch (getCurrentMode()) {
//            case MODE_PULL_UP_TO_REFRESH:
//                originalLoadingLayout = this.getFooterLayout();
//                listViewLoadingLayout = this.footerLoadingView;
//                selection = refreshableView.getCount() - 1;
//                scrollToY = getScrollY() - getHeaderHeight();
//                break;
//            case MODE_PULL_DOWN_TO_REFRESH:
//            default:
//                originalLoadingLayout = this.getHeaderLayout();
//                listViewLoadingLayout = this.headerLoadingView;
//                selection = 0;
//                scrollToY = getScrollY() + getHeaderHeight();
//                break;
//        }
//
//        if (doScroll) {
//            // We scroll slightly so that the ListView's header/footer is at the
//            // same Y position as our normal header/footer
//            this.setHeaderScroll(scrollToY);
//        }
//
//        // Hide our original Loading View
//        originalLoadingLayout.setVisibility(View.INVISIBLE);
//
//        // Show the ListView Loading View and set it to refresh
//        listViewLoadingLayout.setVisibility(View.VISIBLE);
//        listViewLoadingLayout.refreshing();
//
//        if (doScroll) {
//            // Make sure the ListView is scrolled to show the loading
//            // header/footer
//            refreshableView.setSelection(selection);
//
//            // Smooth scroll as normal
//            smoothScrollTo(0);
//        }
//    }
 
//    @Override
//    protected void resetHeader() {
//
//        LoadingLayout originalLoadingLayout;
//        LoadingLayout listViewLoadingLayout;
//
//        int scrollToHeight = getHeaderHeight();
//        final boolean doScroll;
//
//        switch (getCurrentMode()) {
//            case MODE_PULL_UP_TO_REFRESH:
//                originalLoadingLayout = this.getFooterLayout();
//                listViewLoadingLayout = footerLoadingView;
//                doScroll = this.isReadyForPullUp();
//                break;
//            case MODE_PULL_DOWN_TO_REFRESH:
//            default:
//                originalLoadingLayout = this.getHeaderLayout();
//                listViewLoadingLayout = headerLoadingView;
//                scrollToHeight *= -1;
//                doScroll = this.isReadyForPullDown();
//                break;
//        }
//
//        // Set our Original View to Visible
//        originalLoadingLayout.setVisibility(View.VISIBLE);
//
//        // Scroll so our View is at the same Y as the ListView header/footer,
//        // but only scroll if the ListView is at the top/bottom
//        if (doScroll) {
//            this.setHeaderScroll(scrollToHeight);
//        }
//
//        // Hide the ListView Header/Footer
//        listViewLoadingLayout.setVisibility(View.GONE);
//
//        super.resetHeader();
//    }
 
}