This is the code i'm using, it is running the heavy part on the Background, and it draws a growing circle, and while it is growing, the text that is inside the circle fades out, the problem is that the text flickers between blue (the same color as the circle) and white (the color of the Text). I'm using double buffering (using a canvas, drawing everything i need and after that, publish the image that is beign used on the UI thread).
Any suggestions?
Canvas c = new Canvas(mBitmap);
c.drawColor(0, PorterDuff.Mode.SRC_OVER);
GrowingButtonData buttonInfo = (GrowingButtonData) params[0]
.get("buttonInfo");
int pickedCirclNumber = params[0].getInt("pickedCirclNumber");
int color = buttonInfo.getColor();
currentPaint.setColor(color);
Rect bounds = new Rect();
currentPaint.getTextBounds(buttonData.get(pickedCirclNumber)
.getText(), 0, buttonData.get(pickedCirclNumber)
.getText().length(), bounds);
String name = buttonData.get(pickedCirclNumber).getText();
float xText = offsetX * (pickedCirclNumber + 1)
+ (pickedCirclNumber * radius) + radius / 2.0f;
float yText = offsetY + radius / 2.0f + +bounds.height() / 2.0f;
float initalOffsetX = offsetX * (pickedCirclNumber + 1)
+ (pickedCirclNumber * radius);
while (lastRadius < getMeasuredWidth() * 1.5f) {
currentPaint.setAlpha(255);
currentPaint.setColor(Color.BLUE);
lastRadius += (System.currentTimeMillis() - lastTime);
lastTime = System.currentTimeMillis();
RectF rectF = new RectF();
rectF.set(
initalOffsetX
- ((lastRadius - (float) radius) / 2.0f),
(offsetY - ((lastRadius - (float) radius) / 2.0f)),
initalOffsetX + radius
+ ((lastRadius - (float) radius) / 2.0f),
(offsetY + radius + ((lastRadius - (float) radius) / 2.0f)));
c.drawArc(rectF, 0, 360, true, currentPaint);
int newAlpha = (int)(255.0f * (1.0f-lastRadius/(getMeasuredWidth()*2.0f)))-63;
if (newAlpha<0)
newAlpha =0;
currentPaint.setAlpha(newAlpha);
currentPaint.setColor(Color.GREEN);
c.drawText(name, xText, yText, currentPaint);
publishProgress(new JSONObject());
}
return params[0];
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
@Override
protected void onProgressUpdate(JSONObject... values) {
super.onProgressUpdate(values);
setImageBitmap(mBitmap);
}