@Override
protected void onDraw(Canvas canvas) {
float factor;
if (mProgress == 0 || mProgress == 1) {
factor = 1;
} else {
long elapsed = System.currentTimeMillis() - mProgressSetTime;
if (elapsed < 0) {
factor = 0;
} else if (elapsed > mSmoothAnimDuration) {
factor = 1;
} else {
factor = elapsed / (float) mSmoothAnimDuration;
}
}
mSmoothProgress = mStartProgress + factor * (mProgress - mStartProgress);
// Draw background
if (null != mDrbBackground) {
mDrbBackground.draw(canvas);
}
// Draw progress
if (null != mDrbProgress) {
if (mDrbProgress instanceof NinePatchDrawable
|| (mDrbProgress instanceof DrawableContainer && ((DrawableContainer) mDrbProgress).getCurrent() instanceof NinePatchDrawable)) {
if (mSmoothProgress == 0) {
mDrbProgress.setBounds(0, 0, 0, 0);
} else {
mDrbProgress.setBounds(0, mRawProgressBounds.top,
(int) (mRawProgressBounds.left + (mRawProgressBounds.width() - mProgressDrbMinWidth)
* mSmoothProgress)
+ mProgressDrbMinWidth, mRawProgressBounds.bottom);
}
}
mDrbProgress.draw(canvas);
}
// Draw progress text
if (mProgressTextVisible) {
mSb.delete(0, mSb.length());
if (StringUtils.isEmpty(mText)) {
mSb.append((int) (mSmoothProgress * 100));
mSb.append('%');
} else {
mSb.append(mText);
}
String text = mSb.toString();
mTextPaint.setAntiAlias(true);
mTextPaint.setColor(mProgressTextColor);
mTextPaint.setTextSize(mProgressTextSize);
mTextPaint.setTypeface(mTypeface);
mTextPaint.setTextAlign(Align.CENTER);
FontMetrics fm = mTextPaint.getFontMetrics();
int fontH = (int) (Math.abs(fm.descent - fm.ascent));
canvas.drawText(text, getWidth() >> 1, ((getHeight() - getPaddingTop() - getPaddingBottom()) >> 1) + (fontH >> 1), mTextPaint);
}
if (factor != 1) {
invalidate();
}
notifyProgressChange(mSmoothProgress, mProgress);
}
ProgressHorizontal.java 文件源码
java
阅读 14
收藏 0
点赞 0
评论 0
项目:CuiMarket
作者:
评论列表
文章目录