TutorialScene5Activity.java 2.62 KB
package tonio.noa;

import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

/**
 * Created by psyk on 24/01/18.
 */

public class TutorialScene5Activity extends MyPlayActivity implements View.OnTouchListener {

    private int win_counter = 0;
    private boolean done = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        lanceConsigne("Cette fois\ntu dois cliquer sur les carrés verts!\nC'est ta dernière mission ;)");
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        setContentView(R.layout.tutorial5_display);

        TextView txtV = findViewById(R.id.cons_tut5);
        smallCons = "Clique sur les carrés verts.";
        txtV.setText(smallCons);
        setTts();


        findViewById(R.id.blue_rectangle51).setOnTouchListener(this);
        findViewById(R.id.blue_rectangle52).setOnTouchListener(this);
        findViewById(R.id.blue_rectangle53).setOnTouchListener(this);
        findViewById(R.id.blue_rectangle54).setOnTouchListener(this);
        findViewById(R.id.red_rectangle51).setOnTouchListener(this);
        findViewById(R.id.red_rectangle52).setOnTouchListener(this);
        findViewById(R.id.red_rectangle53).setOnTouchListener(this);
        findViewById(R.id.red_rectangle54).setOnTouchListener(this);
        findViewById(R.id.green_rectangle51).setOnTouchListener(this);
        findViewById(R.id.green_rectangle52).setOnTouchListener(this);
        findViewById(R.id.green_rectangle53).setOnTouchListener(this);
        findViewById(R.id.green_rectangle54).setOnTouchListener(this);

    }

    @Override
    public boolean onTouch(View view, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (view == findViewById(R.id.green_rectangle51)
                    || view == findViewById(R.id.green_rectangle52)
                    || view == findViewById(R.id.green_rectangle53)
                    || view == findViewById(R.id.green_rectangle54)) {
                view.setVisibility(View.INVISIBLE);
                win_counter++;
            } else view.setBackgroundColor(0xff888888);
            return true;
        }
        if (win_counter == 4 && !done) {
            done = true;
            this.bravoPage(null);
            return true;
        } else
            return false;
    }

    @Override
    protected void next() {
        this.backHome(null);
    }
}