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
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
package com.videogo.widget;
 
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
 
import com.videogo.widget.pulltorefresh.LoadingLayout;
import com.videogo.widget.pulltorefresh.PullToRefreshBase.Orientation;
 
import ezviz.ezopensdk.R;
 
public class PullToRefreshHeader extends LoadingLayout {
 
    public enum Style {
        NORMAL, NO_TIME, MORE
    }
 
    private ImageView mArrowImageView;
    private ProgressBar mProgressBar;
    private TextView mHintTextView, mHeaderTimeView, mHintMoreView;
    private ViewGroup mHeaderTimelayout;
 
    private Animation mRotateUpAnim, mRotateDownAnim;
 
    private Style mStyle = Style.NORMAL;
 
    private final static int ROTATE_ANIM_DURATION = 180;
 
    public PullToRefreshHeader(Context context) {
        this(context, Style.NORMAL);
    }
 
    public PullToRefreshHeader(Context context, Style style) {
        super(context, true, Orientation.VERTICAL);
        setContentView(R.layout.pull_to_refresh_header);
 
        mArrowImageView = (ImageView) findViewById(R.id.header_arrow);
        mHintTextView = (TextView) findViewById(R.id.header_hint);
        mHeaderTimeView = (TextView) findViewById(R.id.header_time);
        mProgressBar = (ProgressBar) findViewById(R.id.header_progress);
        mHeaderTimelayout = (ViewGroup) findViewById(R.id.header_time_layout);
        mHintMoreView = (TextView) findViewById(R.id.header_hint_more);
        
        mRotateUpAnim = new RotateAnimation(0.0f, -180.0f, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION);
        mRotateUpAnim.setFillAfter(true);
        mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION);
        mRotateDownAnim.setFillAfter(true);
 
        if (style == Style.NO_TIME) {
            mHeaderTimelayout.setVisibility(View.GONE);
        } else if (style == Style.MORE) {
            mHeaderTimelayout.setVisibility(View.GONE);
        }
        mStyle = style;
    }
 
    @Override
    public void pullToRefresh() {
        if (mStyle == Style.MORE) {
            mHintTextView.setText(R.string.xlistview_header_hint_more);
        } else {
            mHintTextView.setText(R.string.xlistview_header_hint_normal);
        }
        if (mRotateUpAnim == mArrowImageView.getAnimation()) {
            mArrowImageView.startAnimation(mRotateDownAnim);
        }
    }
 
    @Override
    public void refreshing() {
        mHintTextView.setText(R.string.xlistview_header_hint_loading);
        mArrowImageView.clearAnimation();
        mArrowImageView.setVisibility(View.GONE);
        mProgressBar.setVisibility(View.VISIBLE);
    }
 
    @Override
    public void releaseToRefresh() {
        if (mStyle == Style.MORE) {
            mHintTextView.setText(R.string.xlistview_footer_hint_ready);
        } else {
            mHintTextView.setText(R.string.xlistview_header_hint_ready);
        }
        mArrowImageView.startAnimation(mRotateUpAnim);
    }
 
    @Override
    public void onPull(float scaleOfLayout) {
    }
 
    @Override
    public void reset() {
        if (mStyle == Style.MORE) {
            mHintTextView.setText(R.string.xlistview_header_hint_more);
        } else {
            mHintTextView.setText(R.string.xlistview_header_hint_normal);
        }
        mArrowImageView.clearAnimation();
        mArrowImageView.setVisibility(View.VISIBLE);
        mProgressBar.setVisibility(View.GONE);
        mHintMoreView.setVisibility(View.GONE);
    }
 
    @Override
    public void disableRefresh() {
        if (mStyle == Style.MORE) {
            mHintMoreView.setVisibility(View.VISIBLE);
            mHintTextView.setText(R.string.xlistview_footer_no_more);
        }
    }
 
    public void setLastRefreshTime(CharSequence text) {
        mHeaderTimeView.setText(text);
    }
}