| package com.doumee.lib_coremodel.view; | 
|   | 
| import android.content.Context; | 
| import android.graphics.drawable.AnimationDrawable; | 
| import android.graphics.drawable.BitmapDrawable; | 
| import android.util.AttributeSet; | 
| import android.view.Gravity; | 
| import android.view.View; | 
| import android.widget.ImageView; | 
| import android.widget.LinearLayout; | 
|   | 
| import androidx.annotation.NonNull; | 
| import androidx.annotation.Nullable; | 
|   | 
| import com.doumee.lib_coremodel.R; | 
| import com.doumee.lib_coremodel.util.RxTimerUtil; | 
| import com.scwang.smart.refresh.layout.api.RefreshHeader; | 
| import com.scwang.smart.refresh.layout.api.RefreshKernel; | 
| import com.scwang.smart.refresh.layout.api.RefreshLayout; | 
| import com.scwang.smart.refresh.layout.constant.RefreshState; | 
| import com.scwang.smart.refresh.layout.constant.SpinnerStyle; | 
| import com.scwang.smart.refresh.layout.util.SmartUtil; | 
|   | 
| public class MyRefreshHeader extends LinearLayout implements RefreshHeader { | 
|     private ImageView imageView; | 
|     private AnimationDrawable anim; | 
|     private RxTimerUtil rxTimerUtil; | 
|     private boolean mSrlPrimaryColor; | 
|   | 
|     public MyRefreshHeader(Context context) { | 
|         this(context,null); | 
|     } | 
|   | 
|     public MyRefreshHeader(Context context, @Nullable AttributeSet attrs) { | 
|         super(context, attrs); | 
|         imageView=new ImageView(context); | 
|         imageView.setBackgroundResource(R.drawable.animation_list); | 
|         anim= (AnimationDrawable) imageView.getBackground(); | 
|         addView(imageView, SmartUtil.dp2px(30), SmartUtil.dp2px(30)); | 
|         setGravity(Gravity.CENTER); | 
|     } | 
|   | 
|     @NonNull | 
|     @Override | 
|     public View getView() { | 
|         return this; | 
|     } | 
|   | 
|     @NonNull | 
|     @Override | 
|     public SpinnerStyle getSpinnerStyle() { | 
|         return SpinnerStyle.Translate; | 
|     } | 
|   | 
|     @Override | 
|     public void setPrimaryColors(int... colors) { | 
|         //srlPrimaryColor | 
|         if(colors.length>0){ | 
|             if(!mSrlPrimaryColor&&!(getBackground() instanceof BitmapDrawable)){ | 
|                 setBackgroundColor(colors[0]); | 
|                 mSrlPrimaryColor=true; | 
|             } | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) { | 
|   | 
|     } | 
|   | 
|     @Override | 
|     public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) { | 
|   | 
|     } | 
|   | 
|     @Override | 
|     public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) { | 
|   | 
|     } | 
|   | 
|     @Override | 
|     public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) { | 
|         anim.start(); | 
|     } | 
|   | 
|     @Override | 
|     public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) { | 
|         if(rxTimerUtil==null){ | 
|             rxTimerUtil = new RxTimerUtil(); | 
|         } | 
|         rxTimerUtil.timer(200, new RxTimerUtil.IRxNext() { | 
|             @Override | 
|             public void doNext(long number) { | 
|                 imageView.setVisibility(GONE); | 
|                 anim.stop(); | 
|             } | 
|         }); | 
|   | 
|         return 200; | 
|     } | 
|   | 
|     @Override | 
|     public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) { | 
|   | 
|     } | 
|   | 
|     @Override | 
|     public boolean isSupportHorizontalDrag() { | 
|         return false; | 
|     } | 
|   | 
|     @Override | 
|     public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { | 
|         switch (newState) { | 
|             case None: | 
|             case PullDownToRefresh: | 
|             case Refreshing: | 
|                 //anim.start(); | 
|                 imageView.setVisibility(VISIBLE); | 
|                 break; | 
|             case ReleaseToRefresh: | 
|   | 
|                 break; | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     protected void onDetachedFromWindow() { | 
|         super.onDetachedFromWindow(); | 
|         if(rxTimerUtil!=null) { | 
|             rxTimerUtil.cancel(); | 
|         } | 
|     } | 
| } |