diff --git a/app/build.gradle b/app/build.gradle index b8bc7c13..3818f1f4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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') { diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java index 2a5a8fcb..d721df99 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java +++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java @@ -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) { diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java index 79c5a893..40ab52e2 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java +++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java @@ -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)); } diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java index e14c0055..5f5a2354 100644 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java +++ b/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java @@ -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; @@ -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; @@ -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); @@ -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)); @@ -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; } @@ -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; } diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/internal/MaterialProgressDrawable.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/internal/MaterialProgressDrawable.java index 5973a7b0..59110fc8 100644 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/internal/MaterialProgressDrawable.java +++ b/refresh-header/src/main/java/com/scwang/smartrefresh/header/internal/MaterialProgressDrawable.java @@ -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) { diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java index fb212083..a9f211cf 100644 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java +++ b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java @@ -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); @@ -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 { @@ -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 { diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java index d1fd92d3..b8057bbb 100644 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java +++ b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java @@ -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 diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java index 20dc4831..5685e525 100644 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java +++ b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java @@ -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); @@ -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) {