ull != data) {
// sum all data's value
float sum = 0;
for (int i = 0; i < data.size(); i++) {
sum = sum + data.get(i).getValue();
}
Paint mPaintFill = new Paint();
mPaintFill.setStyle(Style.FILL);
mPaintFill.setAntiAlias(true);
Paint mPaintBorder = new Paint();
mPaintBorder.setStyle(Style.STROKE);
mPaintBorder.setColor(radiusColor);
mPaintBorder.setAntiAlias(true);
int offset = -90;
// draw arcs of every piece
for (int j = 0; j < data.size(); j++) {
Titleva lueColorEntity e = data.get(j);
// get color
mPaintFill.setColor(e.getColor());
RectF oval = new RectF(position.x - radiusLength, position.y
- radiusLength, position.x + radiusLength, position.y
+ radiusLength);
int sweep = Math.round(e.getValue() / sum * 360f);
canvas.drawArc(oval, offset, sweep, true, mPaintFill);
canvas.drawArc(oval, offset, sweep, true, mPaintBorder);
offset = offset + sweep;
}
float sumvalue = 0f;
for (Titleva lueColorEntity e : data) {
float value = e.getValue();
sumvalue = sumvalue + value;
float rate = (sumvalue - value / 2) / sum;
mPaintFill.setColor(Color.BLUE);
// percentage
float percentage = (int) (value / sum * 10000) / 100f;
float offsetX = (float) (position.x - radiusLength * 0.5
* Math.sin(rate * -2 * Math.PI));
float offsetY = (float) (position.y - radiusLength * 0.5
* Math.cos(rate * -2 * Math.PI));
Paint mPaintFont = new Paint();
mPaintFont.setColor(Color.WHITE);
mPaintFont.setTextSize(MyUtils.sp2px(getContext(), 15));
mPaintFont.setAntiAlias(true);
mPaintFont.setStrokeWidth(5);
// draw titles
String title = e.getTitle();
float realx = 0;
float realy = 0;
// TODO title position
if (offsetX < position.x) {
realx = offsetX - mPaintFont.measureText(title) - 5;
} else if (offsetX > position.x) {
realx = offsetX + 5;
} else if (offsetX == position.x) {
realx = offsetX - (mPaintFont.measureText(title)/2);
}
if (offsetY >= position.y) {
if (value / sum < 0.2f) {
realy = offsetY + 10;
} else {
realy = offsetY + 5;
}
} else if (offsetY < position.y) {
if (value / sum < 0.2f) {
realy = offsetY - 10;
} else {
realy = offsetY + 5;
}
}
if(percentage != 0.0f) {
canvas.drawText(title, realx, realy, mPaintFont);
canvas.drawText(String.valueOf((int)value) + "min", realx, realy + MyUtils.sp2px(getContext(), 15), mPaintFont);
canvas.drawText(String.valueOf(percentage) + "%", realx,
realy + MyUtils.sp2px(getContext(), 30), mPaintFont);
}
}
}
}
/**
* @return the data
*/
public List getData() {
return data;
}
/**
* @param data
* the data to set
*/
public void setData(List data) {
this.data = data;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title
* the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the position
*/
public Point getPosition() {
return position;
}
/**
* @param position
* the position to set
*/
public void setPosition(Point position) {
this.position = position;
}
/**
* @return the radiusLength
*/
public int getRadiusLength() {
return radiusLength;
}
/**
* @param radiusLength
* the radiusLength to set
*/
public void setRadiusLength(int radiusLength) {
this.radiusLength = radiusLength;
}
/**
* @return the radiusColor
*/
public int getRadiusColor() {
return radiusColor;
}
/**
* @param radiusColor
* the radiusColor to set
*/
public void setRadiusColor(int radiusColor) {
this.radiusCol