1
wxr
2023-04-23 2cd55265ccff3b0a267d7953b2dd9e5dca437aa6
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
package com.videogo.widget.pulltorefresh;
 
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
 
import com.videogo.widget.pulltorefresh.PullToRefreshBase.Orientation;
 
@SuppressLint("ViewConstructor")
public abstract class LoadingLayout extends FrameLayout {
 
    protected final boolean mHeaderOrFooter;
 
    protected final Orientation mScrollDirection;
 
    private View mContentView;
    private Runnable mPostRenderRunnable;
 
    public LoadingLayout(Context context, final boolean headerOrFooter, final Orientation scrollDirection) {
        super(context);
        mHeaderOrFooter = headerOrFooter;
        mScrollDirection = scrollDirection;
    }
 
    protected void setContentView(int layoutResID) {
        mContentView = LayoutInflater.from(getContext()).inflate(layoutResID, this, false);
        LayoutParams lp = (LayoutParams) mContentView.getLayoutParams();
        if (mHeaderOrFooter)
            lp.gravity = mScrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT;
        else
            lp.gravity = mScrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;
        addView(mContentView, lp);
    }
 
    public final void setHeight(int height) {
        ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams();
        lp.height = height;
        requestLayout();
    }
 
    public final void setWidth(int width) {
        ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams();
        lp.width = width;
        requestLayout();
    }
 
    public int getContentSize(Orientation orientation) {
        switch (orientation) {
            case HORIZONTAL:
                return mContentView.getWidth();
            case VERTICAL:
            default:
                return mContentView.getHeight();
        }
    }
 
    public abstract void pullToRefresh();
 
    public abstract void refreshing();
 
    public abstract void releaseToRefresh();
 
    public abstract void onPull(float scaleOfLayout);
 
    public abstract void reset();
 
    public abstract void disableRefresh();
 
    public final void showInvisibleViews() {
        if (View.INVISIBLE == mContentView.getVisibility()) {
            mContentView.setVisibility(View.VISIBLE);
        }
    }
 
    public final void hideAllViews() {
        if (View.VISIBLE == mContentView.getVisibility()) {
            mContentView.setVisibility(View.INVISIBLE);
        }
    }
 
    public void postRenderRunnable(Runnable r) {
        mPostRenderRunnable = r;
    }
 
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
 
        boolean result = mScrollDirection == Orientation.VERTICAL ? (bottom - top) > 0 : (right - left) > 0;
        if (result && mPostRenderRunnable != null) {
            mPostRenderRunnable.run();
            mPostRenderRunnable = null;
        }
    }
}