Blame view

app/src/main/java/tonio/noa/ConsigneActivity.java 1.67 KB
c13d9bc3   aarnaude   activity consigne...
1
2
3
4
5
  package tonio.noa;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
427a4dcd   aarnaude   ajout texttospeec...
6
  import android.speech.tts.TextToSpeech;
c13d9bc3   aarnaude   activity consigne...
7
8
9
10
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.TextView;
  
427a4dcd   aarnaude   ajout texttospeec...
11
12
  import java.util.Locale;
  
c13d9bc3   aarnaude   activity consigne...
13
14
15
16
17
18
  /**
   * Created by psyk on 22/01/18.
   */
  
  public class ConsigneActivity extends Activity {
  
427a4dcd   aarnaude   ajout texttospeec...
19
20
21
      private TextToSpeech consigneSpk;
      private TextView consigneTxt;
  
c13d9bc3   aarnaude   activity consigne...
22
23
24
25
26
27
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          final Intent intent = getIntent();
          setContentView(R.layout.consigne_display);
427a4dcd   aarnaude   ajout texttospeec...
28
          consigneTxt = findViewById(R.id.consigne);
c13d9bc3   aarnaude   activity consigne...
29
30
31
32
          consigneTxt.setText(intent.getStringExtra("keyConsigne"));
          View view = findViewById(R.id.consigne_view);
          view.setOnTouchListener(new View.OnTouchListener() {
  
427a4dcd   aarnaude   ajout texttospeec...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
              @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();
c13d9bc3   aarnaude   activity consigne...
59
60
      }
  }