From bd802ba0ca82fba39d964847e8690374d71dceff Mon Sep 17 00:00:00 2001 From: junhualin Date: Mon, 16 Dec 2019 20:31:53 +0800 Subject: [PATCH 1/6] =?UTF-8?q?RefreshInternal=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=B7=E6=96=B0=E5=8A=A0=E8=BD=BD=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 10 +++++----- .../example/CustomExampleActivity.java | 5 +++++ .../layout/SmartRefreshLayout.java | 19 +++++++++++++++++++ .../layout/api/RefreshInternal.java | 7 +++++++ .../layout/internal/InternalAbstract.java | 6 ++++++ 5 files changed, 42 insertions(+), 5 deletions(-) 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/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) { From 01f4bfe1b09c4740177809bf786403de2995b3e6 Mon Sep 17 00:00:00 2001 From: junhualin Date: Mon, 6 Jan 2020 10:47:16 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMaterialHeader=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=90=8E=E4=BC=9A=E5=BD=B1=E5=93=8D=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=A4=B4=E9=83=A8=E6=95=88=E6=9E=9C=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scwang/smartrefresh/header/MaterialHeader.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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..bad67bec 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 @@ -165,10 +165,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; } From 1a54f31cc0c7415197c32639ad23471a6c4b843c Mon Sep 17 00:00:00 2001 From: junhualin Date: Mon, 6 Jan 2020 10:47:41 +0800 Subject: [PATCH 3/6] =?UTF-8?q?1=20=E4=BF=AE=E5=A4=8DMaterialProgressDrawa?= =?UTF-8?q?ble=E8=AE=BE=E7=BD=AE=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=90=8E=E5=AF=BC=E8=87=B4=E7=8E=AF=E5=BD=A2=E7=AE=AD?= =?UTF-8?q?=E5=A4=B4=E8=A2=AB=E8=A6=86=E7=9B=96=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?2=20=E4=BF=AE=E5=A4=8D=E8=83=8C=E6=99=AF=E5=90=8E=E5=9C=A8?= =?UTF-8?q?=E6=9A=97=E8=89=B2=E8=83=8C=E6=99=AF=E4=B8=8B=E6=9C=89=E7=99=BD?= =?UTF-8?q?=E8=BE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../header/internal/MaterialProgressDrawable.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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) { From d258bd4ceec4078fd22b4314b5da90ec0442363b Mon Sep 17 00:00:00 2001 From: junhualin Date: Mon, 6 Jan 2020 10:47:59 +0800 Subject: [PATCH 4/6] =?UTF-8?q?1=20=E4=BF=AE=E5=A4=8DMaterialHeader?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=BF=9B=E5=BA=A6=E6=9D=A1=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6=E5=90=88=E9=A2=84=E6=9C=9F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=982=20=E7=A7=BB=E9=99=A4=E8=BF=9B=E5=BA=A6=E6=9D=A1?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=80=8F=E6=98=8E3=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=BF=9B=E5=BA=A6=E6=9D=A1=E9=80=8F=E6=98=8E?= =?UTF-8?q?=E5=BA=A6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smartrefresh/header/MaterialHeader.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 bad67bec..18a40bfa 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; @@ -80,7 +81,7 @@ public MaterialHeader(Context context, AttributeSet attrs) { 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); @@ -280,14 +281,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; } From 8b0dc742225bd1a33e28bd7881f36d84ad59aea8 Mon Sep 17 00:00:00 2001 From: junhualin Date: Mon, 6 Jan 2020 10:48:14 +0800 Subject: [PATCH 5/6] =?UTF-8?q?MaterialStyleActivity=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=97=B6=E5=90=8C=E6=97=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AE=AD=E5=A4=B4=E8=BF=9B=E5=BA=A6=E6=9D=A1=E7=9A=84=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=EF=BC=8C=E4=BD=BFdemo=E4=BD=93=E9=AA=8C=E6=9B=B4?= =?UTF-8?q?=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../refreshlayout/activity/style/MaterialStyleActivity.java | 1 + 1 file changed, 1 insertion(+) 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)); } From c2e007014dcd59a08f176e2cae4ffa7645124a19 Mon Sep 17 00:00:00 2001 From: junhualin Date: Mon, 6 Jan 2020 11:04:26 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B6=E6=B5=8B?= =?UTF-8?q?=E9=87=8F=E9=AB=98=E5=BA=A6=E5=8F=97=E5=85=B6=E4=BB=96header?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E5=BD=B1=E5=93=8D=E9=97=AE=E9=A2=98=EF=BC=9A?= =?UTF-8?q?MaterialHeader=E6=B5=8B=E9=87=8F=E6=97=B6=E7=BB=99=E5=85=B6?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E9=AB=98=E5=BA=A6=E4=B8=BA=E6=9C=80=E5=B0=8F?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E5=90=8C=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/scwang/smartrefresh/header/MaterialHeader.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 18a40bfa..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 @@ -59,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; @@ -77,7 +78,8 @@ 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); @@ -112,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));