Skip to content
Open
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ dependencies {
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'

// implementation project(':refresh-footer')
// implementation project(':refresh-header')
// implementation project(':refresh-layout')
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
implementation project(':refresh-footer')
implementation project(':refresh-header')
implementation project(':refresh-layout')
// implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
// implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'

// //noinspection GradleDependency,GradleCompatible
// implementation ('com.android.support:support-v4:22.1.0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public void setPrimaryColors(int... colors) {

}

@Override
public void onAutoRefresh(boolean isAutoRefresh) {

}

@Override
public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
private void setThemeColor(int colorPrimary, int colorPrimaryDark) {
mToolbar.setBackgroundResource(colorPrimary);
mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white);
mMaterialHeader.setColorSchemeResources(colorPrimary);
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Path;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class MaterialHeader extends InternalAbstract implements RefreshHeader {
*/
protected int mWaveHeight;
protected int mHeadHeight;
protected int mHeadDefaultHeight;
protected Path mBezierPath;
protected Paint mBezierPaint;
protected RefreshState mState;
Expand All @@ -76,11 +78,12 @@ public MaterialHeader(Context context, AttributeSet attrs) {
mSpinnerStyle = SpinnerStyle.MatchLayout;
final View thisView = this;
final ViewGroup thisGroup = this;
thisView.setMinimumHeight(SmartUtil.dp2px(100));
mHeadDefaultHeight = SmartUtil.dp2px(100);
thisView.setMinimumHeight(mHeadDefaultHeight);

mProgress = new MaterialProgressDrawable(this);
mProgress.setBackgroundColor(CIRCLE_BG_LIGHT);
mProgress.setAlpha(255);
// mProgress.setAlpha(255);
mProgress.setColorSchemeColors(0xff0099cc,0xffff4444,0xff669900,0xffaa66cc,0xffff8800);
mCircleView = new CircleImageView(context,CIRCLE_BG_LIGHT);
mCircleView.setImageDrawable(mProgress);
Expand Down Expand Up @@ -111,7 +114,8 @@ public MaterialHeader(Context context, AttributeSet attrs) {

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.setMeasuredDimension(getSize(widthMeasureSpec), getSize(heightMeasureSpec));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
super.setMeasuredDimension(getSize(widthMeasureSpec), mHeadDefaultHeight);
final View circleView = mCircleView;
circleView.measure(MeasureSpec.makeMeasureSpec(mCircleDiameter, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(mCircleDiameter, MeasureSpec.EXACTLY));
Expand Down Expand Up @@ -165,10 +169,13 @@ protected void dispatchDraw(Canvas canvas) {
@Override
public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {
final View thisView = this;
if (!mShowBezierWave) {
kernel.requestDefaultTranslationContentFor(this, false);
// kernel.requestDefaultHeaderTranslationContent(false);
}
//不改变布局移动的默认设置因为会影响后续设置的刷新头部的效果
// if (!mShowBezierWave) {
// kernel.requestDefaultTranslationContentFor(this, false);
//// kernel.requestDefaultHeaderTranslationContent(false);
// }
//只改变自身是否移动布局内容
kernel.getRefreshLayout().setEnableHeaderTranslationContent(mShowBezierWave);
if (thisView.isInEditMode()) {
mWaveHeight = mHeadHeight = height / 2;
}
Expand Down Expand Up @@ -277,14 +284,23 @@ public MaterialHeader setProgressBackgroundColorSchemeResource(@ColorRes int col
return setProgressBackgroundColorSchemeColor(color);
}

/**
/**
* Set the alpha of the progress spinner disc.
*
* @param alpha 透明度
*/
public MaterialHeader setProgressAlpha(@IntRange(from = 0, to = 1) int alpha) {
mProgress.setAlpha(alpha);
return this;
}


/**
* Set the background color of the progress spinner disc.
*
* @param color 颜色
*/
public MaterialHeader setProgressBackgroundColorSchemeColor(@ColorInt int color) {
final View circle = mCircleView;
circle.setBackgroundColor(color);
mProgress.setBackgroundColor(color);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,19 @@ public void draw(Canvas c, Rect bounds) {
final float endAngle = (mEndTrim + mRotation) * 360;
float sweepAngle = endAngle - startAngle;

if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), (bounds.width() + 1f) / 2f,
mCirclePaint);
}

if (sweepAngle != 0) {
mPaint.setColor(mCurrentColor);
c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
}

drawTriangle(c, startAngle, sweepAngle, bounds);

if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2f,
mCirclePaint);
}
}

private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,17 @@ protected void notifyStateChanged(RefreshState state) {
final OnStateChangedListener refreshListener = mOnMultiPurposeListener;
if (refreshHeader != null) {
refreshHeader.onStateChanged(this, oldState, state);
//重置Header刷新标记
if (state == RefreshState.None && oldState == RefreshState.RefreshFinish) {
mRefreshHeader.onAutoRefresh(false);
}
}
if (refreshFooter != null) {
refreshFooter.onStateChanged(this, oldState, state);
//重置Footer刷新标记
if (state == RefreshState.None && oldState == RefreshState.LoadFinish) {
mRefreshFooter.onAutoRefresh(false);
}
}
if (refreshListener != null) {
refreshListener.onStateChanged(this, oldState, state);
Expand Down Expand Up @@ -3169,6 +3177,11 @@ public void onAnimationEnd(Animator animation) {
}
};
setViceState(RefreshState.Refreshing);
//触发Header自动刷新回调
if (mRefreshHeader != null) {
mRefreshHeader.onAutoRefresh(true);
}

if (delayed > 0) {
mHandler.postDelayed(runnable, delayed);
} else {
Expand Down Expand Up @@ -3266,6 +3279,12 @@ public void onAnimationEnd(Animator animation) {
}
};
setViceState(RefreshState.Loading);
//触发Footer自动刷新回调
if (mRefreshFooter != null)
{
mRefreshFooter.onAutoRefresh(true);
}

if (delayed > 0) {
mHandler.postDelayed(runnable, delayed);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public interface RefreshInternal extends OnStateChangedListener {
@RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES})
void setPrimaryColors(@ColorInt int... colors);

/**
* 【仅限框架内调用】自动刷新 (如果通过autoRefreshXxx或autoLoadMoreXxx方法触发才调用,在RefreshLayout#autoXxx中调用)
* @param isAutoRefresh 当触发autoRefreshXxx或autoLoadMoreXxx方法时候才进行回调且为true,当刷新完成时必定回调且为false
*/
@RestrictTo({LIBRARY, LIBRARY_GROUP, SUBCLASSES})
void onAutoRefresh(boolean isAutoRefresh);

/**
* 【仅限框架内调用】尺寸定义完成 (如果高度不改变(代码修改:setHeader),只调用一次, 在RefreshLayout#onMeasure中调用)
* @param kernel RefreshKernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class InternalAbstract extends RelativeLayout implements Refresh
protected View mWrappedView;
protected SpinnerStyle mSpinnerStyle;
protected RefreshInternal mWrappedInternal;
protected boolean mIsAutoRefresh;

protected InternalAbstract(@NonNull View wrapped) {
this(wrapped, wrapped instanceof RefreshInternal ? (RefreshInternal) wrapped : null);
Expand Down Expand Up @@ -116,6 +117,11 @@ public SpinnerStyle getSpinnerStyle() {
return mSpinnerStyle = SpinnerStyle.Translate;
}

@Override
public void onAutoRefresh(boolean isAutoRefresh) {
mIsAutoRefresh = isAutoRefresh;
}

@Override
public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {
if (mWrappedInternal != null && mWrappedInternal != this) {
Expand Down