Android animation is slow/not chaining
<p>Hello i want to chain some android animations.
I added a listener to call a new animation after animation end.</p>

<p>I dont know if this is my mobile which causes the slowlyness.</p>

<p>here is my code:</p>

<p>click start, wait for a combination
click a button which represents the combination
start again a new combination of two
click two buttons ... then 3,4,5 ...</p>

<pre><code>private Resources res;
AnimationDrawable frameAnimation;

private TextView result;
private TextView punchSize;
private int correctColorPunches = 0;
private List&lt;Integer&gt; combination = new ArrayList&lt;Integer&gt;();
private List&lt;Integer&gt; enteredCombination = new ArrayList&lt;Integer&gt;();;
Random randomGenerator = new Random();

Animation animation1;
Animation animation2;
Animation animation3;
Animation animation4;
Animation animation5;

int animationCounter = 0;
private boolean animationReady = true;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String deviceId = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
    res = getResources();

    button1 = (ImageView) findViewById(R.id.button1);
    button2 = (ImageView) findViewById(R.id.button2);
    button3 = (ImageView) findViewById(R.id.button3);
    button4 = (ImageView) findViewById(R.id.button4);
    button5 = (ImageView) findViewById(R.id.button5);

    animation1 = AnimationUtils.loadAnimation(this, R.anim.animation);
    animation2 = AnimationUtils.loadAnimation(this, R.anim.animation);
    animation3 = AnimationUtils.loadAnimation(this, R.anim.animation);
    animation4 = AnimationUtils.loadAnimation(this, R.anim.animation);
    animation5 = AnimationUtils.loadAnimation(this, R.anim.animation);
    animation1.setAnimationListener(this);
    animation2.setAnimationListener(this);
    animation3.setAnimationListener(this);
    animation4.setAnimationListener(this);
    animation5.setAnimationListener(this);

    result = (TextView) findViewById(R.id.result);
    punchSize = (TextView) findViewById(R.id.punchSize);
    startGameButton = (Button) findViewById(R.id.startGameButton);


    result.setText("0");
    startGameButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            punchSize.setText("1");
            startNewCombinationRound();
            enableOnClickListener();
            msg("Spiel gestartet...");
        }
    });
}

private Animation getAnimation(int animationId) {
     switch (animationId){
        case 0 : return animation1;
        case 1 : return animation2;
        case 2 : return animation3;
        case 3 : return animation4;
        case 4 : return animation5;
    }
    return null;
}

private void playAnimation() {
    while (!animationReady) {
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
    if(animationCounter &lt; combination.size()) {
        animationReady = false;
        findViewById(getButton(combination.get(animationCounter))).startAnimation(getAnimation(combination.get(animationCounter)));
        return;
    }
}


private int generateRandomButtonId() {
    return randomGenerator.nextInt(4)+1;
}

private void startNewCombinationRound() {
    enteredCombination.clear();
    this.combination.add(generateRandomButtonId());
    animationCounter = 0;
    playAnimation();
}

private int getButton(int buttonId) {
    switch (buttonId){
        case 1 : return R.id.button1;
        case 2 : return R.id.button2;
        case 3 : return R.id.button3;
        case 4 : return R.id.button4;
        case 5 : return R.id.button5;
    }
    return R.id.button1;
}

private void enableOnClickListener() {
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setValuesAndValidate(1);
        }
    });

    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setValuesAndValidate(2);
        }
    });

    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setValuesAndValidate(3);
        }
    });

    button4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setValuesAndValidate(4);
        }
    });

    button5.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setValuesAndValidate(5);
        }
    });
}


private void disableOnClickListener() {
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            tooFastMsg();
        }
    });

    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            tooFastMsg();
        }
    });

    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            tooFastMsg();
        }
    });

    button4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            tooFastMsg();
        }
    });

    button5.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            tooFastMsg();
        }
    });
}

private void tooFastMsg() {
    msg("Du bist zu schnell!");
}

private void setValuesAndValidate(int buttonId) {
    enteredCombination.add(buttonId);
    validateCombination();
    setResult();
}

private void setResult() {
    correctColorPunches = correctColorPunches + 1;
    result.setText(String.valueOf(correctColorPunches));
}

private void validateCombination() {
    int numberOfEnteredValues = enteredCombination.size();

    if(combination.size()==0) {
        msg("Noch nicht gestartet...");
    } else {
        if(numberOfEnteredValues &lt; combination.size()) {
            for (int i = 0; i &lt; numberOfEnteredValues; i++) {
                if(!combination.get(i).equals(enteredCombination.get(i))) {
                    msg("GameOver!");
                    Intent intent = getIntent();
                    finish();
                    startActivity(intent);
                    return;
                }
            }
            return;
        }
        for (int i = 0; i &lt; numberOfEnteredValues; i++) {
            if(!combination.get(i).equals(enteredCombination.get(i))) {
                msg("GameOver!");
                Intent intent = getIntent();
                finish();
                startActivity(intent);
                return;
            }
        }
        punchSize.setText(String.valueOf(combination.size()+1));
        msg("Richtig!");
        startNewCombinationRound();
    }
}

public void onAnimationStart(Animation animation) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    Log.d("blub", "#######################################################START"+dateFormat.format(date) + " counter:"+animationCounter);
    animationCounter++;

    //To change body of implemented methods use File | Settings | File Templates.
}

public void onAnimationEnd(Animation animation) {
     DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    Log.d("blub", "#######################################################ENDE"+dateFormat.format(date) + " counter:"+animationCounter);
    animationReady = true;
    playAnimation();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }
}

public void onAnimationRepeat(Animation animation) {


}
</code></pre>

<p>}</p>
