Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created June 15, 2018 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/07dd8418b2dfd1262c2f0d55ed315d9a to your computer and use it in GitHub Desktop.
Save ssaurel/07dd8418b2dfd1262c2f0d55ed315d9a to your computer and use it in GitHub Desktop.
spin method for the Roulette Game on the SSaurel's Channel
@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