Files
yusheng-android/BaseModule/src/main/java/com/xscm/moduleutil/widget/CustomRefreshHeader.java
2025-11-07 09:22:39 +08:00

119 lines
3.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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) {
}
}