MainActivity.java 1.71 KB
package tonio.noa;

import android.app.Activity;
import android.content.Intent;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.Locale;

public class MainActivity extends Activity implements View.OnLongClickListener {

    private TextToSpeech tts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.button_id_play).setOnLongClickListener(this);
        findViewById(R.id.button_id_tutorial).setOnLongClickListener(this);

        tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    tts.setLanguage(Locale.FRENCH);
                }
            }
        });
    }

    public void themePage(View view) {

        startActivity(new Intent(this, ThemeActivity.class));
        finish();
    }

    public void configurePage(View view) {

        startActivity(new Intent(this, ConfigureActivity.class));
        finish();
    }

    public void tutorialPage(View view) {

        startActivity(new Intent(this, TutorialScene1Activity.class));
        finish();
    }

    public boolean onLongClick(View view) {
        tts.speak(((TextView) view).getText(), TextToSpeech.QUEUE_FLUSH, null, null);
        return true;
    }

    @Override
    public void onDestroy() {
        if (tts != null) {
            tts.stop();
            tts.shutdown();
        }
        super.onDestroy();
    }
}