|
3 | 3 | import android.content.Context; |
4 | 4 | import android.support.annotation.ColorInt; |
5 | 5 | import android.support.annotation.NonNull; |
6 | | -import android.util.AttributeSet; |
7 | | -import android.view.Gravity; |
8 | 6 | import android.view.View; |
9 | | -import android.widget.ImageView; |
10 | | -import android.widget.LinearLayout; |
11 | | -import android.widget.TextView; |
| 7 | +import android.widget.RelativeLayout; |
12 | 8 |
|
13 | 9 | import com.scwang.smartrefresh.layout.api.RefreshHeader; |
14 | 10 | import com.scwang.smartrefresh.layout.api.RefreshKernel; |
15 | 11 | import com.scwang.smartrefresh.layout.api.RefreshLayout; |
16 | 12 | import com.scwang.smartrefresh.layout.constant.RefreshState; |
17 | 13 | import com.scwang.smartrefresh.layout.constant.SpinnerStyle; |
18 | | -import com.scwang.smartrefresh.layout.internal.ProgressDrawable; |
19 | | -import com.scwang.smartrefresh.layout.internal.pathview.PathsView; |
20 | | -import com.scwang.smartrefresh.layout.util.DensityUtil; |
21 | 14 |
|
22 | 15 | /**anyview |
23 | 16 | * Created by painter.g on 2018/3/9. |
24 | 17 | */ |
25 | 18 |
|
26 | | -public class AnyHeader extends LinearLayout implements RefreshHeader { |
27 | | - private TextView mHeaderText;//标题文本 |
28 | | - private PathsView mArrowView;//下拉箭头 |
29 | | - private ImageView mProgressView;//刷新动画视图 |
30 | | - private ProgressDrawable mProgressDrawable;//刷新动画 |
31 | | - private View view; |
32 | | - private View pullDownToRefreshView; |
33 | | - private View releaseToRefreshView; |
34 | | - private View refreshingView; |
35 | | - protected int mPaddingTop = 20; |
36 | | - protected int mPaddingBottom = 20; |
| 19 | +public class AnyHeader extends RelativeLayout implements RefreshHeader { |
37 | 20 | private RefreshKernel mRefreshKernel; |
| 21 | + private int mBackgroundColor; |
38 | 22 |
|
39 | 23 | public AnyHeader(Context context) { |
40 | 24 | super(context); |
41 | | - initView(context); |
42 | | - } |
43 | | - public AnyHeader(Context context, AttributeSet attrs) { |
44 | | - super(context, attrs); |
45 | | - this.initView(context); |
46 | | - } |
47 | | - public AnyHeader(Context context, AttributeSet attrs, int defStyleAttr) { |
48 | | - super(context, attrs, defStyleAttr); |
49 | | - this.initView(context); |
50 | 25 | } |
51 | 26 | @Override |
52 | 27 | public void onInitialized(@NonNull RefreshKernel kernel, int height, int extendHeight) { |
53 | 28 | mRefreshKernel = kernel; |
54 | | - // mRefreshKernel.requestDrawBackgroundForHeader(Color.parseColor("red")); |
| 29 | + mRefreshKernel.requestDrawBackgroundForHeader(mBackgroundColor); |
55 | 30 | } |
56 | 31 | private void initView(Context context) { |
57 | | - setGravity(Gravity.CENTER); |
58 | | - //view = new TextView(context); |
59 | | - //mProgressDrawable = new ProgressDrawable(); |
60 | | - // mArrowView = new PathsView(context); |
61 | | - //mProgressView = new ImageView(context); |
62 | | - //mProgressView.setImageDrawable(mProgressDrawable); |
63 | | - // mArrowView.parserPaths("M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"); |
64 | | - // addView(mProgressView, DensityUtil.dp2px(20), DensityUtil.dp2px(20)); |
65 | | - // addView(mArrowView, DensityUtil.dp2px(20), DensityUtil.dp2px(20)); |
66 | | - addView(new View(context), DensityUtil.dp2px(20), DensityUtil.dp2px(20)); |
67 | | - //((TextView)view).setText("SmartRefreshLayout"); |
68 | | - //addView(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
69 | | - setMinimumHeight(DensityUtil.dp2px(60)); |
| 32 | + //setMinimumHeight(DensityUtil.dp2px(60)); |
| 33 | + } |
| 34 | + public void setView(View v){ |
| 35 | + addView(v); |
70 | 36 | } |
71 | 37 | @NonNull |
72 | 38 | public View getView() { |
73 | 39 | return this;//真实的视图就是自己,不能返回null |
74 | 40 | } |
75 | | - public void setView(View view){ |
76 | | - if(view !=null){ |
77 | | - addView(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
78 | | - } |
79 | | - //return this; |
80 | | - } |
| 41 | + |
81 | 42 | @Override |
82 | 43 | public SpinnerStyle getSpinnerStyle() { |
83 | 44 | return SpinnerStyle.Translate;//指定为平移,不能null |
84 | 45 | } |
| 46 | + |
85 | 47 | @Override |
86 | | - public void onStartAnimator(RefreshLayout layout, int headHeight, int extendHeight) { |
87 | | - //mProgressDrawable.start();//开始动画 |
| 48 | + public void setPrimaryColors(int... colors) { |
| 49 | + |
88 | 50 | } |
| 51 | + |
| 52 | + public AnyHeader setPrimaryColor(@ColorInt int primaryColor) { |
| 53 | + mBackgroundColor = primaryColor; |
| 54 | + if (mRefreshKernel != null) { |
| 55 | + mRefreshKernel.requestDrawBackgroundForHeader(primaryColor); |
| 56 | + } |
| 57 | + return this; |
| 58 | + } |
| 59 | + |
89 | 60 | @Override |
90 | | - public int onFinish(RefreshLayout layout, boolean success) { |
91 | | - return 500;//延迟500毫秒之后再弹回 |
| 61 | + public void onPulling(float percent, int offset, int height, int extendHeight) { |
| 62 | + |
92 | 63 | } |
| 64 | + |
93 | 65 | @Override |
94 | | - public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) { |
| 66 | + public void onReleasing(float percent, int offset, int height, int extendHeight) { |
| 67 | + |
95 | 68 | } |
| 69 | + |
96 | 70 | @Override |
97 | | - public boolean isSupportHorizontalDrag() { |
98 | | - return false; |
| 71 | + public void onReleased(RefreshLayout refreshLayout, int height, int extendHeight) { |
| 72 | + |
99 | 73 | } |
100 | 74 |
|
101 | 75 | @Override |
102 | | - public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) { |
| 76 | + public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int extendHeight) { |
| 77 | + |
103 | 78 | } |
| 79 | + |
104 | 80 | @Override |
105 | | - public void onPulling(float percent, int offset, int headHeight, int extendHeight) { |
| 81 | + public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) { |
| 82 | + return 0; |
106 | 83 | } |
107 | 84 |
|
108 | 85 | @Override |
109 | | - public void onReleased(RefreshLayout refreshLayout, int height, int extendHeight) { |
| 86 | + public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) { |
| 87 | + |
110 | 88 | } |
111 | 89 |
|
112 | 90 | @Override |
113 | | - public void onReleasing(float percent, int offset, int headHeight, int extendHeight) { |
| 91 | + public boolean isSupportHorizontalDrag() { |
| 92 | + return false; |
114 | 93 | } |
| 94 | + |
115 | 95 | @Override |
116 | | - public void setPrimaryColors(@ColorInt int ... colors){ |
| 96 | + public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) { |
| 97 | + |
117 | 98 | } |
| 99 | + /*@Override |
| 100 | + protected void onFinishInflate() { |
| 101 | + int childCount = getChildCount(); |
| 102 | + for(int i=0;i<childCount;i++){ |
| 103 | + addView(getChildAt(i)); |
| 104 | + } |
| 105 | + super.onFinishInflate(); |
| 106 | + }*/ |
118 | 107 | } |
0 commit comments