Blame view

app/src/main/java/tonio/noa/MyPlayActivity.java 2.02 KB
d55d5943   aarnaude   resolution Bravo
1
2
3
4
  package tonio.noa;
  
  import android.app.Activity;
  import android.content.Intent;
2db7566f   aarnaude   modification de M...
5
  import android.speech.tts.TextToSpeech;
d55d5943   aarnaude   resolution Bravo
6
7
8
  import android.view.View;
  import android.widget.Toast;
  
4fbbe27a   aarnaude   ajout de la fonct...
9
10
  import java.util.Locale;
  
d55d5943   aarnaude   resolution Bravo
11
12
13
14
15
16
17
18
  
  /**
   * Created by psyk on 09/01/18.
   */
  
  public abstract class MyPlayActivity extends Activity {
  
      public static final int REQUEST_CODE = 1;
2db7566f   aarnaude   modification de M...
19
      protected TextToSpeech tts;
4fbbe27a   aarnaude   ajout de la fonct...
20
      protected String smallCons;
d55d5943   aarnaude   resolution Bravo
21
22
23
  
      protected abstract void next();
  
4fbbe27a   aarnaude   ajout de la fonct...
24
25
26
27
      protected void enonceConsigne(View view) {
          tts.speak(smallCons, TextToSpeech.QUEUE_FLUSH, null, null);
      }
  
2db7566f   aarnaude   modification de M...
28
      protected void bravoPage(View view) {
d55d5943   aarnaude   resolution Bravo
29
30
          startActivityForResult(new Intent(this, BravoActivity.class), REQUEST_CODE);
      }
2db7566f   aarnaude   modification de M...
31
32
33
34
35
36
37
38
  
      protected void lanceConsigne(String cons) {
          Intent i = new Intent(this, ConsigneActivity.class);
          i.putExtra("keyConsigne", cons);
          int requestCode = 0;
          startActivityForResult(i, requestCode);
      }
  
4fbbe27a   aarnaude   ajout de la fonct...
39
40
41
42
43
44
45
46
47
48
49
50
      protected void setTts() {
  
          tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
              @Override
              public void onInit(int status) {
                  if (status != TextToSpeech.ERROR) {
                      tts.setLanguage(Locale.FRENCH);
                  }
              }
          });
      }
  
d55d5943   aarnaude   resolution Bravo
51
      @Override
2db7566f   aarnaude   modification de M...
52
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
d55d5943   aarnaude   resolution Bravo
53
54
55
          try {
              super.onActivityResult(requestCode, resultCode, data);
  
2db7566f   aarnaude   modification de M...
56
              if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
d55d5943   aarnaude   resolution Bravo
57
58
59
60
61
62
63
64
65
                  this.next();
                  finish();
              }
          } catch (Exception ex) {
              Toast.makeText(MyPlayActivity.this, ex.toString(),
                      Toast.LENGTH_SHORT).show();
          }
      }
  
4fbbe27a   aarnaude   ajout de la fonct...
66
67
68
69
70
71
72
73
74
75
      @Override
      public void onDestroy() {
          if (tts != null) {
              tts.stop();
              tts.shutdown();
          }
          super.onDestroy();
      }
  
      protected void backHome(View view) {
d55d5943   aarnaude   resolution Bravo
76
77
78
79
  
          startActivity(new Intent(this, MainActivity.class));
          finish();
      }
2db7566f   aarnaude   modification de M...
80
  
d55d5943   aarnaude   resolution Bravo
81
  }