Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Dsiner committed Dec 24, 2020
1 parent d86aee2 commit 5d776a3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 94 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Maven:
<dependency>
<groupId>com.dsiner.lib</groupId>
<artifactId>pulllayout</artifactId>
<version>1.0.1</version>
<version>1.0.3</version>
</dependency>
```
or Gradle:
```groovy
implementation 'com.dsiner.lib:pulllayout:1.0.1'
implementation 'com.dsiner.lib:pulllayout:1.0.3'
```

## Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,9 @@ public class Loading extends State {
private float mFactor;
private boolean mTaskRunning;

static class AnimUpdateListener implements ValueAnimator.AnimatorUpdateListener {
private final WeakReference<Loading> reference;

AnimUpdateListener(Loading view) {
this.reference = new WeakReference<>(view);
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
Loading view = reference.get();
if (view == null || view.mContext == null
|| view.mContext instanceof Activity && ((Activity) view.mContext).isFinishing()
|| view.mView == null) {
return;
}
view.mFactor = (float) animation.getAnimatedValue();
view.mView.invalidate();
}
public Loading(View view) {
super(view);
init(mContext);
}

@Override
Expand All @@ -66,11 +51,6 @@ public void stop() {
mTaskRunning = false;
}

public Loading(View view) {
super(view);
init(mContext);
}

private void init(Context context) {
mSpace = Utils.dp2px(context, 2.5f);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Expand Down Expand Up @@ -106,4 +86,24 @@ public void onDraw(Canvas canvas) {
mRectF.set(mRect);
canvas.drawArc(mRectF, mFactor, 90, false, mPaint);
}

static class AnimUpdateListener implements ValueAnimator.AnimatorUpdateListener {
private final WeakReference<Loading> reference;

AnimUpdateListener(Loading view) {
this.reference = new WeakReference<>(view);
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
Loading view = reference.get();
if (view == null || view.mContext == null
|| view.mContext instanceof Activity && ((Activity) view.mContext).isFinishing()
|| view.mView == null) {
return;
}
view.mFactor = (float) animation.getAnimatedValue();
view.mView.invalidate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,75 @@ public class Success extends State {
private Task mTask;
private Handler mHandler;

public Success(View view) {
super(view);
init(mContext);
initAttr(mContext);
}

@Override
public void reStart() {
stop();
mTaskRunning = true;
mStep = 0;
mView.invalidate();
mHandler.postDelayed(mTask, 700);
}

@Override
public void stop() {
mAnimator.cancel();
mTaskRunning = false;
mStep = 0;
mHandler.removeCallbacks(mTask);
}

private void init(Context context) {
mTask = new Task(this);
mHandler = new Handler();

mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

mAnimator = ValueAnimator.ofFloat(0f, 1f);
mAnimator.setDuration(450);
mAnimator.setInterpolator(new LinearInterpolator());
mAnimator.addListener(new AnimListenerAdapter(this));
mAnimator.addUpdateListener(new AnimUpdateListener(this));
}

protected void initAttr(Context context) {
mSign = new Done(mView);
mContent = "Refresh success";

mPaintText.setColor(mColorWhite);
mPaintText.setTextSize(Utils.dp2px(context, 14));
mPaintText.setTextAlign(Paint.Align.CENTER);
mTextHeight = Utils.getTextHeight(mPaintText);

mPaint.setColor(mColor);
}

@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mStep == 0) {
mSign.onDraw(canvas);
return;
}
float start = mHeight * 0.35f / 2f;
float end = (float) Math.sqrt(mHeight / 2f * mHeight / 2f + mWidth / 2f * mWidth / 2f) + 1;
canvas.drawCircle(mWidth / 2f, mHeight / 2f, start + (end - start) * mFactor, mPaint);

canvas.drawText(mContent, mWidth / 2f, mHeight / 2 + mTextHeight / 2, mPaintText);
}

@Override
public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
super.setMeasuredDimension(measuredWidth, measuredHeight);
mSign.setMeasuredDimension(measuredWidth, measuredHeight);
}

static class AnimListenerAdapter extends AnimatorListenerAdapter {
private final WeakReference<Success> reference;

Expand Down Expand Up @@ -105,73 +174,4 @@ public void run() {
view.mAnimator.start();
}
}

@Override
public void reStart() {
stop();
mTaskRunning = true;
mStep = 0;
mView.invalidate();
mHandler.postDelayed(mTask, 700);
}

@Override
public void stop() {
mAnimator.cancel();
mTaskRunning = false;
mStep = 0;
mHandler.removeCallbacks(mTask);
}

public Success(View view) {
super(view);
init(mContext);
initAttr(mContext);
}

private void init(Context context) {
mTask = new Task(this);
mHandler = new Handler();

mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

mAnimator = ValueAnimator.ofFloat(0f, 1f);
mAnimator.setDuration(450);
mAnimator.setInterpolator(new LinearInterpolator());
mAnimator.addListener(new AnimListenerAdapter(this));
mAnimator.addUpdateListener(new AnimUpdateListener(this));
}

protected void initAttr(Context context) {
mSign = new Done(mView);
mContent = "Refresh success";

mPaintText.setColor(mColorWhite);
mPaintText.setTextSize(Utils.dp2px(context, 14));
mPaintText.setTextAlign(Paint.Align.CENTER);
mTextHeight = Utils.getTextHeight(mPaintText);

mPaint.setColor(mColor);
}

@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mStep == 0) {
mSign.onDraw(canvas);
return;
}
float start = mHeight * 0.35f / 2f;
float end = (float) Math.sqrt(mHeight / 2f * mHeight / 2f + mWidth / 2f * mWidth / 2f) + 1;
canvas.drawCircle(mWidth / 2f, mHeight / 2f, start + (end - start) * mFactor, mPaint);

canvas.drawText(mContent, mWidth / 2f, mHeight / 2 + mTextHeight / 2, mPaintText);
}

@Override
public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
super.setMeasuredDimension(measuredWidth, measuredHeight);
mSign.setMeasuredDimension(measuredWidth, measuredHeight);
}
}

0 comments on commit 5d776a3

Please sign in to comment.