protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); var time = (float)(DateTimeHelperClass.CurrentUnixTimeMillis() - _startTime) / _period; if (_isPlaying) { for (var i = 3; i >= 0; i--) { var y = (float)-(_jumpHeight * Math.Max(0, Math.Sin(time + i / 1.5f))); switch (i) { case 2: _dotOne.TranslationY = y; break; case 1: _dotTwo.TranslationY = y; break; case 0: _dotThree.TranslationY = y; break; } } } else { for (var i = 3; i >= 0; i--) { var y = (float)-(_jumpHeight * Math.Max(0, Math.Sin(time + i / 1.5f))); switch (i) { case 2: if (y == 0 || _lockDotOne) { _lockDotOne = true; _dotOne.TranslationY = 0; } else { _dotOne.TranslationY = y; } break; case 1: if (y == 0 || _lockDotTwo) { _lockDotTwo = true; _dotTwo.TranslationY = 0; } else { _dotTwo.TranslationY = y; } break; case 0: if (y == 0 || _lockDotThree) { _lockDotThree = true; _dotThree.TranslationY = 0; } else { _dotThree.TranslationY = y; } break; } } if (_lockDotOne && _lockDotTwo && _lockDotThree) { //all are in bottom position SetWillNotDraw(true); } } Invalidate(); }