Created
June 15, 2018 08:35
-
-
Save ssaurel/07dd8418b2dfd1262c2f0d55ed315d9a to your computer and use it in GitHub Desktop.
spin method for the Roulette Game on the SSaurel's Channel
This file contains hidden or 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
@OnClick(R.id.spinBtn) | |
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.setDuration(3600); | |
rotateAnim.setFillAfter(true); | |
rotateAnim.setInterpolator(new DecelerateInterpolator()); | |
rotateAnim.setAnimationListener(new Animation.AnimationListener() { | |
@Override | |
public void onAnimationStart(Animation animation) { | |
// we empty the result text view when the animation start | |
resultTv.setText(""); | |
} | |
@Override | |
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))); | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { | |
} | |
}); | |
// we start the animation | |
wheel.startAnimation(rotateAnim); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment