ConsigneActivity.java 1.67 KB
package tonio.noa;

import android.app.Activity;
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;

import java.util.Locale;

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

public class ConsigneActivity extends Activity {

    private TextToSpeech consigneSpk;
    private TextView consigneTxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        final Intent intent = getIntent();
        setContentView(R.layout.consigne_display);
        consigneTxt = findViewById(R.id.consigne);
        consigneTxt.setText(intent.getStringExtra("keyConsigne"));
        View view = findViewById(R.id.consigne_view);
        view.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent event) {
                setResult(RESULT_OK, intent);
                finish();
                return true;
            }
        });

        consigneSpk = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    consigneSpk.setLanguage(Locale.FRENCH);
                    consigneSpk.speak(consigneTxt.getText(), TextToSpeech.QUEUE_FLUSH, null, null);
                }
            }
        });
    }

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