xuxiuxi
2017-07-14 bcefcf7249692e61574438d3857e737c2fd29ca7
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
package cn.com.basic.face.pulltorefresh;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
 
import com.bsk.zhangbo.demoforbsk.R;
 
public class LoadingLayout extends FrameLayout {
 
    static final int DEFAULT_ROTATION_ANIMATION_DURATION = 150;
 
    private final ImageView headerImage;
    private final ProgressBar headerProgress;
    private final TextView headerText;
 
    private String pullLabel;
    private String refreshingLabel;
    private String releaseLabel;
 
    private final Animation rotateAnimation, resetRotateAnimation;
 
    public LoadingLayout(Context context, final int mode, String releaseLabel,
                         String pullLabel, String refreshingLabel) {
        super(context);
        ViewGroup header = (ViewGroup) LayoutInflater.from(context).inflate(
                R.layout.pull_to_refresh_header, this);
        headerText = (TextView) header.findViewById(R.id.pull_to_refresh_text);
        headerImage = (ImageView) header
                .findViewById(R.id.pull_to_refresh_image);
        headerProgress = (ProgressBar) header
                .findViewById(R.id.pull_to_refresh_progress);
 
        final Interpolator interpolator = new LinearInterpolator();
        rotateAnimation = new RotateAnimation(0, -180,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        rotateAnimation.setInterpolator(interpolator);
        rotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
        rotateAnimation.setFillAfter(true);
 
        resetRotateAnimation = new RotateAnimation(-180, 0,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        resetRotateAnimation.setInterpolator(interpolator);
        resetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
        resetRotateAnimation.setFillAfter(true);
 
        this.releaseLabel = releaseLabel;
        this.pullLabel = pullLabel;
        this.refreshingLabel = refreshingLabel;
 
        switch (mode) {
            case PullToRefreshBase.MODE_PULL_UP_TO_REFRESH:
                headerImage.setImageResource(R.drawable.pulltorefresh_up_arrow);
                break;
            case PullToRefreshBase.MODE_PULL_DOWN_TO_REFRESH:
            default:
                headerImage.setImageResource(R.drawable.pulltorefresh_down_arrow);
                break;
        }
    }
 
    public void reset() {
        headerText.setText(pullLabel);
        headerImage.setVisibility(View.VISIBLE);
        headerProgress.setVisibility(View.GONE);
    }
 
    public void releaseToRefresh() {
        headerText.setText(releaseLabel);
        headerImage.clearAnimation();
        headerImage.startAnimation(rotateAnimation);
    }
 
    public void setPullLabel(String pullLabel) {
        this.pullLabel = pullLabel;
    }
 
    public void refreshing() {
        headerText.setText(refreshingLabel);
        headerImage.clearAnimation();
        headerImage.setVisibility(View.INVISIBLE);
        headerProgress.setVisibility(View.VISIBLE);
    }
 
    public void setRefreshingLabel(String refreshingLabel) {
        this.refreshingLabel = refreshingLabel;
    }
 
    public void setReleaseLabel(String releaseLabel) {
        this.releaseLabel = releaseLabel;
    }
 
    public void pullToRefresh() {
        headerText.setText(pullLabel);
        headerImage.clearAnimation();
        headerImage.startAnimation(resetRotateAnimation);
    }
 
    public void setTextColor(int color) {
        headerText.setTextColor(color);
    }
 
}