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