protected void onDraw



protected void onDraw(Canvas canvas) {

Date d =
new Date(year, month 1, 1);
first_day = d.getDay();

final float w = getWidth();
final float h = getHeight();
//Рисуем общую рамку для View
canvas.drawRoundRect(new RectF(3, 3, w — 6, h — 6), 5, 5, paint);
//Рисуем название месяца
final String month_str = MonthName(month);
textPaint.setColor(Color.BLACK);
textPaint.setTextSize(20);
float text_width = textPaint.measureText(month_str);
canvas.drawText(month_str, (w — text_width) /
2, 23, textPaint);

day_rect_w = (w — 8 * 58) / 7;
day_rect_h = (h — 8 * 5 41) / 6;
head_day(canvas);


first_day = first_day 1;
if (first_day == 0) {
first_day = 7;
}

if (first_day == —1) {
first_day = 6;
}


int i, j;
j =
0;

int s = first_day 1;

for (i = 1; i <= count_day; i++) {
float x0 = 5 + 5 * s + day_rect_w * s;
float x1 = x0 + day_rect_w;
float y0 = 41 + 5 + 5 * j + day_rect_h * j;
float y1 = y0 + day_rect_h;
RectF rect =
new RectF(x0, y0, x1, y1);

if (s==6){
paint.setColor(Color.rgb(255,120,120));
paint.setStyle(Paint.Style.FILL);
canvas.drawRoundRect(rect,
5, 5, paint);
}

paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);

canvas.drawRoundRect(rect,
5, 5, paint);

s++;

if (s == 7) {
s =
0;
j++;

}

}


}

 

Leave a Reply