119 lines
3.3 KiB
Java
119 lines
3.3 KiB
Java
package com.xscm.moduleutil.widget;
|
||
|
||
import android.annotation.SuppressLint;
|
||
import android.content.Context;
|
||
import android.graphics.drawable.AnimationDrawable;
|
||
import android.util.AttributeSet;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.widget.ImageView;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.annotation.Nullable;
|
||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||
|
||
import com.xscm.moduleutil.R;
|
||
import com.xscm.moduleutil.utils.logger.Logger;
|
||
import com.scwang.smartrefresh.layout.api.RefreshHeader;
|
||
import com.scwang.smartrefresh.layout.api.RefreshKernel;
|
||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||
import com.scwang.smartrefresh.layout.constant.RefreshState;
|
||
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
|
||
|
||
/**
|
||
* 项目名称 qipao-android
|
||
* 包名:com.qpyy.module.index.widget
|
||
* 创建人 王欧
|
||
* 创建时间 2020/6/30 3:55 PM
|
||
* 描述 describe
|
||
*/
|
||
public class CustomRefreshHeader extends ConstraintLayout implements RefreshHeader {
|
||
ImageView mImageView;
|
||
AnimationDrawable mAnimationDrawable;
|
||
|
||
public CustomRefreshHeader(Context context) {
|
||
this(context, null);
|
||
}
|
||
|
||
public CustomRefreshHeader(Context context, @Nullable AttributeSet attrs) {
|
||
super(context, attrs);
|
||
LayoutInflater.from(context).inflate(R.layout.index_header_custom_refresh, this);
|
||
mImageView = findViewById(R.id.image);
|
||
mAnimationDrawable = (AnimationDrawable) mImageView.getBackground();
|
||
}
|
||
|
||
@NonNull
|
||
@Override
|
||
public View getView() {
|
||
return this;
|
||
}
|
||
|
||
@NonNull
|
||
@Override
|
||
public SpinnerStyle getSpinnerStyle() {
|
||
return SpinnerStyle.Translate;
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void setPrimaryColors(int... colors) {
|
||
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {
|
||
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {
|
||
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
|
||
Logger.e("onReleased");
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
|
||
Logger.e("onStartAnimator");
|
||
//判断是否在运行
|
||
if (!mAnimationDrawable.isRunning()) {
|
||
//开启帧动画
|
||
mAnimationDrawable.start();
|
||
}
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) {
|
||
if (mAnimationDrawable.isRunning()) {
|
||
//开启帧动画
|
||
mAnimationDrawable.stop();
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public boolean isSupportHorizontalDrag() {
|
||
return false;
|
||
}
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
@Override
|
||
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
|
||
|
||
}
|
||
}
|