ThemeActivity.java 2.2 KB
package tonio.noa;


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

import java.util.Locale;

/**
 * Created by tonio on 16/11/17.
 */

public class ThemeActivity extends Activity implements View.OnLongClickListener {

    private TextToSpeech tts;

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.theme_display);

        findViewById(R.id.button_id_health).setOnLongClickListener(this);
        findViewById(R.id.button_id_sociability).setOnLongClickListener(this);
        findViewById(R.id.button_id_security).setOnLongClickListener(this);
        findViewById(R.id.button_id_hygiene).setOnLongClickListener(this);
        findViewById(R.id.button_id_independence).setOnLongClickListener(this);
        findViewById(R.id.button_id_food).setOnLongClickListener(this);

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

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

    public void healthPage(View view) {

        startActivity(new Intent(this, HealthActivity.class));
    }

    public void hygienePage(View view) {

        startActivity(new Intent(this, Hygiene1Activity.class));
    }

    public void foodPage(View view) {

        startActivity(new Intent(this, Food1Activity.class));
    }

    public void securityPage(View view) {

        startActivity(new Intent(this, Security1Activity.class));
    }

    public void backHome(View view) {

        startActivity(new Intent(this, MainActivity.class));
    }

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