admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
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
package com.wpc.library.widget.TitleBar;
 
import android.view.View;
import android.widget.AbsListView;
 
 
public class DefaultContentHandler implements ContentHandler {
    public static boolean canChildScrollUp(View view) {
        if (android.os.Build.VERSION.SDK_INT < 14) {
            if (view instanceof AbsListView) {
                final AbsListView absListView = (AbsListView) view;
                return absListView.getChildCount() > 0
                        && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                        .getTop() < absListView.getPaddingTop());
            } else {
                return view.getScrollY() > 0;
            }
        } else {
            return view.canScrollVertically(-1);
        }
    }
 
    /**
     * Default implement for check can perform pull to refresh
     *
     * @param layout
     * @param content
     * @param header
     * @return
     */
    public static boolean checkContentCanBePulledDown(MaterialHeaderLayout layout, View content, View header) {
        if (content instanceof ContentHandler) {
            return ((ContentHandler) content).checkCanDoRefresh(layout, content, header);
        } else {
            return !canChildScrollUp(content);
        }
    }
 
    @Override
    public boolean checkCanDoRefresh(MaterialHeaderLayout layout, View content, View header) {
        return checkContentCanBePulledDown(layout, content, header);
    }
 
    @Override
    public void onChange(float ratio, float offsetY) {
 
    }
 
    @Override
    public void onOffsetCalculated(int totalOffset) {
 
    }
}