Instantly share code, notes, and snippets.

Embed
What would you like to do?
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