Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2018 08:35
What would you like to do?
spin method for the Roulette Game on the SSaurel's Channel
public void spin(View v) {
degreeOld = degree % 360;
// we calculate random angle for rotation of our wheel
degree = RANDOM.nextInt(360) + 720;
// rotation effect on the center of the wheel
RotateAnimation rotateAnim = new RotateAnimation(degreeOld, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setInterpolator(new DecelerateInterpolator());
rotateAnim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
// we empty the result text view when the animation start
public void onAnimationEnd(Animation animation) {
// we display the correct sector pointed by the triangle at the end of the rotate animation
resultTv.setText(getSector(360 - (degree % 360)));
public void onAnimationRepeat(Animation animation) {
// we start the animation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment