Created
June 24, 2020 10:55
-
-
Save utsmannn/3430d8c95c265ccd11057987b6d5d294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun rotateMarker(marker: Marker, toRotation: Float) { | |
val handler = Handler() | |
val start = SystemClock.uptimeMillis() | |
val startRotation = marker.rotation | |
val duration: Long = 300 | |
handler.post(object : Runnable { | |
override fun run() { | |
val elapsed = SystemClock.uptimeMillis() - start | |
val t = LinearInterpolator().getInterpolation(elapsed.toFloat() / duration) | |
val rot = t * toRotation + (1 - t) * startRotation | |
marker.rotation = if (-rot > 180) rot / 2 else rot | |
if (t < 1.0) { | |
handler.postDelayed(this, 16) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment