80,349
社区成员
发帖
与我相关
我的任务
分享
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint = new Paint();
mPaint.setAntiAlias(true);
int round = mHeight/2;
System.out.println("max="+maxCount + " current="+currentCount);
mPaint.setColor(Color.rgb(71, 76, 80));
RectF rectBg = new RectF(0, 0, mWidth, mHeight);
canvas.drawRoundRect(rectBg, round, round, mPaint);
mPaint.setColor(Color.BLACK);
RectF rectBlackBg = new RectF(2, 2, mWidth-2, mHeight-2);
canvas.drawRoundRect(rectBlackBg, round, round, mPaint);
float section = currentCount/maxCount;
RectF rectProgressBg = new RectF(3, 3, (mWidth-3)*section, mHeight-3);
mPaint.setColor(SECTION_COLORS[0]);
canvas.drawRoundRect(rectProgressBg, round, round, mPaint);
if(section <= 0.23f/1.0f){
}
else if(section > 0.23f/1.0f & section <= 0.48f/1.0f){
mPaint.setColor(SECTION_COLORS[1]);
canvas.drawRect(3+(mWidth-3)*0.23f, 3, (mWidth-3)*0.27f, mHeight-3,mPaint);
}
else if(section > 0.48f/1.0f & section <= 0.73f/1.0f){
mPaint.setColor(SECTION_COLORS[1]);
canvas.drawRect(3+(mWidth-3)*0.23f, 3, (mWidth-3)*0.27f, mHeight-3,mPaint);
mPaint.setColor(SECTION_COLORS[1]);
canvas.drawRect(3+(mWidth-3)*0.48f, 3, (mWidth-3)*0.52f, mHeight-3,mPaint);
}
else if(section > 0.73f/1.0f){
mPaint.setColor(SECTION_COLORS[1]);
canvas.drawRect(3+(mWidth-3)*0.23f, 3, (mWidth-3)*0.27f, mHeight-3,mPaint);
mPaint.setColor(SECTION_COLORS[1]);
canvas.drawRect(3+(mWidth-3)*0.48f, 3, (mWidth-3)*0.52f, mHeight-3,mPaint);
mPaint.setColor(SECTION_COLORS[1]);
canvas.drawRect(3+(mWidth-3)*0.73f, 3, (mWidth-3)*0.77f, mHeight-3,mPaint);
}
// else{
// int count = (section <= 1.0f/3.0f*2 ) ? 2 : 3;
// int[] colors = new int[count];
// System.arraycopy(SECTION_COLORS, 0, colors, 0, count);
// float[] positions = new float[count];
// if(count == 2){
// positions[0] = 0.0f;
// positions[1] = 1.0f-positions[0];
// }else{
// positions[0] = 0.0f;
// positions[1] = (maxCount/3)/currentCount;
// positions[2] = 1.0f-positions[0]*2;
// }
// positions[positions.length-1] = 1.0f;
// LinearGradient shader = new LinearGradient(3, 3, (mWidth-3)*section, mHeight-3, colors,null, Shader.TileMode.MIRROR);
// mPaint.setShader(shader);
// }
// canvas.drawRoundRect(rectProgressBg, round, round, mPaint);
}