@ -137,6 +85,16 @@ public class AnimatedProgressBar extends LinearLayout {
@@ -137,6 +85,16 @@ public class AnimatedProgressBar extends LinearLayout {
returnmProgress;
}
privatefinalPaintmPaint=newPaint();
privatefinalRectmRect=newRect();
@Override
protectedvoidonDraw(Canvascanvas){
mPaint.setColor(mProgressColor);
mPaint.setStrokeWidth(10);
mRect.right=mRect.left+mDrawWidth;
canvas.drawRect(mRect,mPaint);
}
/**
*setstheprogressasanintegervaluebetween0and100.
@ -154,29 +112,30 @@ public class AnimatedProgressBar extends LinearLayout {
@@ -154,29 +112,30 @@ public class AnimatedProgressBar extends LinearLayout {
progress=0;
}
if(mProgressView.getAlpha()<1.0f&&progress<100){
if(this.getAlpha()<1.0f){
fadeIn();
}
finalintmaxWidth=this.getMeasuredWidth();// get the maximum width the view can be
intinitialWidth=mProgressView.getMeasuredWidth();// get the initial width of the view
intmWidth=this.getMeasuredWidth();
// Set the drawing bounds for the ProgressBar
mRect.left=0;
mRect.top=0;
mRect.bottom=this.getBottom()-this.getTop();
if(progress<mProgress&&!mBidirectionalAnimate){// if the we only animate the view in one direction
// then reset the view width if it is less than the
// previous progress
mProgressView.getLayoutParams().width=0;
mProgressView.requestLayout();
initialWidth=0;
mDrawWidth=0;
}elseif(progress==mProgress){// we don't need to go any farther if the progress is unchanged
return;
}
mProgress=progress;// save the progress
finalintdeltaWidth=(maxWidth*mProgress/100)-initialWidth;// calculate amount the width has to change
finalintdeltaWidth=(mWidth*mProgress/100)-mDrawWidth;// calculate amount the width has to change
animateView(initialWidth,maxWidth,deltaWidth);// animate the width change
animateView(mDrawWidth,mWidth,deltaWidth);// animate the width change
}
/**
@ -187,18 +146,38 @@ public class AnimatedProgressBar extends LinearLayout {
@@ -187,18 +146,38 @@ public class AnimatedProgressBar extends LinearLayout {