Merge branch 'feature/animation' into 'master'

Feature/animation



See merge request !42
This commit is contained in:
pengfeizhou
2019-12-03 11:41:22 +08:00
13 changed files with 132 additions and 143 deletions

View File

@@ -21,7 +21,7 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
private View content;
private Animation.AnimationListener mListener;
private PullingListener mPullingListenr;
private PullingListener mPullingListener;
public DoricRefreshView(@NonNull Context context) {
super(context);
@@ -38,12 +38,15 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
public void setContent(View v) {
removeAllViews();
content = v;
if (v.getLayoutParams() instanceof FrameLayout.LayoutParams) {
((LayoutParams) v.getLayoutParams()).gravity = Gravity.BOTTOM;
ViewGroup.LayoutParams params = v.getLayoutParams();
if (params instanceof LayoutParams) {
((LayoutParams) params).gravity = Gravity.BOTTOM;
} else {
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
v.setLayoutParams(params);
LayoutParams layoutParams = new LayoutParams(
params == null ? ViewGroup.LayoutParams.WRAP_CONTENT : params.width,
params == null ? ViewGroup.LayoutParams.WRAP_CONTENT : params.height);
layoutParams.gravity = Gravity.CENTER;
v.setLayoutParams(layoutParams);
}
addView(v);
}
@@ -53,28 +56,28 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
}
public void setPullingListenr(PullingListener listenr) {
this.mPullingListenr = listenr;
public void setPullingListener(PullingListener listener) {
this.mPullingListener = listener;
}
@Override
public void startAnimation() {
if (mPullingListenr != null) {
mPullingListenr.startAnimation();
if (mPullingListener != null) {
mPullingListener.startAnimation();
}
}
@Override
public void stopAnimation() {
if (mPullingListenr != null) {
mPullingListenr.stopAnimation();
if (mPullingListener != null) {
mPullingListener.stopAnimation();
}
}
@Override
public void setProgressRotation(float rotation) {
if (mPullingListenr != null) {
mPullingListenr.setProgressRotation(rotation);
public void setPullingDistance(float distance) {
if (mPullingListener != null) {
mPullingListener.setPullingDistance(distance);
}
}

View File

@@ -30,6 +30,8 @@ import androidx.swiperefreshlayout.widget.CircularProgressDrawable;
import android.view.animation.Animation.AnimationListener;
import pub.doric.utils.DoricUtils;
/**
* @Description: pub.doric.pullable
* @Author: pengfei.zhou
@@ -117,11 +119,6 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
int mCustomSlingshotDistance;
private Animation mScaleAnimation;
private Animation mScaleDownAnimation;
private Animation mScaleDownToStartAnimation;
boolean mNotify;
@@ -131,6 +128,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
private OnChildScrollUpCallback mChildScrollUpCallback;
private DoricRefreshView mRefreshView;
private AnimationListener mRefreshListener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
@@ -158,6 +156,20 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
private int mPullDownHeight = 0;
private ValueAnimator headerViewAnimator;
private void onRefreshAnimationEnd() {
if (mRefreshing) {
mRefreshView.startAnimation();
if (mNotify) {
if (mListener != null) {
mListener.onRefresh();
}
}
mCurrentTargetOffsetTop = mRefreshView.getTop();
} else {
reset();
}
}
void reset() {
mRefreshing = false;
if (headerViewAnimator != null && headerViewAnimator.isRunning()) {
@@ -169,6 +181,9 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
public void onAnimationUpdate(ValueAnimator animation) {
mCurrentTargetOffsetTop = (int) animation.getAnimatedValue()
- mRefreshView.getMeasuredHeight();
if (mRefreshView.getMeasuredHeight() > 0) {
mRefreshView.setPullingDistance(DoricUtils.px2dp(mRefreshView.getBottom()));
}
mRefreshView.requestLayout();
}
});
@@ -320,36 +335,13 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
}
setTargetOffsetTopAndBottom(endTarget - mCurrentTargetOffsetTop);
mNotify = false;
startScaleUpAnimation(mRefreshListener);
mRefreshView.setVisibility(View.VISIBLE);
onRefreshAnimationEnd();
} else {
setRefreshing(refreshing, false /* notify */);
}
}
private void startScaleUpAnimation(AnimationListener listener) {
mRefreshView.setVisibility(View.VISIBLE);
mScaleAnimation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
setAnimationProgress(interpolatedTime);
}
};
mScaleAnimation.setDuration(mMediumAnimationDuration);
if (listener != null) {
mRefreshView.setAnimationListener(listener);
}
mRefreshView.clearAnimation();
mRefreshView.startAnimation(mScaleAnimation);
}
/**
* Pre API 11, this does an alpha animation.
*
* @param progress
*/
void setAnimationProgress(float progress) {
}
private void setRefreshing(boolean refreshing, final boolean notify) {
if (mRefreshing != refreshing) {
@@ -359,24 +351,11 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
if (mRefreshing) {
animateOffsetToCorrectPosition(mCurrentTargetOffsetTop, mRefreshListener);
} else {
startScaleDownAnimation(mRefreshListener);
onRefreshAnimationEnd();
}
}
}
void startScaleDownAnimation(Animation.AnimationListener listener) {
mScaleDownAnimation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
setAnimationProgress(1 - interpolatedTime);
}
};
mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
mRefreshView.setAnimationListener(listener);
mRefreshView.clearAnimation();
mRefreshView.startAnimation(mScaleDownAnimation);
}
/**
* @return Whether the SwipeRefreshWidget is actively showing refresh
* progress.
@@ -744,24 +723,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
} else {
// cancel refresh
mRefreshing = false;
Animation.AnimationListener listener = null;
listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
startScaleDownAnimation(null);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
};
animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
animateOffsetToStartPosition(mCurrentTargetOffsetTop, null);
}
}
@@ -912,7 +874,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
ViewCompat.offsetTopAndBottom(mRefreshView, offset);
mCurrentTargetOffsetTop = mRefreshView.getTop();
if (mRefreshView.getMeasuredHeight() > 0) {
mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight() * 2);
mRefreshView.setPullingDistance(DoricUtils.px2dp(mRefreshView.getBottom()));
}
}

View File

@@ -16,5 +16,5 @@ public interface PullingListener {
*
* @param rotation Rotation is from [0..2]
*/
void setProgressRotation(float rotation);
void setPullingDistance(float rotation);
}

View File

@@ -33,7 +33,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
@Override
protected DoricSwipeLayout build() {
DoricSwipeLayout doricSwipeLayout = new DoricSwipeLayout(getContext());
doricSwipeLayout.getRefreshView().setPullingListenr(this);
doricSwipeLayout.getRefreshView().setPullingListener(this);
return doricSwipeLayout;
}
@@ -188,9 +188,9 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
}
@Override
public void setProgressRotation(float rotation) {
public void setPullingDistance(float rotation) {
if (mHeaderNode != null) {
mHeaderNode.callJSResponse("setProgressRotation", rotation);
mHeaderNode.callJSResponse("setPullingDistance", rotation);
}
}
}