Skip to content

Commit

Permalink
fix 进度在95-100时再次开始进度条透明度问题
Browse files Browse the repository at this point in the history
  • Loading branch information
youlookwhat committed Jul 9, 2020
1 parent 6d77952 commit 8141fea
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions library/src/main/java/me/jingbin/progress/WebProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* 3. 修改消失动画时长,使其消失时看到可以进度跑完
* 4. [2019.9.29] 修复当第一次进度返回 0 或超过 10,出现不显示进度条的问题
* 5. 能显示渐变色
* 6. 进度在95-100时再次开始进度条透明度问题
*
* @author jingbin
* Link to https://github.com/youlookwhat/WebProgress
Expand Down Expand Up @@ -174,7 +175,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int h = MeasureSpec.getSize(heightMeasureSpec);

if (wMode == MeasureSpec.AT_MOST) {
w = w <= getContext().getResources().getDisplayMetrics().widthPixels ? w : getContext().getResources().getDisplayMetrics().widthPixels;
w = Math.min(w, getContext().getResources().getDisplayMetrics().widthPixels);
}
if (hMode == MeasureSpec.AT_MOST) {
h = mTargetHeight;
Expand All @@ -189,7 +190,7 @@ protected void onDraw(Canvas canvas) {

@Override
protected void dispatchDraw(Canvas canvas) {
canvas.drawRect(0, 0, mCurrentProgress / 100 * Float.valueOf(this.getWidth()), this.getHeight(), mPaint);
canvas.drawRect(0, 0, mCurrentProgress / 100 * (float) this.getWidth(), this.getHeight(), mPaint);
}

@Override
Expand All @@ -202,7 +203,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
CURRENT_MAX_UNIFORM_SPEED_DURATION = MAX_UNIFORM_SPEED_DURATION;
} else {
//取比值
float rate = this.mTargetWidth / Float.valueOf(screenWidth);
float rate = this.mTargetWidth / (float) screenWidth;
CURRENT_MAX_UNIFORM_SPEED_DURATION = (int) (MAX_UNIFORM_SPEED_DURATION * rate);
CURRENT_MAX_DECELERATE_SPEED_DURATION = (int) (MAX_DECELERATE_SPEED_DURATION * rate);
}
Expand All @@ -220,7 +221,9 @@ private void startAnim(boolean isFinished) {
if (mAnimator != null && mAnimator.isStarted()) {
mAnimator.cancel();
}
mCurrentProgress = mCurrentProgress == 0f ? 0.00000001f : mCurrentProgress;
mCurrentProgress = mCurrentProgress == 0 ? 0.00000001f : mCurrentProgress;
// 可能由于透明度造成突然出现的问题
setAlpha(1);

if (!isFinished) {
ValueAnimator mAnimator = ValueAnimator.ofFloat(mCurrentProgress, v);
Expand All @@ -233,7 +236,7 @@ private void startAnim(boolean isFinished) {
} else {

ValueAnimator segment95Animator = null;
if (mCurrentProgress < 95f) {
if (mCurrentProgress < 95) {
segment95Animator = ValueAnimator.ofFloat(mCurrentProgress, 95);
float residue = 1f - mCurrentProgress / 100f - 0.05f;
segment95Animator.setInterpolator(new LinearInterpolator());
Expand Down Expand Up @@ -293,7 +296,7 @@ protected void onDetachedFromWindow() {
}

private void doEnd() {
if (TAG == FINISH && mCurrentProgress == 100f) {
if (TAG == FINISH && mCurrentProgress == 100) {
setVisibility(GONE);
mCurrentProgress = 0f;
this.setAlpha(1f);
Expand Down Expand Up @@ -322,17 +325,22 @@ private int dip2px(float dpValue) {
return (int) (dpValue * scale + 0.5f);
}

public WebProgress setHeight(int heightDp) {
this.mTargetHeight = dip2px(heightDp);
return this;
}

public void setProgress(float progress) {
// fix 同时返回两个 100,产生两次进度条的问题;
if (TAG == UN_START && progress == 100f) {
if (TAG == UN_START && progress == 100) {
setVisibility(View.GONE);
return;
}

if (getVisibility() == View.GONE) {
setVisibility(View.VISIBLE);
}
if (progress < 95f) {
if (progress < 95) {
return;
}
if (TAG != FINISH) {
Expand Down

0 comments on commit 8141fea

Please sign in to comment.