Skip to content

Commit

Permalink
优化Header
Browse files Browse the repository at this point in the history
  • Loading branch information
scwang90 committed Feb 5, 2018
1 parent 85bfacf commit f4e3b07
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 47 deletions.
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_refresh_practive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
tools:listitem="@android:layout/simple_list_item_2"/>
<com.scwang.smartrefresh.header.StoreHouseHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
app:shhEnableFadeAnimation="true"/>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>

</LinearLayout>
2 changes: 1 addition & 1 deletion refresh-header/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ publish {
userOrg = 'scwang90'
groupId = 'com.scwang.smartrefresh'
artifactId = 'SmartRefreshHeader'
version = '1.0.5-alpha-3'
version = '1.0.5'
description = 'Some delicate headers of SmartRefreshLayout'
website = "https://github.com/scwang90/${rootProject.name}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;

import com.scwang.smartrefresh.header.storehouse.StoreHouseBarItem;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class StoreHouseHeader extends View implements RefreshHeader {
private int mTextColor = Color.WHITE;
private int mBackgroundColor = 0;
private boolean mIsInLoading = false;
private boolean mEnableFadeAnimation = false;
private Matrix mMatrix = new Matrix();
private RefreshKernel mRefreshKernel;
private AniController mAniController = new AniController();
Expand Down Expand Up @@ -100,6 +103,7 @@ private void initView(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.StoreHouseHeader);
mLineWidth = ta.getDimensionPixelOffset(R.styleable.StoreHouseHeader_shhLineWidth, mLineWidth);
mDropHeight = ta.getDimensionPixelOffset(R.styleable.StoreHouseHeader_shhDropHeight, mDropHeight);
mEnableFadeAnimation = ta.getBoolean(R.styleable.StoreHouseHeader_shhEnableFadeAnimation, mEnableFadeAnimation);
if (ta.hasValue(R.styleable.StoreHouseHeader_shhText)) {
initWithString(ta.getString(R.styleable.StoreHouseHeader_shhText));
} else {
Expand All @@ -125,13 +129,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
float progress = mProgress;
int c1 = canvas.save();
int len = mItemList.size();

if (isInEditMode()) {
progress = 1;
}
final int c1 = canvas.save();
final int len = mItemList.size();
final float progress = isInEditMode() ? 1 : mProgress;

for (int i = 0; i < len; i++) {

Expand Down Expand Up @@ -360,8 +360,27 @@ public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, R
@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
loadFinish();
for (int i = 0; i < mItemList.size(); i++) {
mItemList.get(i).resetPosition(mHorizontalRandomness);
if (success && mEnableFadeAnimation) {
startAnimation(new Animation() {{
setDuration(250);
setInterpolator(new AccelerateInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
setProgress(1 - interpolatedTime);
invalidate();
if (interpolatedTime == 1) {
for (int i = 0; i < mItemList.size(); i++) {
mItemList.get(i).resetPosition(mHorizontalRandomness);
}
}
}
});
return 250;
} else {
for (int i = 0; i < mItemList.size(); i++) {
mItemList.get(i).resetPosition(mHorizontalRandomness);
}
}
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions refresh-header/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<attr name="shhText" format="string" />
<attr name="shhLineWidth" format="dimension" />
<attr name="shhDropHeight" format="dimension" />
<attr name="shhEnableFadeAnimation" format="boolean" />
</declare-styleable>


Expand Down
2 changes: 1 addition & 1 deletion refresh-layout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ publish {
userOrg = 'scwang90'
groupId = 'com.scwang.smartrefresh'
artifactId = 'SmartRefreshLayout'
version = '1.0.5-alpha-3'
version = '1.0.5'
description = 'An intelligent refresh layout'
website = "https://github.com/scwang90/${rootProject.name}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -848,15 +848,11 @@ public void computeScroll() {
if(mVerticalPermit) {
float velocity;
if (Build.VERSION.SDK_INT >= 14) {
velocity = mScroller.getCurrVelocity();
velocity = finalY > 0 ? -mScroller.getCurrVelocity() : mScroller.getCurrVelocity();
} else {
velocity = 1f * (finalY - mScroller.getCurrY()) / Math.max((mScroller.getDuration() - mScroller.timePassed()), 1);
}
if (finalY > 0) {// 手势向上划 Footer
animSpinnerBounce(-velocity);
} else if (finalY < 0){// 手势向下划 Header
animSpinnerBounce(velocity);
velocity = 1f * (mScroller.getCurrY() - finalY) / Math.max((mScroller.getDuration() - mScroller.timePassed()), 1);
}
animSpinnerBounce(velocity);
}
mScroller.forceFinished(true);
} else {
Expand Down Expand Up @@ -1734,10 +1730,16 @@ public LayoutParams(ViewGroup.LayoutParams source) {
//<editor-fold desc="嵌套滚动 NestedScrolling">

//<editor-fold desc="NestedScrollingParent">

@Override
public int getNestedScrollAxes() {
return mNestedScrollingParentHelper.getNestedScrollAxes();
}

@Override
public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
boolean accepted = isEnabled() && isNestedScrollingEnabled() && (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
accepted = accepted && (isEnableRefresh() || isEnableLoadMore());
accepted = accepted && (mEnableOverScrollDrag || isEnableRefresh() || isEnableLoadMore());
return accepted;
}

Expand Down Expand Up @@ -1883,23 +1885,6 @@ public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int

}

@Override
public int getNestedScrollAxes() {
return mNestedScrollingParentHelper.getNestedScrollAxes();
}

@Override
public void onStopNestedScroll(@NonNull View target) {
mNestedScrollingParentHelper.onStopNestedScroll(target);
mNestedScrollInProgress = false;
// Finish the spinner for nested scrolling if we ever consumed any
// unconsumed nested scroll
mTotalUnconsumed = 0;
overSpinner();
// Dispatch up our nested parent
stopNestedScroll();
}

@Override
public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
// Dispatch up to the nested parent first
Expand All @@ -1911,19 +1896,25 @@ public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed,
// 'offset in window 'functionality to see if we have been moved from the event.
// This is a decent indication of whether we should take over the event stream or not.
final int dy = dyUnconsumed + mParentOffsetInWindow[1];
if (dy < 0 && isEnableRefresh() /* && (mRefreshContent == null || mRefreshContent.canRefresh())*/) {
if (mViceState == RefreshState.None) {
mKernel.setState(RefreshState.PullDownToRefresh);
}
mTotalUnconsumed += Math.abs(dy);
moveSpinnerInfinitely(mTotalUnconsumed/* + mTouchSpinner*/);
} else if (dy > 0 && isEnableLoadMore() /* && (mRefreshContent == null || mRefreshContent.canLoadMore())*/) {
if (dy != 0 && (mEnableOverScrollDrag || (dy < 0 && isEnableRefresh()) || (dy > 0 && isEnableLoadMore()))) {
if (mViceState == RefreshState.None) {
mKernel.setState(RefreshState.PullUpToLoad);
mKernel.setState(dy > 0 ? RefreshState.PullUpToLoad : RefreshState.PullDownToRefresh);
}
mTotalUnconsumed -= Math.abs(dy);
moveSpinnerInfinitely(mTotalUnconsumed/* + mTouchSpinner*/);
moveSpinnerInfinitely(mTotalUnconsumed -= dy);
}
// if (dy < 0 && isEnableRefresh() /* && (mRefreshContent == null || mRefreshContent.canRefresh())*/) {
// if (mViceState == RefreshState.None) {
// mKernel.setState(RefreshState.PullDownToRefresh);
// }
// mTotalUnconsumed += Math.abs(dy);
// moveSpinnerInfinitely(mTotalUnconsumed/* + mTouchSpinner*/);
// } else if (dy > 0 && isEnableLoadMore() /* && (mRefreshContent == null || mRefreshContent.canLoadMore())*/) {
// if (mViceState == RefreshState.None) {
// mKernel.setState(RefreshState.PullUpToLoad);
// }
// mTotalUnconsumed -= Math.abs(dy);
// moveSpinnerInfinitely(mTotalUnconsumed/* + mTouchSpinner*/);
// }
}

@Override
Expand All @@ -1935,6 +1926,18 @@ public boolean onNestedPreFling(@NonNull View target, float velocityX, float vel
public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed) {
return dispatchNestedFling(velocityX, velocityY, consumed);
}

@Override
public void onStopNestedScroll(@NonNull View target) {
mNestedScrollingParentHelper.onStopNestedScroll(target);
mNestedScrollInProgress = false;
// Finish the spinner for nested scrolling if we ever consumed any
// unconsumed nested scroll
mTotalUnconsumed = 0;
overSpinner();
// Dispatch up our nested parent
stopNestedScroll();
}
//</editor-fold>

//<editor-fold desc="NestedScrollingChild">
Expand Down

0 comments on commit f4e3b07

Please sign in to comment.