Maybe this will improve the performance just enough:
private int mCurrentColor;
if(rect_dark.contains(x, y)) {
isdark = !isdark;
if (isdark) {
mCurrentColor = getResources().getColor(R.color.dark_color);
} else {
mCurrentColor = getResources().getColor(R.color.light_color);
}
invalidate();
}
This avoids the color assignments in onDraw
method. If this is still unsatisfactory, you might try double buffering, as mentioned here.