-
Notifications
You must be signed in to change notification settings - Fork 483
/
Copy pathMaterialHeaderView.java
executable file
·202 lines (171 loc) · 6.79 KB
/
MaterialHeaderView.java
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
package com.cjj;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.widget.FrameLayout;
public class MaterialHeaderView extends FrameLayout implements MaterialHeadListener {
private final static String Tag = MaterialHeaderView.class.getSimpleName();
private MaterialWaveView materialWaveView;
private CircleProgressBar circleProgressBar;
private int waveColor;
private int progressTextColor;
private int[] progress_colors;
private int progressStokeWidth;
private boolean isShowArrow, isShowProgressBg;
private int progressValue, progressValueMax;
private int textType;
private int progressBg;
private int progressSize;
private static float density;
public MaterialHeaderView(Context context) {
this(context, null);
}
public MaterialHeaderView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MaterialHeaderView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
protected void init(AttributeSet attrs, int defStyle) {
if (isInEditMode()) return;
setClipToPadding(false);
setWillNotDraw(false);
}
public int getWaveColor() {
return waveColor;
}
public void setWaveColor(int waveColor) {
this.waveColor = waveColor;
if (null != materialWaveView) {
materialWaveView.setColor(this.waveColor);
}
}
public void setProgressSize(int progressSize) {
this.progressSize = progressSize;
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) density * progressSize, (int) density * progressSize);
layoutParams.gravity = Gravity.CENTER;
if(circleProgressBar!=null)
circleProgressBar.setLayoutParams(layoutParams);
}
public void setProgressBg(int progressBg) {
this.progressBg = progressBg;
if(circleProgressBar!=null)
circleProgressBar.setProgressBackGroundColor(progressBg);
}
public void setIsProgressBg(boolean isShowProgressBg) {
this.isShowProgressBg = isShowProgressBg;
if(circleProgressBar!=null)
circleProgressBar.setCircleBackgroundEnabled(isShowProgressBg);
}
public void setProgressTextColor(int textColor) {
this.progressTextColor = textColor;
}
public void setProgressColors(int[] colors) {
this.progress_colors = colors;
if(circleProgressBar!=null)
circleProgressBar.setColorSchemeColors(progress_colors);
}
public void setTextType(int textType) {
this.textType = textType;
}
public void setProgressValue(int value) {
this.progressValue = value;
this.post(new Runnable() {
@Override
public void run() {
if (circleProgressBar != null) {
circleProgressBar.setProgress(progressValue);
}
}
});
}
public void setProgressValueMax(int value) {
this.progressValueMax = value;
}
public void setProgressStokeWidth(int w) {
this.progressStokeWidth = w;
if(circleProgressBar!=null)
circleProgressBar.setProgressStokeWidth(progressStokeWidth);
}
public void showProgressArrow(boolean isShowArrow) {
this.isShowArrow = isShowArrow;
if(circleProgressBar!=null)
circleProgressBar.setShowArrow(isShowArrow);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
density = getContext().getResources().getDisplayMetrics().density;
materialWaveView = new MaterialWaveView(getContext());
materialWaveView.setColor(waveColor);
addView(materialWaveView);
circleProgressBar = new CircleProgressBar(getContext());
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) density * progressSize, (int) density * progressSize);
layoutParams.gravity = Gravity.CENTER;
circleProgressBar.setLayoutParams(layoutParams);
circleProgressBar.setColorSchemeColors(progress_colors);
circleProgressBar.setProgressStokeWidth(progressStokeWidth);
circleProgressBar.setShowArrow(isShowArrow);
circleProgressBar.setShowProgressText(textType == 0);
circleProgressBar.setTextColor(progressTextColor);
circleProgressBar.setProgress(progressValue);
circleProgressBar.setMax(progressValueMax);
circleProgressBar.setCircleBackgroundEnabled(isShowProgressBg);
circleProgressBar.setProgressBackGroundColor(progressBg);
addView(circleProgressBar);
}
@Override
public void onComlete(MaterialRefreshLayout materialRefreshLayout) {
if (materialWaveView != null) {
materialWaveView.onComlete(materialRefreshLayout);
}
if (circleProgressBar != null) {
circleProgressBar.onComlete(materialRefreshLayout);
ViewCompat.setTranslationY(circleProgressBar, 0);
ViewCompat.setScaleX(circleProgressBar, 0);
ViewCompat.setScaleY(circleProgressBar, 0);
}
}
@Override
public void onBegin(MaterialRefreshLayout materialRefreshLayout) {
if (materialWaveView != null) {
materialWaveView.onBegin(materialRefreshLayout);
}
if (circleProgressBar != null) {
ViewCompat.setScaleX(circleProgressBar, 0.001f);
ViewCompat.setScaleY(circleProgressBar, 0.001f);
circleProgressBar.onBegin(materialRefreshLayout);
}
}
@Override
public void onPull(MaterialRefreshLayout materialRefreshLayout, float fraction) {
if (materialWaveView != null) {
materialWaveView.onPull(materialRefreshLayout, fraction);
}
if (circleProgressBar != null) {
circleProgressBar.onPull(materialRefreshLayout, fraction);
float a = Util.limitValue(1, fraction);
ViewCompat.setScaleX(circleProgressBar, a);
ViewCompat.setScaleY(circleProgressBar, a);
ViewCompat.setAlpha(circleProgressBar, a);
}
}
@Override
public void onRelease(MaterialRefreshLayout materialRefreshLayout, float fraction) {
}
@Override
public void onRefreshing(MaterialRefreshLayout materialRefreshLayout) {
if (materialWaveView != null) {
materialWaveView.onRefreshing(materialRefreshLayout);
}
if (circleProgressBar != null) {
ViewCompat.setScaleX(circleProgressBar, 1f);
ViewCompat.setScaleY(circleProgressBar, 1f);
ViewCompat.setAlpha(circleProgressBar, 1f);
circleProgressBar.onRefreshing(materialRefreshLayout);
}
}
}