@Override protected void onDraw(Canvas canvas) { canvas.drawRect(outBox.getLeft(), outBox.getTop(), outBox.getRight(), outBox.getBottom(), outBox.getPaint()); dirChange = box.bounce(canvas, strokeWidth); rectifyBoundaries(canvas, box); canvas.drawRect(box.getLeft(), box.getTop(), box.getRight(), box.getBottom(), box.getPaint()); handler.postDelayed(r, dirChange ? FRAME_RATE * 20 : FRAME_RATE); }